box_packer 1.2.2 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/box_packer.rb +0 -10
- data/lib/box_packer/box.rb +10 -1
- data/lib/box_packer/builder.rb +3 -0
- data/lib/box_packer/container.rb +7 -0
- data/lib/box_packer/dimensions.rb +10 -27
- data/lib/box_packer/item.rb +3 -0
- data/lib/box_packer/packer.rb +11 -1
- data/lib/box_packer/position.rb +2 -2
- data/lib/box_packer/svg_exporter.rb +2 -3
- data/lib/box_packer/vector.rb +51 -0
- metadata +3 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 577f9d185a95ed861e725040c6af624d2470fbea
|
4
|
+
data.tar.gz: e1959d0f2230fd26b464b5340d31cd45ea29c3b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 708d9ad7db2ca97d46c275e9545ff67e1aadd6788fc439dff8a78acc46d8b334a95d1c8d27a686b61357093a8a11bcf1f41b9c1bacc28ab72aa9d1933a88bcb6
|
7
|
+
data.tar.gz: 704c4c92f46af99ecf269347ecef930f41368922642c3447aed04e2dfdf0e77330a356da14bdcffd2b21eaa5cbb98bd5d985abb1e307849d7e926d3342983626
|
data/README.md
CHANGED
@@ -30,7 +30,7 @@ BoxPacker.container [3, 6, 7] do
|
|
30
30
|
add_item [1,3,5]
|
31
31
|
add_item [4,3,5]
|
32
32
|
add_item [3,5,5]
|
33
|
-
pack! #
|
33
|
+
pack! # 2
|
34
34
|
|
35
35
|
puts packed_successfully # true
|
36
36
|
puts packings.count # 2
|
@@ -53,7 +53,7 @@ BoxPacker.container [15, 20, 13], label: 'Parcel', weight_limit: 50, packings_li
|
|
53
53
|
add_item [2, 3, 5], label: 'Shoes', weight: 47, quantity: 2
|
54
54
|
add_item [3, 3, 1], label: 'Watch', weight: 24
|
55
55
|
add_item [1, 1, 4], label: 'Bag', weight: 7
|
56
|
-
pack! #
|
56
|
+
pack! # 3
|
57
57
|
|
58
58
|
puts self # |Container| Parcel 20x15x13 Weight Limit:50 Packings Limit:3
|
59
59
|
# | Packing| Remaining Volume:3870 Remaining Weight:3
|
data/lib/box_packer.rb
CHANGED
@@ -1,12 +1,2 @@
|
|
1
|
-
require 'attire'
|
2
|
-
require 'forwardable'
|
3
|
-
|
4
|
-
require 'box_packer/position'
|
5
|
-
require 'box_packer/dimensions'
|
6
|
-
require 'box_packer/box'
|
7
|
-
require 'box_packer/item'
|
8
|
-
require 'box_packer/packer'
|
9
|
-
require 'box_packer/packing'
|
10
|
-
require 'box_packer/svg_exporter'
|
11
1
|
require 'box_packer/container'
|
12
2
|
require 'box_packer/builder'
|
data/lib/box_packer/box.rb
CHANGED
@@ -1,7 +1,16 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
require_relative 'position'
|
3
|
+
require_relative 'dimensions'
|
4
|
+
|
1
5
|
module BoxPacker
|
2
6
|
class Box
|
3
7
|
extend Forwardable
|
4
|
-
|
8
|
+
|
9
|
+
def initialize(dimensions, opts = {})
|
10
|
+
@dimensions = dimensions
|
11
|
+
@position = opts[:position] || Position[0, 0, 0]
|
12
|
+
end
|
13
|
+
|
5
14
|
def_delegators :dimensions, :volume, :each_rotation, :width, :height, :depth
|
6
15
|
attr_accessor :dimensions, :position
|
7
16
|
|
data/lib/box_packer/builder.rb
CHANGED
data/lib/box_packer/container.rb
CHANGED
@@ -1,43 +1,26 @@
|
|
1
|
-
|
1
|
+
require_relative 'vector'
|
2
2
|
|
3
3
|
module BoxPacker
|
4
4
|
class Dimensions < Vector
|
5
|
-
def +(other)
|
6
|
-
Dimensions[*super]
|
7
|
-
end
|
8
|
-
|
9
|
-
def -(other)
|
10
|
-
Dimensions[*super]
|
11
|
-
end
|
12
|
-
|
13
|
-
def width
|
14
|
-
Dimensions[self[0], 0, 0]
|
15
|
-
end
|
16
|
-
|
17
|
-
def height
|
18
|
-
Dimensions[0, self[1], 0]
|
19
|
-
end
|
20
|
-
|
21
|
-
def depth
|
22
|
-
Dimensions[0, 0, self[2]]
|
23
|
-
end
|
24
|
-
|
25
5
|
def volume
|
26
|
-
@volume ||=
|
6
|
+
@volume ||= to_a.reduce(&:*)
|
27
7
|
end
|
28
8
|
|
29
9
|
def >=(other)
|
30
|
-
|
10
|
+
zip_map(other, :>=).reduce(&:&)
|
31
11
|
end
|
32
12
|
|
33
13
|
def each_rotation
|
34
|
-
|
35
|
-
|
36
|
-
|
14
|
+
yield Dimensions[x, y, z]
|
15
|
+
yield Dimensions[x, z, y]
|
16
|
+
yield Dimensions[z, x, y]
|
17
|
+
yield Dimensions[z, y, x]
|
18
|
+
yield Dimensions[y, x, z]
|
19
|
+
yield Dimensions[y, z, x]
|
37
20
|
end
|
38
21
|
|
39
22
|
def to_s
|
40
|
-
|
23
|
+
to_a.join('x')
|
41
24
|
end
|
42
25
|
end
|
43
26
|
end
|
data/lib/box_packer/item.rb
CHANGED
data/lib/box_packer/packer.rb
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
module BoxPacker
|
2
2
|
class Packer
|
3
3
|
extend Forwardable
|
4
|
-
|
4
|
+
|
5
|
+
def self.pack(container)
|
6
|
+
new(container).pack
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(container)
|
10
|
+
@container = container
|
11
|
+
end
|
12
|
+
|
5
13
|
def_delegators :container, :new_packing!, :packings_limit, :packings, :packing
|
6
14
|
|
7
15
|
def pack
|
@@ -17,6 +25,8 @@ module BoxPacker
|
|
17
25
|
|
18
26
|
private
|
19
27
|
|
28
|
+
attr_reader :container
|
29
|
+
|
20
30
|
def too_many_packings?
|
21
31
|
packings.count >= packings_limit if packings_limit
|
22
32
|
end
|
data/lib/box_packer/position.rb
CHANGED
@@ -53,7 +53,6 @@ module BoxPacker
|
|
53
53
|
|
54
54
|
class Face
|
55
55
|
attr_reader :width, :height, :axes
|
56
|
-
attr_query :front?
|
57
56
|
|
58
57
|
def self.reset(margin, scale, container_dimensions)
|
59
58
|
@@coords_mapping = [0, 1, 2]
|
@@ -65,7 +64,7 @@ module BoxPacker
|
|
65
64
|
end
|
66
65
|
|
67
66
|
def iterate_class_variables
|
68
|
-
if front
|
67
|
+
if front
|
69
68
|
@@axes[0] = width + @@margin * 2
|
70
69
|
else
|
71
70
|
@@coords_mapping.rotate!
|
@@ -110,7 +109,7 @@ module BoxPacker
|
|
110
109
|
|
111
110
|
def sorted_items(packing)
|
112
111
|
items = packing.sort_by { |i| i.position[k] }
|
113
|
-
items.reverse! unless front
|
112
|
+
items.reverse! unless front
|
114
113
|
items
|
115
114
|
end
|
116
115
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module BoxPacker
|
2
|
+
class Vector
|
3
|
+
def self.[](*args)
|
4
|
+
new(*args)
|
5
|
+
end
|
6
|
+
|
7
|
+
def initialize(x, y, z)
|
8
|
+
@x, @y, @z = x, y, z
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :x, :y, :z
|
12
|
+
|
13
|
+
def +(other)
|
14
|
+
self.class.new(*zip_map(other, :+))
|
15
|
+
end
|
16
|
+
|
17
|
+
def -(other)
|
18
|
+
self.class.new(*zip_map(other, :-))
|
19
|
+
end
|
20
|
+
|
21
|
+
def width
|
22
|
+
self.class.new(x, 0, 0)
|
23
|
+
end
|
24
|
+
|
25
|
+
def height
|
26
|
+
self.class.new(0, y, 0)
|
27
|
+
end
|
28
|
+
|
29
|
+
def depth
|
30
|
+
self.class.new(0, 0, z)
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_a
|
34
|
+
[x, y, z]
|
35
|
+
end
|
36
|
+
|
37
|
+
def ==(other)
|
38
|
+
zip_map(other, :==).reduce(&:&)
|
39
|
+
end
|
40
|
+
|
41
|
+
def eql?(other)
|
42
|
+
zip_map(other, :eql?).reduce(&:&)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def zip_map(other, method)
|
48
|
+
to_a.zip(other.to_a).map { |a, b| a.send(method, b) }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
metadata
CHANGED
@@ -1,35 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: box_packer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Max White
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: attire
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.0'
|
20
|
-
- - ">="
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 0.0.3
|
23
|
-
type: :runtime
|
24
|
-
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
requirements:
|
27
|
-
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0.0'
|
30
|
-
- - ">="
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 0.0.3
|
33
13
|
- !ruby/object:Gem::Dependency
|
34
14
|
name: rasem
|
35
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,6 +62,7 @@ files:
|
|
82
62
|
- lib/box_packer/packing.rb
|
83
63
|
- lib/box_packer/position.rb
|
84
64
|
- lib/box_packer/svg_exporter.rb
|
65
|
+
- lib/box_packer/vector.rb
|
85
66
|
homepage: https://github.com/mushishi78/box_packer
|
86
67
|
licenses:
|
87
68
|
- MIT
|