Class: Geometer::Point
- Inherits:
-
Struct
- Object
- Struct
- Geometer::Point
- Defined in:
- lib/geometer/point.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #divide(sz) ⇒ Object (also: #/)
- #inspect ⇒ Object
- #invert ⇒ Object (also: #-@)
- #scale(sz) ⇒ Object (also: #*)
- #to_i ⇒ Object
- #translate(other_point) ⇒ Object
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x
2 3 4 |
# File 'lib/geometer/point.rb', line 2 def x @x end |
#y ⇒ Object
Returns the value of attribute y
2 3 4 |
# File 'lib/geometer/point.rb', line 2 def y @y end |
Instance Method Details
#divide(sz) ⇒ Object Also known as: /
17 18 19 |
# File 'lib/geometer/point.rb', line 17 def divide(sz) scale(1.0/sz) end |
#inspect ⇒ Object
3 4 5 |
# File 'lib/geometer/point.rb', line 3 def inspect "(#{x},#{y})" end |
#invert ⇒ Object Also known as: -@
7 8 9 |
# File 'lib/geometer/point.rb', line 7 def invert Point.new(-x,-y) end |
#scale(sz) ⇒ Object Also known as: *
12 13 14 |
# File 'lib/geometer/point.rb', line 12 def scale(sz) Point.new(x*sz,y*sz) end |
#to_i ⇒ Object
27 28 29 |
# File 'lib/geometer/point.rb', line 27 def to_i Point.new(x.to_i, y.to_i) end |
#translate(other_point) ⇒ Object
22 23 24 25 |
# File 'lib/geometer/point.rb', line 22 def translate(other_point) dx,dy = *other_point Point.new(x+dx, y+dy) end |