class Cartesius::Point
Attributes
x[R]
y[R]
Public Class Methods
distance(point1, point2)
click to toggle source
# File lib/cartesius/point.rb, line 17 def self.distance(point1, point2) Math.sqrt((point1.x - point2.x) ** 2 + (point1.y - point2.y) ** 2) end
new(x:, y:)
click to toggle source
# File lib/cartesius/point.rb, line 9 def initialize(x:, y:) @x, @y = x.to_r, y.to_r end
origin()
click to toggle source
# File lib/cartesius/point.rb, line 13 def self.origin new(x: 0, y: 0) end
Public Instance Methods
==(point)
click to toggle source
# File lib/cartesius/point.rb, line 37 def == (point) point.instance_of?(self.class) && point.x == @x && point.y == @y end
Also aliased as: eql?
congruent?(point)
click to toggle source
# File lib/cartesius/point.rb, line 33 def congruent?(point) point.instance_of?(self.class) end
origin?()
click to toggle source
# File lib/cartesius/point.rb, line 21 def origin? self == Point.origin end
to_coordinates()
click to toggle source
# File lib/cartesius/point.rb, line 25 def to_coordinates "(#{stringfy(x)}; #{stringfy(y)})" end
to_equation()
click to toggle source
# File lib/cartesius/point.rb, line 29 def to_equation equationfy('x^2' => 1, 'y^2' => 1, 'x' => -2 * @x, 'y' => -2 * @y, '1' => @x ** 2 + @y ** 2) end
Private Instance Methods
hash()
click to toggle source
# File lib/cartesius/point.rb, line 46 def hash @x.hash ^ @y.hash end