easy-box-packer 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/easy-box-packer.rb +26 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8fdf9c87fb9465a372621274314c24d467848dcc
|
4
|
+
data.tar.gz: 328700b5ffd7860761c832d43ade508b01749cac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 181a58237b38d18dd3672e01aa66bc93583de44c3be03258e9505edec538c9ab58d529a60dea4a7ff9dd4155747d008507baa9d475a13dfd62f942f0f0e8f54c
|
7
|
+
data.tar.gz: ffbf053c8ac2aa0213f32df3b4c8a87276f15ab7159dcfa6fe63d71a44fc88e92790422d3b2fdcbff3a9008a0682341b8b46747f7c0396cb50a2d6d6323cebaf
|
data/easy-box-packer.rb
CHANGED
@@ -139,5 +139,31 @@ module EasyBoxPacker
|
|
139
139
|
}
|
140
140
|
]
|
141
141
|
end
|
142
|
+
|
143
|
+
def find_smallest_container(items:)
|
144
|
+
array_of_lwh = items.map { |i| i[:dimensions].sort.reverse }
|
145
|
+
items_max_length = array_of_lwh.max { |x, y| x[0] <=> y[0] }[0]
|
146
|
+
items_max_width = array_of_lwh.max { |x, y| x[1] <=> y[1] }[1]
|
147
|
+
items_min_height = array_of_lwh.max { |x, y| x[2] <=> y[2] }[2]
|
148
|
+
items_total_height = array_of_lwh.inject(0) { |sum, x| sum + x[2] }.round(1)
|
149
|
+
miminum_box = {}
|
150
|
+
(items_min_height..items_total_height.ceil).step(0.1).to_a.bsearch do |i|
|
151
|
+
packing = pack(
|
152
|
+
container: { dimensions: [items_max_length, items_max_width, i] },
|
153
|
+
items: array_of_lwh.map { |a| { dimensions: a }})
|
154
|
+
|
155
|
+
if packing[:packings].size == 1
|
156
|
+
miminum_box = {
|
157
|
+
length: items_max_length,
|
158
|
+
width: items_max_width,
|
159
|
+
height: i
|
160
|
+
}
|
161
|
+
true
|
162
|
+
else
|
163
|
+
false
|
164
|
+
end
|
165
|
+
end
|
166
|
+
miminum_box
|
167
|
+
end
|
142
168
|
end
|
143
169
|
end
|