Class: Geometry::Point
- Inherits:
-
Struct
- Object
- Struct
- Geometry::Point
- Defined in:
- lib/geometry/point.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Class Method Summary collapse
Instance Method Summary collapse
- #==(another_point) ⇒ Object
- #advance_by(vector) ⇒ Object
- #distance_to(point) ⇒ Object
- #to_vector ⇒ Object
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x
2 3 4 |
# File 'lib/geometry/point.rb', line 2 def x @x end |
#y ⇒ Object
Returns the value of attribute y
2 3 4 |
# File 'lib/geometry/point.rb', line 2 def y @y end |
Class Method Details
.new_by_array(array) ⇒ Object
3 4 5 |
# File 'lib/geometry/point.rb', line 3 def self.new_by_array(array) self.new(array[0], array[1]) end |
Instance Method Details
#==(another_point) ⇒ Object
7 8 9 |
# File 'lib/geometry/point.rb', line 7 def ==(another_point) x === another_point.x && y === another_point.y end |
#advance_by(vector) ⇒ Object
15 16 17 |
# File 'lib/geometry/point.rb', line 15 def advance_by(vector) Point x + vector.x, y + vector.y end |
#distance_to(point) ⇒ Object
19 20 21 |
# File 'lib/geometry/point.rb', line 19 def distance_to(point) Geometry.distance(self, point) end |
#to_vector ⇒ Object
11 12 13 |
# File 'lib/geometry/point.rb', line 11 def to_vector Vector.new(x, y) end |