Class: Vissen::Output::Point
- Inherits:
-
Object
- Object
- Vissen::Output::Point
- 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
-
#position ⇒ Array<Float>
(also: #to_a)
readonly
An array containing the x and y coordinates of the point.
Class Method Summary collapse
-
.from(obj, **args) ⇒ Point
Coerce objects into points.
Instance Method Summary collapse
-
#freeze ⇒ self
Prevents the position from being changed.
-
#initialize(x, y, scale: 1.0) ⇒ Point
constructor
A new instance of Point.
-
#inspect ⇒ String
A string representation of the point.
-
#x ⇒ Float
The x coordinate of the point.
-
#y ⇒ Float
The y coordinate of the point.
Constructor Details
#initialize(x, y, scale: 1.0) ⇒ Point
Returns a new instance of Point.
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
#position ⇒ Array<Float> (readonly) Also known as: to_a
Returns 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.
51 52 53 |
# File 'lib/vissen/output/point.rb', line 51 def from(obj, **args) new(*obj.to_a, **args) end |
Instance Method Details
#freeze ⇒ self
Prevents the position from being changed.
35 36 37 38 |
# File 'lib/vissen/output/point.rb', line 35 def freeze @position.freeze super end |
#inspect ⇒ String
Returns 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 |
#x ⇒ Float
Returns the x coordinate of the point.
23 24 25 |
# File 'lib/vissen/output/point.rb', line 23 def x @position[0] end |
#y ⇒ Float
Returns the y coordinate of the point.
28 29 30 |
# File 'lib/vissen/output/point.rb', line 28 def y @position[1] end |