Class: Geometry::PointZero
- Inherits:
-
Object
- Object
- Geometry::PointZero
- Defined in:
- lib/geometry/point_zero.rb
Overview
Accessors collapse
-
#x ⇒ Numeric
readonly
X-component.
-
#y ⇒ Numeric
readonly
Y-component.
-
#z ⇒ Numeric
readonly
Z-component.
Accessors collapse
-
#[](i) ⇒ Numeric
Element i (starting at 0).
Unary operators collapse
Instance Method Summary collapse
- #*(other) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #/(other) ⇒ Object
- #coerce(other) ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
-
#to_ary ⇒ Object
This is a hack to get Array#== to work properly.
Instance Attribute Details
#x ⇒ Numeric (readonly)
Returns X-component.
46 47 48 |
# File 'lib/geometry/point_zero.rb', line 46 def x 0 end |
#y ⇒ Numeric (readonly)
Returns Y-component.
52 53 54 |
# File 'lib/geometry/point_zero.rb', line 52 def y 0 end |
#z ⇒ Numeric (readonly)
Returns Z-component.
58 59 60 |
# File 'lib/geometry/point_zero.rb', line 58 def z 0 end |
Instance Method Details
#*(other) ⇒ Object
93 94 95 |
# File 'lib/geometry/point_zero.rb', line 93 def *(other) self end |
#+(other) ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/geometry/point_zero.rb', line 75 def +(other) case other when Array, Numeric then other else Point[other] end end |
#+@ ⇒ Object
66 67 68 |
# File 'lib/geometry/point_zero.rb', line 66 def +@ self end |
#-(other) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'lib/geometry/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 |
#-@ ⇒ Object
70 71 72 |
# File 'lib/geometry/point_zero.rb', line 70 def -@ self end |
#/(other) ⇒ Object
97 98 99 100 101 |
# File 'lib/geometry/point_zero.rb', line 97 def /(other) raise OperationNotDefined unless other.is_a? Numeric raise ZeroDivisionError if 0 == other self end |
#[](i) ⇒ Numeric
Returns Element i (starting at 0).
40 41 42 |
# File 'lib/geometry/point_zero.rb', line 40 def [](i) 0 end |
#coerce(other) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/geometry/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) ⇒ Boolean Also known as: ==
11 12 13 14 15 16 17 |
# File 'lib/geometry/point_zero.rb', line 11 def eql?(other) if other.respond_to? :all? other.all? {|e| e.eql? 0} else other == 0 end end |
#to_ary ⇒ Object
This is a hack to get Array#== to work properly. It works on ruby 2.0 and 1.9.3.
33 34 35 |
# File 'lib/geometry/point_zero.rb', line 33 def to_ary [] end |