Class: Quartz::Point

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#xObject

Returns the value of attribute x.



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

def x
  @x
end

#yObject

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

#absObject



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

#perpObject



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

def perp
  Point.new(-@y, @x)
end

#to_sObject



59
60
61
# File 'lib/rubyquartz/point.rb', line 59

def to_s
  "(#{@x}, #{@y})"
end