binpack 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/binpack.rb +8 -8
- data/lib/binpack/version.rb +1 -1
- metadata +2 -2
data/lib/binpack.rb
CHANGED
@@ -19,7 +19,7 @@ module Binpack
|
|
19
19
|
def initialize(width, height, padding=1)
|
20
20
|
@width, @height, @padding = width, height, padding.to_i
|
21
21
|
@items = []
|
22
|
-
@rows = (
|
22
|
+
@rows = (0...@height + (@padding * 2)).map{ "_"*(@width + (@padding * 2)) }
|
23
23
|
end
|
24
24
|
|
25
25
|
def add(item)
|
@@ -28,17 +28,17 @@ module Binpack
|
|
28
28
|
alias_method "<<".to_sym, :add
|
29
29
|
|
30
30
|
def try_adding(item)
|
31
|
-
itemrow = "_" * (item.width + (@padding * 2))
|
31
|
+
itemrow = "_" * (item.width.ceil + (@padding * 2))
|
32
32
|
@rows.each_with_index {|r,i|
|
33
|
-
break if i > @rows.size - (item.
|
33
|
+
break if i > @rows.size - (item.height.ceil + @padding * 2)
|
34
34
|
next unless r.include?(itemrow)
|
35
|
-
idxs = @rows[i + @padding, item.height + @padding].map { |s| s.index(itemrow) }
|
35
|
+
idxs = @rows[i + @padding, item.height.ceil + @padding].map { |s| s.index(itemrow) }
|
36
36
|
next unless idxs.all?
|
37
37
|
idx = idxs.max
|
38
|
-
next unless @rows[i, item.height + (@padding*2)].all? { |s| s[idx,itemrow.size] == itemrow }
|
38
|
+
next unless @rows[i, item.height.ceil + (@padding * 2)].all? { |s| s[idx,itemrow.size] == itemrow }
|
39
39
|
g = rand(16).to_s(16)
|
40
|
-
@rows[i + @padding, item.height].each{ |s|
|
41
|
-
s[idx + @padding, item.width] = "#{g}" * item.width
|
40
|
+
@rows[i + @padding, item.height.ceil].each{ |s|
|
41
|
+
s[idx + @padding, item.width.ceil] = "#{g}" * item.width.ceil
|
42
42
|
}
|
43
43
|
@items.push([item, idx, i])
|
44
44
|
return item
|
@@ -74,4 +74,4 @@ module Binpack
|
|
74
74
|
bins
|
75
75
|
end
|
76
76
|
end
|
77
|
-
end
|
77
|
+
end
|
data/lib/binpack/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: binpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-25 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: 2 dimensional bin packing library adapted from a RubyQuiz solution by
|
15
15
|
Ilmari Heikkinen
|