class Euclidean::PointZero
An object repesenting a {Point} at the origin in N-dimensional space
A {PointZero} object is a {Point} that will always compare equal to zero and unequal to everything else, regardless of size. You can think of it as an application of the {en.wikipedia.org/wiki/Null_Object_pattern Null Object
Pattern}.
Public Instance Methods
*(other)
click to toggle source
# File lib/euclidean/point_zero.rb, line 93 def *(other) self end
+(other)
click to toggle source
@endgroup
# File lib/euclidean/point_zero.rb, line 75 def +(other) case other when Array, Numeric then other else Point[other] end end
+@()
click to toggle source
@group Unary operators
# File lib/euclidean/point_zero.rb, line 66 def +@ self end
-(other)
click to toggle source
# File lib/euclidean/point_zero.rb, line 83 def -(other) if other.is_a? Size -Point[other] elsif other.respond_to? :-@ -other elsif other.respond_to? :map other.map {|a| -a } end end
-@()
click to toggle source
# File lib/euclidean/point_zero.rb, line 70 def -@ self end
/(other)
click to toggle source
# File lib/euclidean/point_zero.rb, line 97 def /(other) raise OperationNotDefined unless other.is_a? Numeric raise ZeroDivisionError if 0 == other self end
[](i)
click to toggle source
@group Accessors @param [Integer] i Index into the {Point}‘s elements @return [Numeric] Element i (starting at 0)
# File lib/euclidean/point_zero.rb, line 40 def [](i) 0 end
coerce(other)
click to toggle source
# File lib/euclidean/point_zero.rb, line 20 def coerce(other) if other.is_a? Numeric [other, 0] elsif other.is_a? Array [other, Array.new(other.size,0)] elsif other.is_a? Vector [other, Vector[*Array.new(other.size,0)]] else [Point[other], Point[Array.new(other.size,0)]] end end
eql?(other)
click to toggle source
# File lib/euclidean/point_zero.rb, line 11 def eql?(other) if other.respond_to? :all? other.all? {|e| e.eql? 0} else other == 0 end end
Also aliased as: ==
to_a()
click to toggle source
This is a hack to get Array#== to work properly. It works on ruby 2.0 and 1.9.3.
# File lib/euclidean/point_zero.rb, line 33 def to_a [] end
x()
click to toggle source
@attribute [r] x @return [Numeric] X-component
# File lib/euclidean/point_zero.rb, line 46 def x 0 end
y()
click to toggle source
@attribute [r] y @return [Numeric] Y-component
# File lib/euclidean/point_zero.rb, line 52 def y 0 end
z()
click to toggle source
@attribute [r] z @return [Numeric] Z-component
# File lib/euclidean/point_zero.rb, line 58 def z 0 end