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



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

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

Instance Attribute Details

#xObject (readonly)

Returns the value of attribute x.



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

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



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

def y
  @y
end

Instance Method Details

#*(n) ⇒ Object

returns the pair multiplied by a scalar



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

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

#+(p) ⇒ Object

returns the addition of the pairs



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

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

#-(p) ⇒ Object

returns the subtraction of the pairs



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

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

#/(n) ⇒ Object

returns the pair divided by a scalar



109
110
111
# File 'lib/drawable.rb', line 109

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

#==(p) ⇒ Object

returns true if the pairs are equal



114
115
116
# File 'lib/drawable.rb', line 114

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

#compileObject



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

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