Class: JennCad::Size
- Inherits:
-
Object
- Object
- JennCad::Size
- Defined in:
- lib/jenncad/position.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
Returns the value of attribute size.
Instance Method Summary collapse
- #add(other) ⇒ Object
- #d ⇒ Object
-
#initialize(args = {}) ⇒ Size
constructor
A new instance of Size.
- #set(a, to) ⇒ Object
- #to_point ⇒ Object
- #union(other) ⇒ Object
- #x ⇒ Object
- #y ⇒ Object
- #z ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Size
Returns a new instance of Size.
4 5 6 7 8 9 10 11 |
# File 'lib/jenncad/position.rb', line 4 def initialize(args={}) @size = { x: args[:x].to_d, y: args[:y].to_d, z: (args[:z] || args[:h]).to_d, d: args[:d].to_d, } end |
Instance Attribute Details
#size ⇒ Object
Returns the value of attribute size.
3 4 5 |
# File 'lib/jenncad/position.rb', line 3 def size @size end |
Instance Method Details
#add(other) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/jenncad/position.rb', line 13 def add(other) return self if other.nil? @size[:x] += other.x @size[:y] += other.y @size[:z] += other.z @size[:d] += other.d self end |
#d ⇒ Object
50 51 52 |
# File 'lib/jenncad/position.rb', line 50 def d @size[:d] end |
#set(a, to) ⇒ Object
34 35 36 |
# File 'lib/jenncad/position.rb', line 34 def set(a, to) @size[a] = to end |
#to_point ⇒ Object
30 31 32 |
# File 'lib/jenncad/position.rb', line 30 def to_point Point.new(x: @size[:x], y: @size[:y], z: @size[:z]) end |
#union(other) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/jenncad/position.rb', line 22 def union(other) @size[:x] = [@size[:x], other.x].max @size[:y] = [@size[:y], other.y].max @size[:z] = [@size[:z], other.z].max @size[:d] = [@size[:d], other.d].max self end |
#x ⇒ Object
38 39 40 |
# File 'lib/jenncad/position.rb', line 38 def x @size[:x] end |
#y ⇒ Object
42 43 44 |
# File 'lib/jenncad/position.rb', line 42 def y @size[:y] end |
#z ⇒ Object
46 47 48 |
# File 'lib/jenncad/position.rb', line 46 def z @size[:z] end |