Class: BoxPacker::Vector

Inherits:
Object
  • Object
show all
Defined in:
lib/box_packer/vector.rb

Direct Known Subclasses

Dimensions, Position

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#xObject (readonly)

Returns the value of attribute x.



11
12
13
# File 'lib/box_packer/vector.rb', line 11

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



11
12
13
# File 'lib/box_packer/vector.rb', line 11

def y
  @y
end

#zObject (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

#depthObject



29
30
31
# File 'lib/box_packer/vector.rb', line 29

def depth
  self.class.new(0, 0, z)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/box_packer/vector.rb', line 41

def eql?(other)
  zip_map(other, :eql?).reduce(&:&)
end

#heightObject



25
26
27
# File 'lib/box_packer/vector.rb', line 25

def height
  self.class.new(0, y, 0)
end

#to_aObject



33
34
35
# File 'lib/box_packer/vector.rb', line 33

def to_a
  [x, y, z]
end

#widthObject



21
22
23
# File 'lib/box_packer/vector.rb', line 21

def width
  self.class.new(x, 0, 0)
end