Class: BoxPacker::Vector
- Inherits:
-
Object
- Object
- BoxPacker::Vector
- Defined in:
- lib/box_packer/vector.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
-
#z ⇒ Object
readonly
Returns the value of attribute z.
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #==(other) ⇒ Object
- #depth ⇒ Object
- #eql?(other) ⇒ Boolean
- #height ⇒ Object
-
#initialize(x, y, z) ⇒ Vector
constructor
A new instance of Vector.
- #to_a ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(x, y, z) ⇒ Vector
Returns a new instance of Vector.
7 8 9 |
# File 'lib/box_packer/vector.rb', line 7 def initialize(x, y, z) @x, @y, @z = x, y, z end |
Instance Attribute Details
#x ⇒ Object (readonly)
Returns the value of attribute x.
11 12 13 |
# File 'lib/box_packer/vector.rb', line 11 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
11 12 13 |
# File 'lib/box_packer/vector.rb', line 11 def y @y end |
#z ⇒ Object (readonly)
Returns the value of attribute z.
11 12 13 |
# File 'lib/box_packer/vector.rb', line 11 def z @z end |
Class Method Details
.[](*args) ⇒ Object
3 4 5 |
# File 'lib/box_packer/vector.rb', line 3 def self.[](*args) new(*args) end |
Instance Method Details
#+(other) ⇒ Object
13 14 15 |
# File 'lib/box_packer/vector.rb', line 13 def +(other) self.class.new(*zip_map(other, :+)) end |
#-(other) ⇒ Object
17 18 19 |
# File 'lib/box_packer/vector.rb', line 17 def -(other) self.class.new(*zip_map(other, :-)) end |
#==(other) ⇒ Object
37 38 39 |
# File 'lib/box_packer/vector.rb', line 37 def ==(other) zip_map(other, :==).reduce(&:&) end |
#depth ⇒ Object
29 30 31 |
# File 'lib/box_packer/vector.rb', line 29 def depth self.class.new(0, 0, z) end |
#eql?(other) ⇒ Boolean
41 42 43 |
# File 'lib/box_packer/vector.rb', line 41 def eql?(other) zip_map(other, :eql?).reduce(&:&) end |
#height ⇒ Object
25 26 27 |
# File 'lib/box_packer/vector.rb', line 25 def height self.class.new(0, y, 0) end |
#to_a ⇒ Object
33 34 35 |
# File 'lib/box_packer/vector.rb', line 33 def to_a [x, y, z] end |
#width ⇒ Object
21 22 23 |
# File 'lib/box_packer/vector.rb', line 21 def width self.class.new(x, 0, 0) end |