Class: RubyPost::Pair

Inherits:
Drawable show all
Defined in:
lib/drawable.rb

Overview

Cartesion point.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x = 0, y = 0) ⇒ Pair

Can set the value and individual scales of the x and y point



73
74
75
76
77
# File 'lib/drawable.rb', line 73

def initialize(x=0,y=0)
  super()
  @x = x
  @y = y
end

Instance Attribute Details

#xObject (readonly)

Returns the value of attribute x.



69
70
71
# File 'lib/drawable.rb', line 69

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



70
71
72
# File 'lib/drawable.rb', line 70

def y
  @y
end

Instance Method Details

#*(n) ⇒ Object

returns the pair multiplied by a scalar



94
95
96
# File 'lib/drawable.rb', line 94

def *(n)
  Pair.new(@x*n, @y*n)
end

#+(p) ⇒ Object

returns the addition of the pairs



84
85
86
# File 'lib/drawable.rb', line 84

def +(p)
  Pair.new(@x + p.x, @y + p.y)
end

#-(p) ⇒ Object

returns the subtraction of the pairs



89
90
91
# File 'lib/drawable.rb', line 89

def -(p)
  Pair.new(@x - p.x, @y - p.y)
end

#/(n) ⇒ Object

returns the pair divided by a scalar



99
100
101
# File 'lib/drawable.rb', line 99

def /(n)
  Pair.new(@x/n, @y/n)
end

#==(p) ⇒ Object

returns true if the pairs are equal



104
105
106
# File 'lib/drawable.rb', line 104

def ==(p)
  @x == p.x && @y == p.y 
end

#compileObject



79
80
81
# File 'lib/drawable.rb', line 79

def compile
  '(' + @x.compile + ', ' + @y.compile  + ')'
end