Class: Quartz::Point
- Inherits:
-
Object
- Object
- Quartz::Point
- Defined in:
- lib/rubyquartz/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
- #*(scalar) ⇒ Object
- #+(p) ⇒ Object
- #-(p) ⇒ Object
- #abs ⇒ Object
- #dot(p) ⇒ Object
-
#initialize(x, y) ⇒ Point
constructor
A new instance of Point.
- #perp ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(x, y) ⇒ Point
Returns a new instance of Point.
30 31 32 33 |
# File 'lib/rubyquartz/point.rb', line 30 def initialize(x,y) @x = x @y = y end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
28 29 30 |
# File 'lib/rubyquartz/point.rb', line 28 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
28 29 30 |
# File 'lib/rubyquartz/point.rb', line 28 def y @y end |
Instance Method Details
#*(scalar) ⇒ Object
43 44 45 |
# File 'lib/rubyquartz/point.rb', line 43 def *(scalar) Point.new(@x*scalar, @y*scalar) end |
#+(p) ⇒ Object
35 36 37 |
# File 'lib/rubyquartz/point.rb', line 35 def +(p) Point.new(@x+p.x, @y+p.y) end |
#-(p) ⇒ Object
39 40 41 |
# File 'lib/rubyquartz/point.rb', line 39 def -(p) Point.new(@x-p.x, @y-p.y) end |
#abs ⇒ Object
55 56 57 |
# File 'lib/rubyquartz/point.rb', line 55 def abs Point.new(@x.abs, @y.abs) end |
#dot(p) ⇒ Object
47 48 49 |
# File 'lib/rubyquartz/point.rb', line 47 def dot(p) (@x*p.x) + (@y*p.y) end |
#to_s ⇒ Object
59 60 61 |
# File 'lib/rubyquartz/point.rb', line 59 def to_s "(#{@x}, #{@y})" end |