Class: Vissen::Output::Point

Inherits:
Object
  • Object
show all
Defined in:
lib/vissen/output/point.rb

Overview

Points are simple two dimensional coordinates with an x and y component. They are used by the ‘CloudContext` to keep track of the position of its points.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, scale: 1.0) ⇒ Point

Returns a new instance of Point.

Parameters:

  • x (Numeric)

    the x coordinate of the point.

  • y (Numeric)

    the y coordinate of the point.

  • scale (Numeric) (defaults to: 1.0)

    a scale factor to apply to the coordinates.



18
19
20
# File 'lib/vissen/output/point.rb', line 18

def initialize(x, y, scale: 1.0)
  @position = [x * scale, y * scale]
end

Instance Attribute Details

#positionArray<Float> (readonly) Also known as: to_a

Returns an array containing the x and y coordinates of the point.

Returns:

  • (Array<Float>)

    an array containing the x and y coordinates of the point.



11
12
13
# File 'lib/vissen/output/point.rb', line 11

def position
  @position
end

Class Method Details

.from(obj, **args) ⇒ Point

Coerce objects into points.

Parameters:

  • obj (#to_a)

    the object to be coerced into a ‘Point`.

Returns:

  • (Point)

    a new ‘Point` object.



51
52
53
# File 'lib/vissen/output/point.rb', line 51

def from(obj, **args)
  new(*obj.to_a, **args)
end

Instance Method Details

#freezeself

Prevents the position from being changed.

Returns:

  • (self)


35
36
37
38
# File 'lib/vissen/output/point.rb', line 35

def freeze
  @position.freeze
  super
end

#inspectString

Returns a string representation of the point.

Returns:

  • (String)

    a string representation of the point.



41
42
43
# File 'lib/vissen/output/point.rb', line 41

def inspect
  format('(%0.2f,%0.2f)', *@position)
end

#xFloat

Returns the x coordinate of the point.

Returns:

  • (Float)

    the x coordinate of the point.



23
24
25
# File 'lib/vissen/output/point.rb', line 23

def x
  @position[0]
end

#yFloat

Returns the y coordinate of the point.

Returns:

  • (Float)

    the y coordinate of the point.



28
29
30
# File 'lib/vissen/output/point.rb', line 28

def y
  @position[1]
end