Class: Sangaku::Point
- Inherits:
-
Object
- Object
- Sangaku::Point
- Defined in:
- lib/sangaku/point.rb
Class Method Summary collapse
Instance Method Summary collapse
- #*(scale) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #/(scale) ⇒ Object
- #dist(other) ⇒ Object
-
#initialize(x, y) ⇒ Point
constructor
A new instance of Point.
- #to_a ⇒ Object
- #to_s ⇒ Object (also: #inspect)
- #x ⇒ Object (also: #w)
- #x=(val) ⇒ Object (also: #w=)
- #y ⇒ Object (also: #h)
- #y=(val) ⇒ Object (also: #h=)
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
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_a ⇒ Object
43 |
# File 'lib/sangaku/point.rb', line 43 def to_a; @coord; end |
#to_s ⇒ Object Also known as: inspect
44 |
# File 'lib/sangaku/point.rb', line 44 def to_s; "(#{@coord.join(', ')})"; end |
#x ⇒ Object 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 |
#y ⇒ Object 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 |