easy-box-packer 0.0.5 → 0.0.6
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 +30 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e39931d70dad5421a82dbe062c8826cf63e27db8
|
4
|
+
data.tar.gz: f9a516ed16ec7c8d72beb901e648399462d42d40
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07a6251fdef61a2f4de967d3289e84f834dc4c4e33d1fa202cffce483d189ae56e99acea299cc0f6d1788e7998f3d8ee1de88f7f5f3226a5ad918bdba5d122b1
|
7
|
+
data.tar.gz: d3df8428a5d8b7acd95fdbd87783a51020f1651aa31d85525d7286722ee09b817dc7e8db047623b655e514b82bb2d18b79b9252c6d401428c04a873beb7d421d
|
data/easy-box-packer.rb
CHANGED
@@ -62,7 +62,11 @@ module EasyBoxPacker
|
|
62
62
|
}]
|
63
63
|
end
|
64
64
|
|
65
|
-
|
65
|
+
if packings.size > 1 && check_container_is_bigger_than_greedy_box(container, items)
|
66
|
+
{ packings: generate_packing_for_greedy_box(items), errors: [] }
|
67
|
+
else
|
68
|
+
{ packings: packings, errors: errors }
|
69
|
+
end
|
66
70
|
end
|
67
71
|
|
68
72
|
def find_smallest_container(items:)
|
@@ -426,5 +430,30 @@ module EasyBoxPacker
|
|
426
430
|
# PICK biggest
|
427
431
|
return_possible_spaces.sort_by { |a| a.map {|aa| aa[:dimensions].sort}}.last
|
428
432
|
end
|
433
|
+
|
434
|
+
def item_greedy_box(items)
|
435
|
+
array_of_lwh = items.map { |i| i[:dimensions].sort.reverse }
|
436
|
+
items_max_length = array_of_lwh.max { |x, y| x[0] <=> y[0] }[0]
|
437
|
+
items_max_width = array_of_lwh.max { |x, y| x[1] <=> y[1] }[1]
|
438
|
+
items_total_height = array_of_lwh.inject(0) { |sum, x| sum+=x[2] }.round(1)
|
439
|
+
[items_max_length, items_max_width, items_total_height]
|
440
|
+
end
|
441
|
+
|
442
|
+
def check_container_is_bigger_than_greedy_box(container, items)
|
443
|
+
c = container[:dimensions].sort.reverse
|
444
|
+
greedy_box = item_greedy_box(items)
|
445
|
+
c[0] >= greedy_box[0] && c[1] >= greedy_box[1] && c[2] >= greedy_box[2] && container[:weight_limit].to_f >= items.inject(0) { |sum, i| sum += i[:weight].to_f }
|
446
|
+
end
|
447
|
+
|
448
|
+
def generate_packing_for_greedy_box(items)
|
449
|
+
return_h = {placements: [], weight: 0, spaces: []}
|
450
|
+
height = 0
|
451
|
+
items.each do |i|
|
452
|
+
return_h[:placements] << { dimensions: i[:dimensions], :position=>[0, 0, height], weight: i[:weight].to_f }
|
453
|
+
return_h[:weight] += i[:weight].to_f
|
454
|
+
height += i[:dimensions].sort.first.to_f
|
455
|
+
end
|
456
|
+
[return_h]
|
457
|
+
end
|
429
458
|
end
|
430
459
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy-box-packer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aloha Chen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|