box_packer 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +114 -114
- data/lib/box_packer/box.rb +1 -1
- data/lib/box_packer/container.rb +1 -1
- data/lib/box_packer/item.rb +1 -1
- data/lib/box_packer/packer.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6674a542f5f429666b9e47203e8ccc70dc84959c
|
4
|
+
data.tar.gz: 7f85e16669af7c897a7ec754f0e1a72d05abbef5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb646bc2431f217984f17203585dbe37eeaffc71e6537e223b201eba3f79dc68b084af5a812c95c508b7d931ce24c392e4c226665ae21b72ac0c82f17b95777a
|
7
|
+
data.tar.gz: 4c0da12dd4b7dede43af119a0c00c291ad406ab994ae02359ee87ff303b2dfb6083679230a356c86edd0fa872d6610813f7cb3ff7bc0cb7fc5c4b78bc86bb64f
|
data/README.md
CHANGED
@@ -1,115 +1,115 @@
|
|
1
|
-
BoxPacker
|
2
|
-
=========
|
3
|
-
|
4
|
-
[![Gem Version](https://badge.fury.io/rb/box_packer.svg)](http://badge.fury.io/rb/box_packer)
|
5
|
-
|
6
|
-
A heuristic first-fit 3D bin packing algorithm with optional weight and bin limits.
|
7
|
-
|
8
|
-
Installation
|
9
|
-
------------
|
10
|
-
|
11
|
-
Install gem:
|
12
|
-
|
13
|
-
``` console
|
14
|
-
gem install 'box_packer'
|
15
|
-
```
|
16
|
-
|
17
|
-
Or add to gemfile:
|
18
|
-
|
19
|
-
``` ruby
|
20
|
-
gem 'box_packer'
|
21
|
-
```
|
22
|
-
|
23
|
-
Usage
|
24
|
-
-----
|
25
|
-
|
26
|
-
``` ruby
|
27
|
-
require 'box_packer'
|
28
|
-
|
29
|
-
BoxPacker.container [3, 6, 7] do
|
30
|
-
add_item [1,3,5]
|
31
|
-
add_item [4,3,5]
|
32
|
-
add_item [3,5,5]
|
33
|
-
pack! # returns 2
|
34
|
-
|
35
|
-
puts packed_successfully # true
|
36
|
-
puts packings.count # 2
|
37
|
-
puts packings[0].include? items[1] # false
|
38
|
-
puts packings[0][1].position # (5,0,0)
|
39
|
-
|
40
|
-
puts self # |Container| 7x6x3
|
41
|
-
# | Packing| Remaining Volume:36
|
42
|
-
# | Item| 5x5x3 (0,0,0) Volume:75
|
43
|
-
# | Item| 1x5x3 (5,0,0) Volume:15
|
44
|
-
# | Packing| Remaining Volume:66
|
45
|
-
# | Item| 5x4x3 (0,0,0) Volume:60
|
46
|
-
end
|
47
|
-
```
|
48
|
-
|
49
|
-
With optional labels, weights, quantity and packings limit:
|
50
|
-
|
51
|
-
``` ruby
|
52
|
-
BoxPacker.container [15, 20, 13], label: 'Parcel', weight_limit: 50, packings_limit: 3 do
|
53
|
-
add_item [2, 3, 5], label: 'Shoes', weight: 47, quantity: 2
|
54
|
-
add_item [3, 3, 1], label: 'Watch', weight: 24
|
55
|
-
add_item [1, 1, 4], label: 'Bag', weight: 7
|
56
|
-
pack! # returns 2
|
57
|
-
|
58
|
-
puts self # |Container| Parcel 20x15x13 Weight Limit:50 Packings Limit:3
|
59
|
-
# | Packing| Remaining Volume:3870 Remaining Weight:3
|
60
|
-
# | Item| Shoes 5x3x2 (0,0,0) Volume:30 Weight:47
|
61
|
-
# | Packing| Remaining Volume:3870 Remaining Weight:3
|
62
|
-
# | Item| Shoes 5x3x2 (0,0,0) Volume:30 Weight:47
|
63
|
-
# | Packing| Remaining Volume:3887 Remaining Weight:19
|
64
|
-
# | Item| Watch 3x3x1 (0,0,0) Volume:9 Weight:24
|
65
|
-
# | Item| Bag 4x1x1 (3,0,0) Volume:4 Weight:7
|
66
|
-
end
|
67
|
-
```
|
68
|
-
|
69
|
-
Alternative builder API:
|
70
|
-
|
71
|
-
``` ruby
|
72
|
-
BoxPacker.builder do |b|
|
73
|
-
c1 = b.container [10,5,11]
|
74
|
-
c2 = b.container [17,23,14]
|
75
|
-
|
76
|
-
c1.items = [b.item([1,1,4]), b.item([4,6,7]), b.item([5,8,10])]
|
77
|
-
c2.items = c1.items
|
78
|
-
|
79
|
-
c1.pack! # 2
|
80
|
-
c2.pack! # 1
|
81
|
-
|
82
|
-
puts c1 # |Container| 11x10x5
|
83
|
-
# | Packing| Remaining Volume:146
|
84
|
-
# | Item| 10x8x5 (0,0,0) Volume:400
|
85
|
-
# | Item| 4x1x1 (0,8,0) Volume:4
|
86
|
-
# | Packing| Remaining Volume:382
|
87
|
-
# | Item| 7x6x4 (10,0,0) Volume:168
|
88
|
-
|
89
|
-
puts c2 # |Container| 23x17x14
|
90
|
-
# | Packing| Remaining Volume:4902
|
91
|
-
# | Item| 10x8x5 (0,0,0) Volume:400
|
92
|
-
# | Item| 7x6x4 (10,0,0) Volume:168
|
93
|
-
# | Item| 4x1x1 (17,0,0) Volume:4
|
94
|
-
|
95
|
-
end
|
96
|
-
```
|
97
|
-
|
98
|
-
Export SVG
|
99
|
-
----------
|
100
|
-
|
101
|
-
``` ruby
|
102
|
-
BoxPacker.container [3, 4, 2] do
|
103
|
-
add_item [1,3,2], label: 'Bag', colour: 'red'
|
104
|
-
add_item [3,3,1], label: 'Hat', colour: 'blue'
|
105
|
-
add_item [1,2,2], label: 'Shoes', colour: 'green'
|
106
|
-
add_item [3,1,1], label: 'Slipper', colour: 'purple'
|
107
|
-
add_item [2,1,1], label: 'Dragon', colour: 'orange'
|
108
|
-
pack!
|
109
|
-
draw!('examples/example', scale_longest_side_to: 500, margin: 15)
|
110
|
-
end
|
111
|
-
```
|
112
|
-
|
113
|
-
Output:
|
114
|
-
|
1
|
+
BoxPacker
|
2
|
+
=========
|
3
|
+
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/box_packer.svg)](http://badge.fury.io/rb/box_packer)
|
5
|
+
|
6
|
+
A heuristic first-fit 3D bin packing algorithm with optional weight and bin limits.
|
7
|
+
|
8
|
+
Installation
|
9
|
+
------------
|
10
|
+
|
11
|
+
Install gem:
|
12
|
+
|
13
|
+
``` console
|
14
|
+
gem install 'box_packer'
|
15
|
+
```
|
16
|
+
|
17
|
+
Or add to gemfile:
|
18
|
+
|
19
|
+
``` ruby
|
20
|
+
gem 'box_packer'
|
21
|
+
```
|
22
|
+
|
23
|
+
Usage
|
24
|
+
-----
|
25
|
+
|
26
|
+
``` ruby
|
27
|
+
require 'box_packer'
|
28
|
+
|
29
|
+
BoxPacker.container [3, 6, 7] do
|
30
|
+
add_item [1,3,5]
|
31
|
+
add_item [4,3,5]
|
32
|
+
add_item [3,5,5]
|
33
|
+
pack! # returns 2
|
34
|
+
|
35
|
+
puts packed_successfully # true
|
36
|
+
puts packings.count # 2
|
37
|
+
puts packings[0].include? items[1] # false
|
38
|
+
puts packings[0][1].position # (5,0,0)
|
39
|
+
|
40
|
+
puts self # |Container| 7x6x3
|
41
|
+
# | Packing| Remaining Volume:36
|
42
|
+
# | Item| 5x5x3 (0,0,0) Volume:75
|
43
|
+
# | Item| 1x5x3 (5,0,0) Volume:15
|
44
|
+
# | Packing| Remaining Volume:66
|
45
|
+
# | Item| 5x4x3 (0,0,0) Volume:60
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
With optional labels, weights, quantity and packings limit:
|
50
|
+
|
51
|
+
``` ruby
|
52
|
+
BoxPacker.container [15, 20, 13], label: 'Parcel', weight_limit: 50, packings_limit: 3 do
|
53
|
+
add_item [2, 3, 5], label: 'Shoes', weight: 47, quantity: 2
|
54
|
+
add_item [3, 3, 1], label: 'Watch', weight: 24
|
55
|
+
add_item [1, 1, 4], label: 'Bag', weight: 7
|
56
|
+
pack! # returns 2
|
57
|
+
|
58
|
+
puts self # |Container| Parcel 20x15x13 Weight Limit:50 Packings Limit:3
|
59
|
+
# | Packing| Remaining Volume:3870 Remaining Weight:3
|
60
|
+
# | Item| Shoes 5x3x2 (0,0,0) Volume:30 Weight:47
|
61
|
+
# | Packing| Remaining Volume:3870 Remaining Weight:3
|
62
|
+
# | Item| Shoes 5x3x2 (0,0,0) Volume:30 Weight:47
|
63
|
+
# | Packing| Remaining Volume:3887 Remaining Weight:19
|
64
|
+
# | Item| Watch 3x3x1 (0,0,0) Volume:9 Weight:24
|
65
|
+
# | Item| Bag 4x1x1 (3,0,0) Volume:4 Weight:7
|
66
|
+
end
|
67
|
+
```
|
68
|
+
|
69
|
+
Alternative builder API:
|
70
|
+
|
71
|
+
``` ruby
|
72
|
+
BoxPacker.builder do |b|
|
73
|
+
c1 = b.container [10,5,11]
|
74
|
+
c2 = b.container [17,23,14]
|
75
|
+
|
76
|
+
c1.items = [b.item([1,1,4]), b.item([4,6,7]), b.item([5,8,10])]
|
77
|
+
c2.items = c1.items
|
78
|
+
|
79
|
+
c1.pack! # 2
|
80
|
+
c2.pack! # 1
|
81
|
+
|
82
|
+
puts c1 # |Container| 11x10x5
|
83
|
+
# | Packing| Remaining Volume:146
|
84
|
+
# | Item| 10x8x5 (0,0,0) Volume:400
|
85
|
+
# | Item| 4x1x1 (0,8,0) Volume:4
|
86
|
+
# | Packing| Remaining Volume:382
|
87
|
+
# | Item| 7x6x4 (10,0,0) Volume:168
|
88
|
+
|
89
|
+
puts c2 # |Container| 23x17x14
|
90
|
+
# | Packing| Remaining Volume:4902
|
91
|
+
# | Item| 10x8x5 (0,0,0) Volume:400
|
92
|
+
# | Item| 7x6x4 (10,0,0) Volume:168
|
93
|
+
# | Item| 4x1x1 (17,0,0) Volume:4
|
94
|
+
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
98
|
+
Export SVG
|
99
|
+
----------
|
100
|
+
|
101
|
+
``` ruby
|
102
|
+
BoxPacker.container [3, 4, 2] do
|
103
|
+
add_item [1,3,2], label: 'Bag', colour: 'red'
|
104
|
+
add_item [3,3,1], label: 'Hat', colour: 'blue'
|
105
|
+
add_item [1,2,2], label: 'Shoes', colour: 'green'
|
106
|
+
add_item [3,1,1], label: 'Slipper', colour: 'purple'
|
107
|
+
add_item [2,1,1], label: 'Dragon', colour: 'orange'
|
108
|
+
pack!
|
109
|
+
draw!('examples/example', scale_longest_side_to: 500, margin: 15)
|
110
|
+
end
|
111
|
+
```
|
112
|
+
|
113
|
+
Output:
|
114
|
+
|
115
115
|
![SVG Output](https://rawgit.com/mushishi78/box_packer/master/examples/example1.svg)
|
data/lib/box_packer/box.rb
CHANGED
@@ -22,7 +22,7 @@ module BoxPacker
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def sub_boxes_args(item)
|
25
|
-
[[width +
|
25
|
+
[[width + height + depth - item.width, position: position + item.width],
|
26
26
|
[item.width + height + depth - item.height, position: position + item.height],
|
27
27
|
[item.width + item.height + depth - item.depth, position: position + item.depth]]
|
28
28
|
end
|
data/lib/box_packer/container.rb
CHANGED
@@ -55,7 +55,7 @@ module BoxPacker
|
|
55
55
|
s << " Weight Limit:#{weight_limit}" if weight_limit
|
56
56
|
s << " Packings Limit:#{packings_limit}" if packings_limit
|
57
57
|
s << "\n"
|
58
|
-
s << packed_successfully ? packings.map(&:to_s).join : '| | Did Not Pack!'
|
58
|
+
s << (packed_successfully ? packings.map(&:to_s).join : '| | Did Not Pack!')
|
59
59
|
end
|
60
60
|
|
61
61
|
def draw!(filename, opts = {})
|
data/lib/box_packer/item.rb
CHANGED
data/lib/box_packer/packer.rb
CHANGED
@@ -25,7 +25,7 @@ module BoxPacker
|
|
25
25
|
possible_items = possible_items.dup
|
26
26
|
until possible_items.empty?
|
27
27
|
item = possible_items.shift
|
28
|
-
next unless item.
|
28
|
+
next unless item.rotate_to_fit_into(box)
|
29
29
|
|
30
30
|
pack_item!(item, possible_items, box)
|
31
31
|
break if possible_items.empty?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.2
|
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-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: attire
|
@@ -82,7 +82,7 @@ files:
|
|
82
82
|
- lib/box_packer/packing.rb
|
83
83
|
- lib/box_packer/position.rb
|
84
84
|
- lib/box_packer/svg_exporter.rb
|
85
|
-
homepage:
|
85
|
+
homepage: https://github.com/mushishi78/box_packer
|
86
86
|
licenses:
|
87
87
|
- MIT
|
88
88
|
metadata: {}
|