Class: Geometry::PointIso
- Inherits:
-
Object
- Object
- Geometry::PointIso
- Defined in:
- lib/geometry/point_iso.rb
Overview
An object repesenting a N-dimensional Point with identical elements.
Accessors collapse
- #x ⇒ Object readonly
- #y ⇒ Object readonly
- #z ⇒ Object readonly
Instance Attribute Summary collapse
-
#value ⇒ Number
The value for every element.
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: #==)
-
#initialize(value) ⇒ PointIso
constructor
Initialize to the given value.
- #inspect ⇒ Object
- #is_a?(klass) ⇒ Boolean (also: #kind_of?)
-
#to_ary ⇒ Object
This is a hack to get Array#== to work properly.
- #to_s ⇒ Object
Constructor Details
#initialize(value) ⇒ PointIso
Initialize to the given value
14 15 16 |
# File 'lib/geometry/point_iso.rb', line 14 def initialize(value) @value = value end |
Instance Attribute Details
#value ⇒ Number
Returns the value for every element.
10 11 12 |
# File 'lib/geometry/point_iso.rb', line 10 def value @value end |
#x ⇒ Object (readonly)
65 66 67 |
# File 'lib/geometry/point_iso.rb', line 65 def x @value end |
#y ⇒ Object (readonly)
71 72 73 |
# File 'lib/geometry/point_iso.rb', line 71 def y @value end |
#z ⇒ Object (readonly)
77 78 79 |
# File 'lib/geometry/point_iso.rb', line 77 def z @value end |
Instance Method Details
#*(other) ⇒ Object
119 120 121 122 |
# File 'lib/geometry/point_iso.rb', line 119 def *(other) raise OperationNotDefined unless other.is_a? Numeric self.class.new(other * @value) end |
#+(other) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/geometry/point_iso.rb', line 94 def +(other) case other when Numeric other + @value when Size Point[other.map {|a| a + @value }] else if other.respond_to?(:map) other.map {|a| a + @value } else Point[other + @value] end end end |
#+@ ⇒ Object
85 86 87 |
# File 'lib/geometry/point_iso.rb', line 85 def +@ self end |
#-(other) ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/geometry/point_iso.rb', line 109 def -(other) if other.is_a? Size Point[other.map {|a| @value - a }] elsif other.respond_to? :map other.map {|a| @value - a } else @value - other end end |
#-@ ⇒ Object
89 90 91 |
# File 'lib/geometry/point_iso.rb', line 89 def -@ self.class.new(-@value) end |
#/(other) ⇒ Object
124 125 126 127 128 |
# File 'lib/geometry/point_iso.rb', line 124 def /(other) raise OperationNotDefined unless other.is_a? Numeric raise ZeroDivisionError if 0 == other self.class.new(@value / other) end |
#[](i) ⇒ Numeric
Returns Element i (starting at 0).
59 60 61 |
# File 'lib/geometry/point_iso.rb', line 59 def [](i) @value end |
#coerce(other) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/geometry/point_iso.rb', line 27 def coerce(other) if other.is_a? Numeric [other, @value] elsif other.is_a? Array [other, Array.new(other.size, @value)] elsif other.is_a? Vector [other, Vector[*Array.new(other.size, @value)]] else [Point[other], Point[Array.new(other.size, @value)]] end end |
#eql?(other) ⇒ Boolean Also known as: ==
18 19 20 21 22 23 24 |
# File 'lib/geometry/point_iso.rb', line 18 def eql?(other) if other.respond_to? :all? other.all? {|e| e.eql? @value} else other == @value end end |
#inspect ⇒ Object
39 40 41 |
# File 'lib/geometry/point_iso.rb', line 39 def inspect 'PointIso<' + @value.inspect + '>' end |
#is_a?(klass) ⇒ Boolean Also known as: kind_of?
46 47 48 |
# File 'lib/geometry/point_iso.rb', line 46 def is_a?(klass) (klass == Point) || super end |
#to_ary ⇒ Object
This is a hack to get Array#== to work properly. It works on ruby 2.0 and 1.9.3.
52 53 54 |
# File 'lib/geometry/point_iso.rb', line 52 def to_ary [] end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/geometry/point_iso.rb', line 42 def to_s 'PointIso<' + @value.to_s + '>' end |