class Dieses::Geometry::Point
Attributes
hash[R]
x[R]
y[R]
Public Class Methods
call(*args)
click to toggle source
# File lib/dieses/geometry/point.rb, line 56 def call(*args) new(*args) end
cast(point)
click to toggle source
# File lib/dieses/geometry/point.rb, line 69 def cast(point) Point.new(point.x, point.y) end
distance(starting, ending)
click to toggle source
# File lib/dieses/geometry/point.rb, line 64 def distance(starting, ending) ending ||= origin Math.sqrt((ending.x - starting.x)**2 + (starting.y - ending.y)**2) end
new(x, y)
click to toggle source
# File lib/dieses/geometry/point.rb, line 10 def initialize(x, y) @x, @y = x.to_f, y.to_f @hash = Point.hash ^ to_a.hash freeze end
origin()
click to toggle source
# File lib/dieses/geometry/point.rb, line 60 def origin new 0.0, 0.0 end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/dieses/geometry/point.rb, line 29 def <=>(other) return unless other.is_a? Point to_a <=> other.to_a end
approx(precision = nil)
click to toggle source
# File lib/dieses/geometry/point.rb, line 25 def approx(precision = nil) self.class.new Support.approx(x, precision), Support.approx(y, precision) end
distance(other = nil)
click to toggle source
# File lib/dieses/geometry/point.rb, line 21 def distance(other = nil) self.class.distance(self, other) end
eql?(other)
click to toggle source
# File lib/dieses/geometry/point.rb, line 35 def eql?(other) return false unless other.is_a? Point to_a == other.to_a end
Also aliased as: ==
to_a()
click to toggle source
# File lib/dieses/geometry/point.rb, line 47 def to_a [x, y] end
to_h()
click to toggle source
# File lib/dieses/geometry/point.rb, line 51 def to_h { x: x, y: y } end
to_s()
click to toggle source
# File lib/dieses/geometry/point.rb, line 43 def to_s "P(#{x}, #{y})" end
translate(x: nil, y: nil)
click to toggle source
# File lib/dieses/geometry/point.rb, line 17 def translate(x: nil, y: nil) self.class.new(self.x + (x || 0), self.y + (y || 0)) end