Class: Point

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Point.



5
6
7
8
# File 'lib/kut/misc/point.rb', line 5

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

Instance Attribute Details

#xObject

Returns the value of attribute x.



3
4
5
# File 'lib/kut/misc/point.rb', line 3

def x
  @x
end

#yObject

Returns the value of attribute y.



3
4
5
# File 'lib/kut/misc/point.rb', line 3

def y
  @y
end

Class Method Details

.[](x = 0, y = 0) ⇒ Object



10
11
12
# File 'lib/kut/misc/point.rb', line 10

def Point.[](x = 0, y = 0)
  return Point.new(x, y)
end

Instance Method Details

#+(pt) ⇒ Object



14
15
16
# File 'lib/kut/misc/point.rb', line 14

def +(pt)
  return Point[@x + pt.x, @y + pt.y]
end

#-(pt) ⇒ Object



18
19
20
# File 'lib/kut/misc/point.rb', line 18

def -(pt)
  return Point[@x - pt.x, @y - pt.y]
end

#==(pt) ⇒ Object



22
23
24
# File 'lib/kut/misc/point.rb', line 22

def ==(pt)
  (pt.x == @x) && (pt.y == @y) ? true : false
end