sprite-factory-custom 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/Gemfile +12 -0
- data/LICENSE +20 -0
- data/README.md +351 -0
- data/RELEASE_NOTES.md +60 -0
- data/Rakefile +73 -0
- data/bin/sf +57 -0
- data/lib/sprite_factory/layout/horizontal.rb +44 -0
- data/lib/sprite_factory/layout/packed.rb +118 -0
- data/lib/sprite_factory/layout/vertical.rb +44 -0
- data/lib/sprite_factory/library/chunky_png.rb +31 -0
- data/lib/sprite_factory/library/image_magick.rb +74 -0
- data/lib/sprite_factory/library/rmagick.rb +32 -0
- data/lib/sprite_factory/runner.rb +287 -0
- data/lib/sprite_factory/style.rb +74 -0
- data/lib/sprite_factory.rb +85 -0
- data/sprite_factory.gemspec +27 -0
- data/test/images/custom/custom.css +4 -0
- data/test/images/custom/running.png +0 -0
- data/test/images/custom/stopped.png +0 -0
- data/test/images/empty/readme.txt +1 -0
- data/test/images/formats/alice.gif +0 -0
- data/test/images/formats/codeincomplete.ico +0 -0
- data/test/images/formats/github.ico +0 -0
- data/test/images/formats/monkey.gif +0 -0
- data/test/images/formats/spies.jpg +0 -0
- data/test/images/formats/stackoverflow.ico +0 -0
- data/test/images/formats/thief.png +0 -0
- data/test/images/hover/div.bar__img.icon--active.png +0 -0
- data/test/images/hover/div.bar__img.icon--focus.png +0 -0
- data/test/images/hover/div.bar__img.icon--hover.png +0 -0
- data/test/images/hover/div.bar__img.icon--link.png +0 -0
- data/test/images/hover/div.bar__img.icon--visited.png +0 -0
- data/test/images/hover/div.bar__img.icon.png +0 -0
- data/test/images/hover/div.foo__img.icon--active.png +0 -0
- data/test/images/hover/div.foo__img.icon--focus.png +0 -0
- data/test/images/hover/div.foo__img.icon--hover.png +0 -0
- data/test/images/hover/div.foo__img.icon--link.png +0 -0
- data/test/images/hover/div.foo__img.icon--visited.png +0 -0
- data/test/images/hover/div.foo__img.icon.png +0 -0
- data/test/images/irregular/irregular1.png +0 -0
- data/test/images/irregular/irregular2.png +0 -0
- data/test/images/irregular/irregular3.png +0 -0
- data/test/images/irregular/irregular4.png +0 -0
- data/test/images/irregular/irregular5.png +0 -0
- data/test/images/irregular/readme.txt +2 -0
- data/test/images/reference/custom.css +22 -0
- data/test/images/reference/custom.png +0 -0
- data/test/images/reference/formats.css +28 -0
- data/test/images/reference/formats.png +0 -0
- data/test/images/reference/hover.css +38 -0
- data/test/images/reference/hover.png +0 -0
- data/test/images/reference/index.html +182 -0
- data/test/images/reference/irregular.css +24 -0
- data/test/images/reference/irregular.fixed.css +24 -0
- data/test/images/reference/irregular.fixed.png +0 -0
- data/test/images/reference/irregular.horizontal.css +24 -0
- data/test/images/reference/irregular.horizontal.png +0 -0
- data/test/images/reference/irregular.margin.css +24 -0
- data/test/images/reference/irregular.margin.png +0 -0
- data/test/images/reference/irregular.packed.css +24 -0
- data/test/images/reference/irregular.packed.png +0 -0
- data/test/images/reference/irregular.padded.css +24 -0
- data/test/images/reference/irregular.padded.png +0 -0
- data/test/images/reference/irregular.png +0 -0
- data/test/images/reference/irregular.sassy.css +38 -0
- data/test/images/reference/irregular.sassy.png +0 -0
- data/test/images/reference/irregular.sassy.sass +40 -0
- data/test/images/reference/irregular.vertical.css +24 -0
- data/test/images/reference/irregular.vertical.png +0 -0
- data/test/images/reference/regular.css +24 -0
- data/test/images/reference/regular.custom.css +24 -0
- data/test/images/reference/regular.custom.png +0 -0
- data/test/images/reference/regular.fixed.css +24 -0
- data/test/images/reference/regular.fixed.png +0 -0
- data/test/images/reference/regular.horizontal.css +24 -0
- data/test/images/reference/regular.horizontal.png +0 -0
- data/test/images/reference/regular.margin.css +24 -0
- data/test/images/reference/regular.margin.png +0 -0
- data/test/images/reference/regular.nocomments.css +5 -0
- data/test/images/reference/regular.nocomments.png +0 -0
- data/test/images/reference/regular.packed.css +24 -0
- data/test/images/reference/regular.packed.png +0 -0
- data/test/images/reference/regular.padded.css +24 -0
- data/test/images/reference/regular.padded.png +0 -0
- data/test/images/reference/regular.png +0 -0
- data/test/images/reference/regular.sassy.css +38 -0
- data/test/images/reference/regular.sassy.png +0 -0
- data/test/images/reference/regular.sassy.sass +40 -0
- data/test/images/reference/regular.vertical.css +24 -0
- data/test/images/reference/regular.vertical.png +0 -0
- data/test/images/reference/s.gif +0 -0
- data/test/images/reference/subfolders.css +24 -0
- data/test/images/reference/subfolders.png +0 -0
- data/test/images/regular/regular1.PNG +0 -0
- data/test/images/regular/regular2.PNG +0 -0
- data/test/images/regular/regular3.PNG +0 -0
- data/test/images/regular/regular4.PNG +0 -0
- data/test/images/regular/regular5.PNG +0 -0
- data/test/images/subfolders/england/amy.png +0 -0
- data/test/images/subfolders/england/bob.png +0 -0
- data/test/images/subfolders/france/bob.png +0 -0
- data/test/images/subfolders/usa/amy.png +0 -0
- data/test/images/subfolders/usa/bob.png +0 -0
- data/test/integration_test.rb +167 -0
- data/test/layout/horizontal_test.rb +156 -0
- data/test/layout/packed_test.rb +283 -0
- data/test/layout/test_case.rb +56 -0
- data/test/layout/vertical_test.rb +156 -0
- data/test/library_test.rb +58 -0
- data/test/runner_test.rb +229 -0
- data/test/style_test.rb +72 -0
- data/test/test_case.rb +138 -0
- metadata +286 -0
@@ -0,0 +1,156 @@
|
|
1
|
+
require File.expand_path('test_case', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
module SpriteFactory
|
4
|
+
module Layout
|
5
|
+
class HorizontalTest < SpriteFactory::Layout::TestCase
|
6
|
+
|
7
|
+
#==========================================================================
|
8
|
+
# test REGULAR images
|
9
|
+
#==========================================================================
|
10
|
+
|
11
|
+
def test_horizontal_layout_of_regular_images
|
12
|
+
images = get_regular_images
|
13
|
+
expected = [
|
14
|
+
{ :x => 0, :y => 0 },
|
15
|
+
{ :x => 20, :y => 0 },
|
16
|
+
{ :x => 40, :y => 0 },
|
17
|
+
{ :x => 60, :y => 0 },
|
18
|
+
{ :x => 80, :y => 0 }
|
19
|
+
]
|
20
|
+
verify_layout(100, 10, expected, images, :layout => :horizontal)
|
21
|
+
end
|
22
|
+
|
23
|
+
#--------------------------------------------------------------------------
|
24
|
+
|
25
|
+
def test_padded_horizontal_layout_of_regular_images
|
26
|
+
images = get_regular_images
|
27
|
+
expected = [
|
28
|
+
{ :cssx => 0, :cssy => 0, :cssw => 40, :cssh => 50, :x => 10, :y => 20 },
|
29
|
+
{ :cssx => 40, :cssy => 0, :cssw => 40, :cssh => 50, :x => 50, :y => 20 },
|
30
|
+
{ :cssx => 80, :cssy => 0, :cssw => 40, :cssh => 50, :x => 90, :y => 20 },
|
31
|
+
{ :cssx => 120, :cssy => 0, :cssw => 40, :cssh => 50, :x => 130, :y => 20 },
|
32
|
+
{ :cssx => 160, :cssy => 0, :cssw => 40, :cssh => 50, :x => 170, :y => 20 }
|
33
|
+
]
|
34
|
+
verify_layout(200, 50, expected, images, :layout => :horizontal, :hpadding => 10, :vpadding => 20)
|
35
|
+
end
|
36
|
+
|
37
|
+
#--------------------------------------------------------------------------
|
38
|
+
|
39
|
+
def test_margin_horizontal_layout_of_regular_images
|
40
|
+
images = get_regular_images
|
41
|
+
expected = [
|
42
|
+
{ :cssx => 10, :cssy => 20, :cssw => 20, :cssh => 10, :x => 10, :y => 20 },
|
43
|
+
{ :cssx => 50, :cssy => 20, :cssw => 20, :cssh => 10, :x => 50, :y => 20 },
|
44
|
+
{ :cssx => 90, :cssy => 20, :cssw => 20, :cssh => 10, :x => 90, :y => 20 },
|
45
|
+
{ :cssx => 130, :cssy => 20, :cssw => 20, :cssh => 10, :x => 130, :y => 20 },
|
46
|
+
{ :cssx => 170, :cssy => 20, :cssw => 20, :cssh => 10, :x => 170, :y => 20 }
|
47
|
+
]
|
48
|
+
verify_layout(200, 50, expected, images, :layout => :horizontal, :hmargin => 10, :vmargin => 20)
|
49
|
+
end
|
50
|
+
|
51
|
+
#--------------------------------------------------------------------------
|
52
|
+
|
53
|
+
def test_padded_and_margin_horizontal_layout_of_regular_images
|
54
|
+
images = get_regular_images
|
55
|
+
expected = [
|
56
|
+
{ :cssx => 10, :cssy => 20, :cssw => 24, :cssh => 18, :x => 12, :y => 24 },
|
57
|
+
{ :cssx => 54, :cssy => 20, :cssw => 24, :cssh => 18, :x => 56, :y => 24 },
|
58
|
+
{ :cssx => 98, :cssy => 20, :cssw => 24, :cssh => 18, :x => 100, :y => 24 },
|
59
|
+
{ :cssx => 142, :cssy => 20, :cssw => 24, :cssh => 18, :x => 144, :y => 24 },
|
60
|
+
{ :cssx => 186, :cssy => 20, :cssw => 24, :cssh => 18, :x => 188, :y => 24 }
|
61
|
+
]
|
62
|
+
verify_layout(220, 58, expected, images, :layout => :horizontal, :hmargin => 10, :vmargin => 20, :hpadding => 2, :vpadding => 4)
|
63
|
+
end
|
64
|
+
|
65
|
+
#--------------------------------------------------------------------------
|
66
|
+
|
67
|
+
def test_fixed_horizontal_layout_of_regular_images
|
68
|
+
images = get_regular_images
|
69
|
+
expected = [
|
70
|
+
{ :cssx => 0, :cssy => 0, :cssw => 50, :cssh => 50, :x => 15, :y => 20 },
|
71
|
+
{ :cssx => 50, :cssy => 0, :cssw => 50, :cssh => 50, :x => 65, :y => 20 },
|
72
|
+
{ :cssx => 100, :cssy => 0, :cssw => 50, :cssh => 50, :x => 115, :y => 20 },
|
73
|
+
{ :cssx => 150, :cssy => 0, :cssw => 50, :cssh => 50, :x => 165, :y => 20 },
|
74
|
+
{ :cssx => 200, :cssy => 0, :cssw => 50, :cssh => 50, :x => 215, :y => 20 }
|
75
|
+
]
|
76
|
+
verify_layout(250, 50, expected, images, :layout => :horizontal, :width => 50, :height => 50)
|
77
|
+
end
|
78
|
+
|
79
|
+
#==========================================================================
|
80
|
+
# test IRREGULAR images
|
81
|
+
#==========================================================================
|
82
|
+
|
83
|
+
def test_horizontal_layout_of_irregular_images
|
84
|
+
images = get_irregular_images
|
85
|
+
expected = [
|
86
|
+
{ :x => 0, :y => 0 },
|
87
|
+
{ :x => 20, :y => 5 },
|
88
|
+
{ :x => 60, :y => 10 },
|
89
|
+
{ :x => 120, :y => 15 },
|
90
|
+
{ :x => 200, :y => 20 }
|
91
|
+
]
|
92
|
+
verify_layout(300, 50, expected, images, :layout => :horizontal)
|
93
|
+
end
|
94
|
+
|
95
|
+
#--------------------------------------------------------------------------
|
96
|
+
|
97
|
+
def test_padded_horizontal_layout_of_irregular_images
|
98
|
+
images = get_irregular_images
|
99
|
+
expected = [
|
100
|
+
{ :cssx => 0, :cssy => 0, :cssw => 40, :cssh => 90, :x => 10, :y => 20 },
|
101
|
+
{ :cssx => 40, :cssy => 5, :cssw => 60, :cssh => 80, :x => 50, :y => 25 },
|
102
|
+
{ :cssx => 100, :cssy => 10, :cssw => 80, :cssh => 70, :x => 110, :y => 30 },
|
103
|
+
{ :cssx => 180, :cssy => 15, :cssw => 100, :cssh => 60, :x => 190, :y => 35 },
|
104
|
+
{ :cssx => 280, :cssy => 20, :cssw => 120, :cssh => 50, :x => 290, :y => 40 }
|
105
|
+
]
|
106
|
+
verify_layout(400, 90, expected, images, :layout => :horizontal, :hpadding => 10, :vpadding => 20)
|
107
|
+
end
|
108
|
+
|
109
|
+
#--------------------------------------------------------------------------
|
110
|
+
|
111
|
+
def test_margin_horizontal_layout_of_irregular_images
|
112
|
+
images = get_irregular_images
|
113
|
+
expected = [
|
114
|
+
{ :cssx => 10, :cssy => 20, :cssw => 20, :cssh => 50, :x => 10, :y => 20 },
|
115
|
+
{ :cssx => 50, :cssy => 25, :cssw => 40, :cssh => 40, :x => 50, :y => 25 },
|
116
|
+
{ :cssx => 110, :cssy => 30, :cssw => 60, :cssh => 30, :x => 110, :y => 30 },
|
117
|
+
{ :cssx => 190, :cssy => 35, :cssw => 80, :cssh => 20, :x => 190, :y => 35 },
|
118
|
+
{ :cssx => 290, :cssy => 40, :cssw => 100, :cssh => 10, :x => 290, :y => 40 }
|
119
|
+
]
|
120
|
+
verify_layout(400, 90, expected, images, :layout => :horizontal, :hmargin => 10, :vmargin => 20)
|
121
|
+
end
|
122
|
+
|
123
|
+
#--------------------------------------------------------------------------
|
124
|
+
|
125
|
+
def test_padded_and_margin_horizontal_layout_of_irregular_images
|
126
|
+
images = get_irregular_images
|
127
|
+
expected = [
|
128
|
+
{ :cssx => 10, :cssy => 20, :cssw => 24, :cssh => 58, :x => 12, :y => 24 },
|
129
|
+
{ :cssx => 54, :cssy => 25, :cssw => 44, :cssh => 48, :x => 56, :y => 29 },
|
130
|
+
{ :cssx => 118, :cssy => 30, :cssw => 64, :cssh => 38, :x => 120, :y => 34 },
|
131
|
+
{ :cssx => 202, :cssy => 35, :cssw => 84, :cssh => 28, :x => 204, :y => 39 },
|
132
|
+
{ :cssx => 306, :cssy => 40, :cssw => 104, :cssh => 18, :x => 308, :y => 44 }
|
133
|
+
]
|
134
|
+
verify_layout(420, 98, expected, images, :layout => :horizontal, :hmargin => 10, :vmargin => 20, :hpadding => 2, :vpadding => 4)
|
135
|
+
end
|
136
|
+
|
137
|
+
#--------------------------------------------------------------------------
|
138
|
+
|
139
|
+
def test_fixed_horizontal_layout_of_irregular_images
|
140
|
+
images = get_irregular_images
|
141
|
+
expected = [
|
142
|
+
{ :cssx => 0, :cssy => 0, :cssw => 100, :cssh => 100, :x => 40, :y => 25 },
|
143
|
+
{ :cssx => 100, :cssy => 0, :cssw => 100, :cssh => 100, :x => 130, :y => 30 },
|
144
|
+
{ :cssx => 200, :cssy => 0, :cssw => 100, :cssh => 100, :x => 220, :y => 35 },
|
145
|
+
{ :cssx => 300, :cssy => 0, :cssw => 100, :cssh => 100, :x => 310, :y => 40 },
|
146
|
+
{ :cssx => 400, :cssy => 0, :cssw => 100, :cssh => 100, :x => 400, :y => 45 }
|
147
|
+
]
|
148
|
+
verify_layout(500, 100, expected, images, :layout => :horizontal, :width => 100, :height => 100)
|
149
|
+
end
|
150
|
+
|
151
|
+
#--------------------------------------------------------------------------
|
152
|
+
|
153
|
+
end # class HorizontalTest
|
154
|
+
end # module Layout
|
155
|
+
end # module SpriteFactory
|
156
|
+
|
@@ -0,0 +1,283 @@
|
|
1
|
+
require File.expand_path('test_case', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
module SpriteFactory
|
4
|
+
module Layout
|
5
|
+
class PackedTest < SpriteFactory::Layout::TestCase
|
6
|
+
|
7
|
+
#==========================================================================
|
8
|
+
# test REGULAR images
|
9
|
+
#==========================================================================
|
10
|
+
|
11
|
+
def test_packed_layout_of_regular_images
|
12
|
+
images = get_regular_images
|
13
|
+
expected = [ # expected: -------
|
14
|
+
{ :cssx => 0, :cssy => 0, :cssw => 20, :cssh => 10, :x => 0, :y => 0 }, # |11|33|
|
15
|
+
{ :cssx => 0, :cssy => 10, :cssw => 20, :cssh => 10, :x => 0, :y => 10 }, # -------
|
16
|
+
{ :cssx => 20, :cssy => 0, :cssw => 20, :cssh => 10, :x => 20, :y => 0 }, # |22|44|
|
17
|
+
{ :cssx => 20, :cssy => 10, :cssw => 20, :cssh => 10, :x => 20, :y => 10 }, # -------
|
18
|
+
{ :cssx => 0, :cssy => 20, :cssw => 20, :cssh => 10, :x => 0, :y => 20 } # |55| |
|
19
|
+
] # -------
|
20
|
+
verify_layout(40, 30, expected, images, :layout => :packed)
|
21
|
+
end
|
22
|
+
|
23
|
+
#--------------------------------------------------------------------------
|
24
|
+
|
25
|
+
def test_padded_packed_layout_of_regular_images # expected: ---------------
|
26
|
+
# | | |
|
27
|
+
images = get_regular_images # | 11 | 33 |
|
28
|
+
expected = [ # | | |
|
29
|
+
{ :cssx => 0, :cssy => 0, :cssw => 60, :cssh => 30, :x => 20, :y => 10 }, # ---------------
|
30
|
+
{ :cssx => 0, :cssy => 30, :cssw => 60, :cssh => 30, :x => 20, :y => 40 }, # | | |
|
31
|
+
{ :cssx => 60, :cssy => 0, :cssw => 60, :cssh => 30, :x => 80, :y => 10 }, # | 22 | 44 |
|
32
|
+
{ :cssx => 60, :cssy => 30, :cssw => 60, :cssh => 30, :x => 80, :y => 40 }, # | | |
|
33
|
+
{ :cssx => 0, :cssy => 60, :cssw => 60, :cssh => 30, :x => 20, :y => 70 } # ---------------
|
34
|
+
] # | |
|
35
|
+
verify_layout(120, 90, expected, images, :layout => :packed, # | 55 |
|
36
|
+
:hpadding => 20, # | |
|
37
|
+
:vpadding => 10) # --------
|
38
|
+
end
|
39
|
+
|
40
|
+
#--------------------------------------------------------------------------
|
41
|
+
|
42
|
+
def test_margin_packed_layout_of_regular_images # expected: ---------------
|
43
|
+
# | | |
|
44
|
+
images = get_regular_images # | 11 | 33 |
|
45
|
+
expected = [ # | | |
|
46
|
+
{ :cssx => 20, :cssy => 10, :cssw => 20, :cssh => 10, :x => 20, :y => 10 }, # ---------------
|
47
|
+
{ :cssx => 20, :cssy => 40, :cssw => 20, :cssh => 10, :x => 20, :y => 40 }, # | | |
|
48
|
+
{ :cssx => 80, :cssy => 10, :cssw => 20, :cssh => 10, :x => 80, :y => 10 }, # | 22 | 44 |
|
49
|
+
{ :cssx => 80, :cssy => 40, :cssw => 20, :cssh => 10, :x => 80, :y => 40 }, # | | |
|
50
|
+
{ :cssx => 20, :cssy => 70, :cssw => 20, :cssh => 10, :x => 20, :y => 70 } # ---------------
|
51
|
+
] # | |
|
52
|
+
verify_layout(120, 90, expected, images, :layout => :packed, # | 55 |
|
53
|
+
:hmargin => 20, # | |
|
54
|
+
:vmargin => 10) # --------
|
55
|
+
end
|
56
|
+
|
57
|
+
#--------------------------------------------------------------------------
|
58
|
+
|
59
|
+
def test_fixed_packed_layout_of_regular_images
|
60
|
+
assert_not_implemented ":packed layout does not support fixed :width/:height option" do
|
61
|
+
Layout::Packed.layout(get_regular_images, :width => 50, :height => 50)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
#==========================================================================
|
66
|
+
# test IRREGULAR images
|
67
|
+
#==========================================================================
|
68
|
+
|
69
|
+
def test_packed_layout_of_irregular_images
|
70
|
+
images = get_irregular_images
|
71
|
+
# expected: ---------------
|
72
|
+
expected = [ # |1111111111|44|
|
73
|
+
{ :cssx => 0, :cssy => 0, :cssw => 100, :cssh => 10, :x => 0, :y => 0 }, # -----------|44|
|
74
|
+
{ :cssx => 0, :cssy => 10, :cssw => 80, :cssh => 20, :x => 0, :y => 10 }, # |22222222| |44|
|
75
|
+
{ :cssx => 0, :cssy => 30, :cssw => 60, :cssh => 30, :x => 0, :y => 30 }, # -----------|44|
|
76
|
+
{ :cssx => 100, :cssy => 0, :cssw => 20, :cssh => 50, :x => 100, :y => 0 }, # |333333| ----
|
77
|
+
{ :cssx => 0, :cssy => 60, :cssw => 40, :cssh => 40, :x => 0, :y => 60 } # ---------------
|
78
|
+
] # |5555| |
|
79
|
+
# ---------------
|
80
|
+
verify_layout(120, 100, expected, images, :layout => :packed)
|
81
|
+
end
|
82
|
+
|
83
|
+
#--------------------------------------------------------------------------
|
84
|
+
|
85
|
+
def test_padded_packed_layout_of_irregular_images # expected: (but with more vertical padding than shown here)
|
86
|
+
images = get_irregular_images #
|
87
|
+
# -------------------------
|
88
|
+
expected = [ # | 1111111111 | 4444 |
|
89
|
+
{ :cssx => 0, :cssy => 0, :cssw => 140, :cssh => 30, :x => 20, :y => 10 }, # ---------------- 4444 |
|
90
|
+
{ :cssx => 0, :cssy => 30, :cssw => 120, :cssh => 40, :x => 20, :y => 40 }, # | 22222222 | ----------
|
91
|
+
{ :cssx => 0, :cssy => 70, :cssw => 100, :cssh => 50, :x => 20, :y => 80 }, # -------------- |
|
92
|
+
{ :cssx => 140, :cssy => 0, :cssw => 80, :cssh => 60, :x => 160, :y => 10 }, # | 333333 | |
|
93
|
+
{ :cssx => 0, :cssy => 120, :cssw => 60, :cssh => 70, :x => 20, :y => 130 } # |----------- |
|
94
|
+
] # | 55 | |
|
95
|
+
# -------------------------
|
96
|
+
verify_layout(220, 190, expected, images, :layout => :packed, #
|
97
|
+
:hpadding => 20, #
|
98
|
+
:vpadding => 10) #
|
99
|
+
end
|
100
|
+
|
101
|
+
#--------------------------------------------------------------------------
|
102
|
+
|
103
|
+
def test_margin_packed_layout_of_irregular_images # expected: (but with more vertical margin than shown here)
|
104
|
+
images = get_irregular_images #
|
105
|
+
# -------------------------
|
106
|
+
expected = [ # | 1111111111 | 4444 |
|
107
|
+
{ :cssx => 20, :cssy => 10, :cssw => 100, :cssh => 10, :x => 20, :y => 10 }, # ---------------- 4444 |
|
108
|
+
{ :cssx => 20, :cssy => 40, :cssw => 80, :cssh => 20, :x => 20, :y => 40 }, # | 22222222 | ----------
|
109
|
+
{ :cssx => 20, :cssy => 80, :cssw => 60, :cssh => 30, :x => 20, :y => 80 }, # -------------- |
|
110
|
+
{ :cssx => 160, :cssy => 10, :cssw => 40, :cssh => 40, :x => 160, :y => 10 }, # | 333333 | |
|
111
|
+
{ :cssx => 20, :cssy => 130, :cssw => 20, :cssh => 50, :x => 20, :y => 130 } # |----------- |
|
112
|
+
] # | 55 | |
|
113
|
+
# -------------------------
|
114
|
+
verify_layout(220, 190, expected, images, :layout => :packed, #
|
115
|
+
:hmargin => 20, #
|
116
|
+
:vmargin => 10) #
|
117
|
+
end
|
118
|
+
|
119
|
+
#==========================================================================
|
120
|
+
# other packed algorithm test
|
121
|
+
#==========================================================================
|
122
|
+
|
123
|
+
def test_single_image_is_100_percent_packed
|
124
|
+
images = [
|
125
|
+
{ :width => 100, :height => 100 },
|
126
|
+
{ :width => 100, :height => 50 },
|
127
|
+
{ :width => 50, :height => 100 }
|
128
|
+
]
|
129
|
+
images.each do |image|
|
130
|
+
verify_layout(image[:width], image[:height], [{:x => 0, :y => 0}], [image], :layout => :packed)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
#==========================================================================
|
135
|
+
# some test cases from original bin packing demonstration
|
136
|
+
# (see http://codeincomplete.com/posts/2011/5/7/bin_packing/example/)
|
137
|
+
#==========================================================================
|
138
|
+
|
139
|
+
def test_packed_simple
|
140
|
+
images = expanded_images([
|
141
|
+
{ :width => 500, :height => 200 },
|
142
|
+
{ :width => 250, :height => 200 },
|
143
|
+
{ :width => 50, :height => 50, :num => 20 }
|
144
|
+
])
|
145
|
+
expected = [
|
146
|
+
{ :x => 0, :y => 0 },
|
147
|
+
{ :x => 0, :y => 200 },
|
148
|
+
{ :x => 250, :y => 200 },
|
149
|
+
{ :x => 300, :y => 200 },
|
150
|
+
{ :x => 350, :y => 200 },
|
151
|
+
{ :x => 400, :y => 200 },
|
152
|
+
{ :x => 450, :y => 200 },
|
153
|
+
{ :x => 250, :y => 250 },
|
154
|
+
{ :x => 300, :y => 250 },
|
155
|
+
{ :x => 350, :y => 250 },
|
156
|
+
{ :x => 400, :y => 250 },
|
157
|
+
{ :x => 450, :y => 250 },
|
158
|
+
{ :x => 250, :y => 300 },
|
159
|
+
{ :x => 300, :y => 300 },
|
160
|
+
{ :x => 350, :y => 300 },
|
161
|
+
{ :x => 400, :y => 300 },
|
162
|
+
{ :x => 450, :y => 300 },
|
163
|
+
{ :x => 250, :y => 350 },
|
164
|
+
{ :x => 300, :y => 350 },
|
165
|
+
{ :x => 350, :y => 350 },
|
166
|
+
{ :x => 400, :y => 350 },
|
167
|
+
{ :x => 450, :y => 350 }
|
168
|
+
]
|
169
|
+
verify_layout(500, 400, expected, images, :layout => :packed)
|
170
|
+
end
|
171
|
+
|
172
|
+
#--------------------------------------------------------------------------
|
173
|
+
|
174
|
+
def test_packed_square
|
175
|
+
images = expanded_images([{ :width => 50, :height => 50, :num => 16 }])
|
176
|
+
expected = [
|
177
|
+
{ :x => 0, :y => 0 },
|
178
|
+
{ :x => 50, :y => 0 },
|
179
|
+
{ :x => 0, :y => 50 },
|
180
|
+
{ :x => 50, :y => 50 },
|
181
|
+
{ :x => 100, :y => 0 },
|
182
|
+
{ :x => 100, :y => 50 },
|
183
|
+
{ :x => 0, :y => 100 },
|
184
|
+
{ :x => 50, :y => 100 },
|
185
|
+
{ :x => 100, :y => 100 },
|
186
|
+
{ :x => 150, :y => 0 },
|
187
|
+
{ :x => 150, :y => 50 },
|
188
|
+
{ :x => 150, :y => 100 },
|
189
|
+
{ :x => 0, :y => 150 },
|
190
|
+
{ :x => 50, :y => 150 },
|
191
|
+
{ :x => 100, :y => 150 },
|
192
|
+
{ :x => 150, :y => 150 }
|
193
|
+
]
|
194
|
+
verify_layout(200, 200, expected, images, :layout => :packed)
|
195
|
+
end
|
196
|
+
|
197
|
+
#--------------------------------------------------------------------------
|
198
|
+
|
199
|
+
def test_packed_tall
|
200
|
+
images = expanded_images([{ :width => 50, :height => 500, :num => 5 }])
|
201
|
+
expected = [
|
202
|
+
{ :x => 0, :y => 0 },
|
203
|
+
{ :x => 50, :y => 0 },
|
204
|
+
{ :x => 100, :y => 0 },
|
205
|
+
{ :x => 150, :y => 0 },
|
206
|
+
{ :x => 200, :y => 0 }
|
207
|
+
]
|
208
|
+
verify_layout(250, 500, expected, images, :layout => :packed)
|
209
|
+
end
|
210
|
+
|
211
|
+
#--------------------------------------------------------------------------
|
212
|
+
|
213
|
+
def test_packed_wide
|
214
|
+
images = expanded_images([{ :width => 500, :height => 50, :num => 5 }])
|
215
|
+
expected = [
|
216
|
+
{ :x => 0, :y => 0 },
|
217
|
+
{ :x => 0, :y => 50 },
|
218
|
+
{ :x => 0, :y => 100 },
|
219
|
+
{ :x => 0, :y => 150 },
|
220
|
+
{ :x => 0, :y => 200 }
|
221
|
+
]
|
222
|
+
verify_layout(500, 250, expected, images, :layout => :packed)
|
223
|
+
end
|
224
|
+
|
225
|
+
#--------------------------------------------------------------------------
|
226
|
+
|
227
|
+
def test_packed_tall_and_wide
|
228
|
+
images = expanded_images([
|
229
|
+
{ :width => 50, :height => 500, :num => 3 },
|
230
|
+
{ :width => 500, :height => 50, :num => 3 }
|
231
|
+
])
|
232
|
+
expected = [
|
233
|
+
{ :x => 0, :y => 0 },
|
234
|
+
{ :x => 50, :y => 0 },
|
235
|
+
{ :x => 100, :y => 0 },
|
236
|
+
{ :x => 150, :y => 0 },
|
237
|
+
{ :x => 150, :y => 50 },
|
238
|
+
{ :x => 150, :y => 100 }
|
239
|
+
]
|
240
|
+
verify_layout(650, 500, expected, images, :layout => :packed)
|
241
|
+
end
|
242
|
+
|
243
|
+
#--------------------------------------------------------------------------
|
244
|
+
|
245
|
+
def test_packed_powers_of_2
|
246
|
+
images = expanded_images([
|
247
|
+
{ :width => 64, :height => 64, :num => 2 },
|
248
|
+
{ :width => 32, :height => 32, :num => 4 },
|
249
|
+
{ :width => 16, :height => 16, :num => 8 }
|
250
|
+
])
|
251
|
+
expected = [
|
252
|
+
{ :x => 0, :y => 0 },
|
253
|
+
{ :x => 64, :y => 0 },
|
254
|
+
{ :x => 0, :y => 64 },
|
255
|
+
{ :x => 32, :y => 64 },
|
256
|
+
{ :x => 64, :y => 64 },
|
257
|
+
{ :x => 96, :y => 64 },
|
258
|
+
{ :x => 0, :y => 96 },
|
259
|
+
{ :x => 16, :y => 96 },
|
260
|
+
{ :x => 32, :y => 96 },
|
261
|
+
{ :x => 48, :y => 96 },
|
262
|
+
{ :x => 64, :y => 96 },
|
263
|
+
{ :x => 80, :y => 96 },
|
264
|
+
{ :x => 96, :y => 96 },
|
265
|
+
{ :x => 112, :y => 96 }
|
266
|
+
]
|
267
|
+
verify_layout(128, 112, expected, images, :layout => :packed)
|
268
|
+
end
|
269
|
+
|
270
|
+
#--------------------------------------------------------------------------
|
271
|
+
|
272
|
+
protected
|
273
|
+
|
274
|
+
def expanded_images(images)
|
275
|
+
result = images.map do |i|
|
276
|
+
(1..(i[:num] || 1)).map{{:width => i[:width], :height => i[:height]}}
|
277
|
+
end.flatten
|
278
|
+
end
|
279
|
+
|
280
|
+
end # class PackedTest
|
281
|
+
end # module Layout
|
282
|
+
end # module SpriteFactory
|
283
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path('../test_case', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
module SpriteFactory
|
4
|
+
module Layout
|
5
|
+
class TestCase < SpriteFactory::TestCase
|
6
|
+
|
7
|
+
#==========================================================================
|
8
|
+
# layout test helpers
|
9
|
+
#==========================================================================
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def get_regular_images
|
14
|
+
return [
|
15
|
+
{:width => 20, :height => 10},
|
16
|
+
{:width => 20, :height => 10},
|
17
|
+
{:width => 20, :height => 10},
|
18
|
+
{:width => 20, :height => 10},
|
19
|
+
{:width => 20, :height => 10}
|
20
|
+
]
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_irregular_images
|
24
|
+
return [
|
25
|
+
{:width => 20, :height => 50},
|
26
|
+
{:width => 40, :height => 40},
|
27
|
+
{:width => 60, :height => 30},
|
28
|
+
{:width => 80, :height => 20},
|
29
|
+
{:width => 100, :height => 10}
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
#--------------------------------------------------------------------------
|
34
|
+
|
35
|
+
def verify_layout(expected_width, expected_height, expected_images, images, options = {})
|
36
|
+
max = Layout.send(options[:layout] || :horizontal).layout(images, options)
|
37
|
+
assert_equal(expected_width, max[:width])
|
38
|
+
assert_equal(expected_height, max[:height])
|
39
|
+
assert_equal(expected_images.length, images.length)
|
40
|
+
images.length.times.each do |n|
|
41
|
+
expected = expected_images[n]
|
42
|
+
actual = images[n]
|
43
|
+
assert_equal(expected[:x], actual[:x], "image #{n} - unexpected x")
|
44
|
+
assert_equal(expected[:y], actual[:y], "image #{n} - unexpected y")
|
45
|
+
assert_equal(expected[:cssx] || expected[:x], actual[:cssx], "image #{n} - unexpected cssx")
|
46
|
+
assert_equal(expected[:cssy] || expected[:y], actual[:cssy], "image #{n} - unexpected cssy")
|
47
|
+
assert_equal(expected[:cssw] || actual[:width], actual[:cssw], "image #{n} - unexpected cssw")
|
48
|
+
assert_equal(expected[:cssh] || actual[:height], actual[:cssh], "image #{n} - unexpected cssh")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
#--------------------------------------------------------------------------
|
53
|
+
|
54
|
+
end # class TestCase
|
55
|
+
end # module Layout
|
56
|
+
end # module SpriteFactory
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require File.expand_path('test_case', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
module SpriteFactory
|
4
|
+
module Layout
|
5
|
+
class VerticalTest < SpriteFactory::Layout::TestCase
|
6
|
+
|
7
|
+
#==========================================================================
|
8
|
+
# test REGULAR images
|
9
|
+
#==========================================================================
|
10
|
+
|
11
|
+
def test_vertical_layout_of_regular_images
|
12
|
+
images = get_regular_images
|
13
|
+
expected = [
|
14
|
+
{ :x => 0, :y => 0 },
|
15
|
+
{ :x => 0, :y => 10 },
|
16
|
+
{ :x => 0, :y => 20 },
|
17
|
+
{ :x => 0, :y => 30 },
|
18
|
+
{ :x => 0, :y => 40 }
|
19
|
+
]
|
20
|
+
verify_layout(20, 50, expected, images, :layout => :vertical)
|
21
|
+
end
|
22
|
+
|
23
|
+
#--------------------------------------------------------------------------
|
24
|
+
|
25
|
+
def test_padded_vertical_layout_of_regular_images
|
26
|
+
images = get_regular_images
|
27
|
+
expected = [
|
28
|
+
{ :cssx => 0, :cssy => 0, :cssw => 40, :cssh => 50, :x => 10, :y => 20 },
|
29
|
+
{ :cssx => 0, :cssy => 50, :cssw => 40, :cssh => 50, :x => 10, :y => 70 },
|
30
|
+
{ :cssx => 0, :cssy => 100, :cssw => 40, :cssh => 50, :x => 10, :y => 120 },
|
31
|
+
{ :cssx => 0, :cssy => 150, :cssw => 40, :cssh => 50, :x => 10, :y => 170 },
|
32
|
+
{ :cssx => 0, :cssy => 200, :cssw => 40, :cssh => 50, :x => 10, :y => 220 }
|
33
|
+
]
|
34
|
+
verify_layout(40, 250, expected, images, :layout => :vertical, :hpadding => 10, :vpadding => 20)
|
35
|
+
end
|
36
|
+
|
37
|
+
#--------------------------------------------------------------------------
|
38
|
+
|
39
|
+
def test_margin_vertical_layout_of_regular_images
|
40
|
+
images = get_regular_images
|
41
|
+
expected = [
|
42
|
+
{ :cssx => 10, :cssy => 20, :cssw => 20, :cssh => 10, :x => 10, :y => 20 },
|
43
|
+
{ :cssx => 10, :cssy => 70, :cssw => 20, :cssh => 10, :x => 10, :y => 70 },
|
44
|
+
{ :cssx => 10, :cssy => 120, :cssw => 20, :cssh => 10, :x => 10, :y => 120 },
|
45
|
+
{ :cssx => 10, :cssy => 170, :cssw => 20, :cssh => 10, :x => 10, :y => 170 },
|
46
|
+
{ :cssx => 10, :cssy => 220, :cssw => 20, :cssh => 10, :x => 10, :y => 220 }
|
47
|
+
]
|
48
|
+
verify_layout(40, 250, expected, images, :layout => :vertical, :hmargin => 10, :vmargin => 20)
|
49
|
+
end
|
50
|
+
|
51
|
+
#--------------------------------------------------------------------------
|
52
|
+
|
53
|
+
def test_padded_and_margin_vertical_layout_of_regular_images
|
54
|
+
images = get_regular_images
|
55
|
+
expected = [
|
56
|
+
{ :cssx => 10, :cssy => 20, :cssw => 24, :cssh => 18, :x => 12, :y => 24 },
|
57
|
+
{ :cssx => 10, :cssy => 78, :cssw => 24, :cssh => 18, :x => 12, :y => 82 },
|
58
|
+
{ :cssx => 10, :cssy => 136, :cssw => 24, :cssh => 18, :x => 12, :y => 140 },
|
59
|
+
{ :cssx => 10, :cssy => 194, :cssw => 24, :cssh => 18, :x => 12, :y => 198 },
|
60
|
+
{ :cssx => 10, :cssy => 252, :cssw => 24, :cssh => 18, :x => 12, :y => 256 }
|
61
|
+
]
|
62
|
+
verify_layout(44, 290, expected, images, :layout => :vertical, :hmargin => 10, :vmargin => 20, :hpadding => 2, :vpadding => 4)
|
63
|
+
end
|
64
|
+
|
65
|
+
#--------------------------------------------------------------------------
|
66
|
+
|
67
|
+
def test_fixed_vertical_layout_of_regular_images
|
68
|
+
images = get_regular_images
|
69
|
+
expected = [
|
70
|
+
{ :cssx => 0, :cssy => 0, :cssw => 50, :cssh => 50, :x => 15, :y => 20 },
|
71
|
+
{ :cssx => 0, :cssy => 50, :cssw => 50, :cssh => 50, :x => 15, :y => 70 },
|
72
|
+
{ :cssx => 0, :cssy => 100, :cssw => 50, :cssh => 50, :x => 15, :y => 120 },
|
73
|
+
{ :cssx => 0, :cssy => 150, :cssw => 50, :cssh => 50, :x => 15, :y => 170 },
|
74
|
+
{ :cssx => 0, :cssy => 200, :cssw => 50, :cssh => 50, :x => 15, :y => 220 }
|
75
|
+
]
|
76
|
+
verify_layout(50, 250, expected, images, :layout => :vertical, :width => 50, :height => 50)
|
77
|
+
end
|
78
|
+
|
79
|
+
#==========================================================================
|
80
|
+
# test IRREGULAR images
|
81
|
+
#==========================================================================
|
82
|
+
|
83
|
+
def test_vertical_layout_of_irregular_images
|
84
|
+
images = get_irregular_images
|
85
|
+
expected = [
|
86
|
+
{ :x => 40, :y => 0 },
|
87
|
+
{ :x => 30, :y => 50 },
|
88
|
+
{ :x => 20, :y => 90 },
|
89
|
+
{ :x => 10, :y => 120 },
|
90
|
+
{ :x => 0, :y => 140 }
|
91
|
+
]
|
92
|
+
verify_layout(100, 150, expected, images, :layout => :vertical)
|
93
|
+
end
|
94
|
+
|
95
|
+
#--------------------------------------------------------------------------
|
96
|
+
|
97
|
+
def test_padded_vertical_layout_of_irregular_images
|
98
|
+
images = get_irregular_images
|
99
|
+
expected = [
|
100
|
+
{ :cssx => 40, :cssy => 0, :cssw => 40, :cssh => 90, :x => 50, :y => 20 },
|
101
|
+
{ :cssx => 30, :cssy => 90, :cssw => 60, :cssh => 80, :x => 40, :y => 110 },
|
102
|
+
{ :cssx => 20, :cssy => 170, :cssw => 80, :cssh => 70, :x => 30, :y => 190 },
|
103
|
+
{ :cssx => 10, :cssy => 240, :cssw => 100, :cssh => 60, :x => 20, :y => 260 },
|
104
|
+
{ :cssx => 0, :cssy => 300, :cssw => 120, :cssh => 50, :x => 10, :y => 320 }
|
105
|
+
]
|
106
|
+
verify_layout(120, 350, expected, images, :layout => :vertical, :hpadding => 10, :vpadding => 20)
|
107
|
+
end
|
108
|
+
|
109
|
+
#--------------------------------------------------------------------------
|
110
|
+
|
111
|
+
def test_margin_vertical_layout_of_irregular_images
|
112
|
+
images = get_irregular_images
|
113
|
+
expected = [
|
114
|
+
{ :cssx => 50, :cssy => 20, :cssw => 20, :cssh => 50, :x => 50, :y => 20 },
|
115
|
+
{ :cssx => 40, :cssy => 110, :cssw => 40, :cssh => 40, :x => 40, :y => 110 },
|
116
|
+
{ :cssx => 30, :cssy => 190, :cssw => 60, :cssh => 30, :x => 30, :y => 190 },
|
117
|
+
{ :cssx => 20, :cssy => 260, :cssw => 80, :cssh => 20, :x => 20, :y => 260 },
|
118
|
+
{ :cssx => 10, :cssy => 320, :cssw => 100, :cssh => 10, :x => 10, :y => 320 }
|
119
|
+
]
|
120
|
+
verify_layout(120, 350, expected, images, :layout => :vertical, :hmargin => 10, :vmargin => 20)
|
121
|
+
end
|
122
|
+
|
123
|
+
#--------------------------------------------------------------------------
|
124
|
+
|
125
|
+
def test_padded_and_margin_vertical_layout_of_irregular_images
|
126
|
+
images = get_irregular_images
|
127
|
+
expected = [
|
128
|
+
{ :cssx => 50, :cssy => 20, :cssw => 24, :cssh => 58, :x => 52, :y => 24 },
|
129
|
+
{ :cssx => 40, :cssy => 118, :cssw => 44, :cssh => 48, :x => 42, :y => 122 },
|
130
|
+
{ :cssx => 30, :cssy => 206, :cssw => 64, :cssh => 38, :x => 32, :y => 210 },
|
131
|
+
{ :cssx => 20, :cssy => 284, :cssw => 84, :cssh => 28, :x => 22, :y => 288 },
|
132
|
+
{ :cssx => 10, :cssy => 352, :cssw => 104, :cssh => 18, :x => 12, :y => 356 }
|
133
|
+
]
|
134
|
+
verify_layout(124, 390, expected, images, :layout => :vertical, :hmargin => 10, :vmargin => 20, :hpadding => 2, :vpadding => 4)
|
135
|
+
end
|
136
|
+
|
137
|
+
#--------------------------------------------------------------------------
|
138
|
+
|
139
|
+
def test_fixed_vertical_layout_of_irregular_images
|
140
|
+
images = get_irregular_images
|
141
|
+
expected = [
|
142
|
+
{ :cssx => 0, :cssy => 0, :cssw => 100, :cssh => 100, :x => 40, :y => 25 },
|
143
|
+
{ :cssx => 0, :cssy => 100, :cssw => 100, :cssh => 100, :x => 30, :y => 130 },
|
144
|
+
{ :cssx => 0, :cssy => 200, :cssw => 100, :cssh => 100, :x => 20, :y => 235 },
|
145
|
+
{ :cssx => 0, :cssy => 300, :cssw => 100, :cssh => 100, :x => 10, :y => 340 },
|
146
|
+
{ :cssx => 0, :cssy => 400, :cssw => 100, :cssh => 100, :x => 0, :y => 445 }
|
147
|
+
]
|
148
|
+
verify_layout(100, 500, expected, images, :layout => :vertical, :width => 100, :height => 100)
|
149
|
+
end
|
150
|
+
|
151
|
+
#--------------------------------------------------------------------------
|
152
|
+
|
153
|
+
end # class VerticalTest
|
154
|
+
end # module Layout
|
155
|
+
end # module SpriteFactory
|
156
|
+
|