Class: Sangaku::Point

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y) ⇒ Point

Returns a new instance of Point.



5
6
7
# File 'lib/sangaku/point.rb', line 5

def initialize(x, y)
  @coord = [x, y]
end

Class Method Details

.convert(points) ⇒ Object



9
10
11
# File 'lib/sangaku/point.rb', line 9

def self.convert(points)
  points.map { |p| Point.new(*p) }
end

Instance Method Details

#*(scale) ⇒ Object



31
32
33
# File 'lib/sangaku/point.rb', line 31

def *(scale)
  Point.new(self.x * scale,  self.y * scale)
end

#+(other) ⇒ Object



23
24
25
# File 'lib/sangaku/point.rb', line 23

def +(other)
  Point.new(self.x + other.x, self.y + other.y)
end

#-(other) ⇒ Object



27
28
29
# File 'lib/sangaku/point.rb', line 27

def -(other)
  Point.new(self.x - other.x, self.y - other.y)
end

#/(scale) ⇒ Object



35
36
37
# File 'lib/sangaku/point.rb', line 35

def /(scale)
  Point.new(self.x / scale,  self.y / scale)
end

#dist(other) ⇒ Object



39
40
41
# File 'lib/sangaku/point.rb', line 39

def dist(other)
  Math.sqrt((self.x - other.x) ** 2 + (self.y - other.y) ** 2 )
end

#to_aObject



43
# File 'lib/sangaku/point.rb', line 43

def to_a; @coord; end

#to_sObject Also known as: inspect



44
# File 'lib/sangaku/point.rb', line 44

def to_s; "(#{@coord.join(', ')})"; end

#xObject Also known as: w



13
# File 'lib/sangaku/point.rb', line 13

def x; @coord[0]; end

#x=(val) ⇒ Object Also known as: w=



14
# File 'lib/sangaku/point.rb', line 14

def x=(val); @coord[0]=val; end

#yObject Also known as: h



15
# File 'lib/sangaku/point.rb', line 15

def y; @coord[1]; end

#y=(val) ⇒ Object Also known as: h=



16
# File 'lib/sangaku/point.rb', line 16

def y=(val); @coord[1]=val; end