gosling 2.3.0 → 2.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,19 @@
1
- describe Gosling::ImageLibrary do
2
- before(:all) do
3
- @test_image_path = File.join(File.dirname(__FILE__), "images/key.png")
4
- end
5
-
6
- it "returns a Gosu:Image reference when given a filename" do
7
- expect(Gosling::ImageLibrary.get(@test_image_path)).to be_instance_of(Gosu::Image)
8
- end
9
-
10
- it "raises an argument error if the file does not exist" do
11
- expect { Gosling::ImageLibrary.get("C:/does/not/exist.png") }.to raise_error(ArgumentError)
12
- end
13
-
14
- it "does not create a new Gosu:Image if it already has one cached" do
15
- image_a = Gosling::ImageLibrary.get(@test_image_path)
16
- image_b = Gosling::ImageLibrary.get(@test_image_path)
17
- expect(image_a).to be == image_b
18
- end
19
- end
1
+ describe Gosling::ImageLibrary do
2
+ before(:all) do
3
+ @test_image_path = File.join(File.dirname(__FILE__), "images/key.png")
4
+ end
5
+
6
+ it "returns a Gosu:Image reference when given a filename" do
7
+ expect(Gosling::ImageLibrary.get(@test_image_path)).to be_instance_of(Gosu::Image)
8
+ end
9
+
10
+ it "raises an argument error if the file does not exist" do
11
+ expect { Gosling::ImageLibrary.get("C:/does/not/exist.png") }.to raise_error(ArgumentError)
12
+ end
13
+
14
+ it "does not create a new Gosu:Image if it already has one cached" do
15
+ image_a = Gosling::ImageLibrary.get(@test_image_path)
16
+ image_b = Gosling::ImageLibrary.get(@test_image_path)
17
+ expect(image_a).to be == image_b
18
+ end
19
+ end
@@ -1,25 +1,25 @@
1
- describe MatrixCache do
2
- describe '.get' do
3
- context 'when there are no Mat3 objects available' do
4
- before do
5
- MatrixCache.instance.clear
6
- end
7
-
8
- it 'creates a new Mat3 and returns it' do
9
- new_matrix = Snow::Vec3.new
10
- expect(Snow::Mat3).to receive(:new).and_return(new_matrix)
11
- m = MatrixCache.instance.get
12
- expect(m).to equal(new_matrix)
13
- end
14
- end
15
- end
16
-
17
- describe '.recycle' do
18
- it 'resets the Mat3' do
19
- m = Snow::Mat3[1, 2, 3, 4, 5, 6, 7, 8, 9]
20
- MatrixCache.instance.recycle(m)
21
- [0, 4, 8].each { |i| expect(m[i]).to eq(1) }
22
- [1, 2, 3, 5, 6, 7].each { |i| expect(m[i]).to eq(0) }
23
- end
24
- end
25
- end
1
+ describe MatrixCache do
2
+ describe '.get' do
3
+ context 'when there are no Mat3 objects available' do
4
+ before do
5
+ MatrixCache.instance.clear
6
+ end
7
+
8
+ it 'creates a new Mat3 and returns it' do
9
+ new_matrix = Snow::Vec3.new
10
+ expect(Snow::Mat3).to receive(:new).and_return(new_matrix)
11
+ m = MatrixCache.instance.get
12
+ expect(m).to equal(new_matrix)
13
+ end
14
+ end
15
+ end
16
+
17
+ describe '.recycle' do
18
+ it 'resets the Mat3' do
19
+ m = Snow::Mat3[1, 2, 3, 4, 5, 6, 7, 8, 9]
20
+ MatrixCache.instance.recycle(m)
21
+ [0, 4, 8].each { |i| expect(m[i]).to eq(1) }
22
+ [1, 2, 3, 5, 6, 7].each { |i| expect(m[i]).to eq(0) }
23
+ end
24
+ end
25
+ end
@@ -1,22 +1,22 @@
1
- describe Object do
2
- before(:all) do
3
- @test_object = []
4
- end
5
-
6
- describe '.unfreeze' do
7
- it 'allows the object to be edited after being frozen' do
8
- @test_object.freeze
9
- expect { @test_object << 'a' }.to raise_error(RuntimeError)
10
- @test_object.unfreeze
11
- expect { @test_object << 'a' }.not_to raise_error
12
- end
13
-
14
- it 'works even after multiple freeze/unfreeze cycles' do
15
- 3.times do
16
- @test_object.freeze
17
- @test_object.unfreeze
18
- end
19
- expect { @test_object << 'a' }.not_to raise_error
20
- end
21
- end
22
- end
1
+ describe Object do
2
+ before(:all) do
3
+ @test_object = []
4
+ end
5
+
6
+ describe '.unfreeze' do
7
+ it 'allows the object to be edited after being frozen' do
8
+ @test_object.freeze
9
+ expect { @test_object << 'a' }.to raise_error(RuntimeError)
10
+ @test_object.unfreeze
11
+ expect { @test_object << 'a' }.not_to raise_error
12
+ end
13
+
14
+ it 'works even after multiple freeze/unfreeze cycles' do
15
+ 3.times do
16
+ @test_object.freeze
17
+ @test_object.unfreeze
18
+ end
19
+ expect { @test_object << 'a' }.not_to raise_error
20
+ end
21
+ end
22
+ end
data/spec/polygon_spec.rb CHANGED
@@ -1,285 +1,285 @@
1
- describe Gosling::Polygon do
2
- before(:all) do
3
- @window = Gosu::Window.new(640, 480, false)
4
- @polygon = Gosling::Polygon.new(@window)
5
- end
6
-
7
- describe '#get_vertices' do
8
- it 'returns a list of three or more vertices' do
9
- expect(@polygon.get_vertices).to be_instance_of(Array)
10
- expect(@polygon.get_vertices[0]).to be_instance_of(Snow::Vec3)
11
- expect(@polygon.get_vertices.length).to be >= 3
12
- end
13
- end
14
-
15
- describe '#set_vertices' do
16
- it 'accepts an array of Vectors' do
17
- vertices = [
18
- Snow::Vec3[ 1, 0, 1],
19
- Snow::Vec3[ 0, 1, 1],
20
- Snow::Vec3[-1, 0, 1],
21
- Snow::Vec3[ 0, -1, 1]
22
- ]
23
-
24
- polygon = Gosling::Polygon.new(@window)
25
- expect { polygon.set_vertices(vertices) }.not_to raise_error
26
- expect(polygon.get_vertices.length).to eq(vertices.length)
27
- vertices.each_index do |i|
28
- expect(polygon.get_vertices[i].x).to eq(vertices[i].x)
29
- expect(polygon.get_vertices[i].y).to eq(vertices[i].y)
30
- end
31
-
32
- vertices = [
33
- Snow::Vec2[ 1, 0],
34
- Snow::Vec2[ 0, 1],
35
- Snow::Vec2[-1, 0]
36
- ]
37
-
38
- expect { polygon.set_vertices(vertices) }.not_to raise_error
39
- expect(polygon.get_vertices.length).to eq(vertices.length)
40
- vertices.each_index do |i|
41
- expect(polygon.get_vertices[i].x).to eq(vertices[i].x)
42
- expect(polygon.get_vertices[i].y).to eq(vertices[i].y)
43
- end
44
- end
45
-
46
- it 'accepts an array of arrays of numbers' do
47
- vertices = [
48
- [ 1, 0, 1],
49
- [ 0, 1, 1],
50
- [-1, 0, 1]
51
- ]
52
-
53
- polygon = Gosling::Polygon.new(@window)
54
- expect { polygon.set_vertices(vertices) }.not_to raise_error
55
- expect(polygon.get_vertices.length).to eq(vertices.length)
56
- vertices.each_index do |i|
57
- expect(polygon.get_vertices[i].x).to eq(vertices[i][0])
58
- expect(polygon.get_vertices[i].y).to eq(vertices[i][1])
59
- end
60
-
61
- vertices = [
62
- [ 1, 0],
63
- [ 0, 1],
64
- [-1, 0],
65
- [ 0, -1]
66
- ]
67
-
68
- expect { polygon.set_vertices(vertices) }.not_to raise_error
69
- expect(polygon.get_vertices.length).to eq(vertices.length)
70
- vertices.each_index do |i|
71
- expect(polygon.get_vertices[i].x).to eq(vertices[i][0])
72
- expect(polygon.get_vertices[i].y).to eq(vertices[i][1])
73
- end
74
- end
75
-
76
- it 'raises an error if the parameter is not an array' do
77
- polygon = Gosling::Polygon.new(@window)
78
- expect { polygon.set_vertices("foo") }.to raise_error(ArgumentError)
79
- end
80
-
81
- it 'raises an error if the parameter array does not contains vectors or equivalents' do
82
- vertices = [
83
- ['21', '3'],
84
- ['7', '-3'],
85
- ['4.212', '0.0']
86
- ]
87
- polygon = Gosling::Polygon.new(@window)
88
- expect { polygon.set_vertices(vertices) }.to raise_error(ArgumentError)
89
- end
90
-
91
- it 'raises an error if the parameter array is too short' do
92
- vertices = [
93
- Snow::Vec3[ 1, 0, 1],
94
- Snow::Vec3[ 0, 1, 1]
95
- ]
96
-
97
- polygon = Gosling::Polygon.new(@window)
98
- expect { polygon.set_vertices(vertices) }.to raise_error(ArgumentError)
99
- end
100
-
101
- it 'raises an error if any vertices in the parameter array are not at least length 2' do
102
- vertices = [
103
- Snow::Vec3[ 1, 0, 1],
104
- Snow::Vec3[ 0, 1, 0],
105
- Snow::Vec2[-1, 0],
106
- [0],
107
- ]
108
-
109
- polygon = Gosling::Polygon.new(@window)
110
- expect { polygon.set_vertices(vertices) }.to raise_error(ArgumentError)
111
- end
112
- end
113
-
114
- describe '#set_vertices_rect' do
115
- it 'accepts two positive integers, width and height' do
116
- polygon = Gosling::Polygon.new(@window)
117
-
118
- expect { polygon.set_vertices_rect(1, 1) }.not_to raise_error
119
- expect { polygon.set_vertices_rect(2, 3) }.not_to raise_error
120
- expect { polygon.set_vertices_rect(5, 8) }.not_to raise_error
121
- expect { polygon.set_vertices_rect(100000, 100000) }.not_to raise_error
122
-
123
- expect { polygon.set_vertices_rect('two', 2) }.to raise_error(ArgumentError)
124
- expect { polygon.set_vertices_rect(3, :three) }.to raise_error(ArgumentError)
125
- expect { polygon.set_vertices_rect(-1, 1) }.to raise_error(ArgumentError)
126
- expect { polygon.set_vertices_rect(1, 0) }.to raise_error(ArgumentError)
127
- end
128
-
129
- it 'sets the vertices to form a square with the given width and height' do
130
- polygon = Gosling::Polygon.new(@window)
131
- polygon.set_vertices_rect(13, 21)
132
- expect(polygon.get_vertices).to match_array([
133
- Snow::Vec3[0, 0, 0],
134
- Snow::Vec3[13, 0, 0],
135
- Snow::Vec3[13, 21, 0],
136
- Snow::Vec3[0, 21, 0]
137
- ])
138
- end
139
- end
140
-
141
- describe '#get_global_vertices' do
142
- before(:all) do
143
- @global_polygon = Gosling::Polygon.new(@window)
144
- @global_polygon.set_vertices([
145
- Snow::Vec3[1, 1, 0],
146
- Snow::Vec3[0, -1, 0],
147
- Snow::Vec3[-1, -1, 0],
148
- Snow::Vec3[-1, 2, 0]
149
- ])
150
- end
151
-
152
- it 'returns a list of three or more vertices' do
153
- result = @global_polygon.get_global_vertices
154
- expect(result).to be_instance_of(Array)
155
- expect(result[0]).to be_instance_of(Snow::Vec3)
156
- expect(result.length).to be >= 3
157
- end
158
-
159
- it 'respects centering' do
160
- @global_polygon.x = 0
161
- @global_polygon.y = 0
162
- @global_polygon.center_x = 10
163
- @global_polygon.center_y = 2
164
- @global_polygon.scale_x = 1
165
- @global_polygon.scale_y = 1
166
- @global_polygon.rotation = 0
167
-
168
- vertices = @global_polygon.get_global_vertices
169
- expect(vertices).to be == [
170
- Snow::Vec3[-9, -1, 0],
171
- Snow::Vec3[-10, -3, 0],
172
- Snow::Vec3[-11, -3, 0],
173
- Snow::Vec3[-11, 0, 0]
174
- ]
175
- end
176
-
177
- it 'respects scaling' do
178
- @global_polygon.x = 0
179
- @global_polygon.y = 0
180
- @global_polygon.center_x = 0
181
- @global_polygon.center_y = 0
182
- @global_polygon.scale_x = 3
183
- @global_polygon.scale_y = 2
184
- @global_polygon.rotation = 0
185
-
186
- vertices = @global_polygon.get_global_vertices
187
- expect(vertices).to be == [
188
- Snow::Vec3[3, 2, 0],
189
- Snow::Vec3[0, -2, 0],
190
- Snow::Vec3[-3, -2, 0],
191
- Snow::Vec3[-3, 4, 0]
192
- ]
193
- end
194
-
195
- it 'respects rotation' do
196
- @global_polygon.x = 0
197
- @global_polygon.y = 0
198
- @global_polygon.center_x = 0
199
- @global_polygon.center_y = 0
200
- @global_polygon.scale_x = 1
201
- @global_polygon.scale_y = 1
202
- @global_polygon.rotation = Math::PI / 2
203
-
204
- vertices = @global_polygon.get_global_vertices
205
- expect(vertices).to be == [
206
- Snow::Vec3[1, -1, 0],
207
- Snow::Vec3[-1, 0, 0],
208
- Snow::Vec3[-1, 1, 0],
209
- Snow::Vec3[2, 1, 0]
210
- ]
211
- end
212
-
213
- it 'respects translation' do
214
- @global_polygon.x = -50
215
- @global_polygon.y = 10
216
- @global_polygon.center_x = 0
217
- @global_polygon.center_y = 0
218
- @global_polygon.scale_x = 1
219
- @global_polygon.scale_y = 1
220
- @global_polygon.rotation = 0
221
-
222
- vertices = @global_polygon.get_global_vertices
223
- expect(vertices).to be == [
224
- Snow::Vec3[-49, 11, 0],
225
- Snow::Vec3[-50, 9, 0],
226
- Snow::Vec3[-51, 9, 0],
227
- Snow::Vec3[-51, 12, 0]
228
- ]
229
- end
230
-
231
- context 'with a long ancestry' do
232
- before do
233
- @global_polygon.x = 0
234
- @global_polygon.y = 0
235
- @global_polygon.center_x = 0
236
- @global_polygon.center_y = 0
237
- @global_polygon.scale_x = 1
238
- @global_polygon.scale_y = 1
239
- @global_polygon.rotation = 0
240
-
241
- centered_view = Gosling::Actor.new(@window)
242
- centered_view.center_x = 10
243
- centered_view.center_y = 2
244
-
245
- scaled_view = Gosling::Actor.new(@window)
246
- scaled_view.scale_x = 3
247
- scaled_view.scale_y = 2
248
-
249
- rotated_view = Gosling::Actor.new(@window)
250
- rotated_view.rotation = Math::PI / 2
251
-
252
- translated_view = Gosling::Actor.new(@window)
253
- translated_view.x = -50
254
- translated_view.y = 10
255
-
256
- centered_view.add_child(scaled_view)
257
- scaled_view.add_child(rotated_view)
258
- rotated_view.add_child(translated_view)
259
- translated_view.add_child(@global_polygon)
260
-
261
- @ancestry = [
262
- centered_view,
263
- scaled_view,
264
- rotated_view,
265
- translated_view,
266
- @global_polygon
267
- ]
268
- end
269
-
270
- it 'respects all ancestors' do
271
- vertices = @global_polygon.get_global_vertices
272
- expect(vertices).to be == [
273
- Snow::Vec3[(1 + 10) * 3 - 10, (1 - 50) * -2 - 2, 0],
274
- Snow::Vec3[(-1 + 10) * 3 - 10, (0 - 50) * -2 - 2, 0],
275
- Snow::Vec3[(-1 + 10) * 3 - 10, (-1 - 50) * -2 - 2, 0],
276
- Snow::Vec3[(2 + 10) * 3 - 10, (-1 - 50) * -2 - 2, 0]
277
- ]
278
- end
279
-
280
- after do
281
- @ancestry.each { |actor| actor.parent.remove_child(actor) if actor.parent }
282
- end
283
- end
284
- end
1
+ describe Gosling::Polygon do
2
+ before(:all) do
3
+ @window = Gosu::Window.new(640, 480, false)
4
+ @polygon = Gosling::Polygon.new(@window)
5
+ end
6
+
7
+ describe '#get_vertices' do
8
+ it 'returns a list of three or more vertices' do
9
+ expect(@polygon.get_vertices).to be_instance_of(Array)
10
+ expect(@polygon.get_vertices[0]).to be_instance_of(Snow::Vec3)
11
+ expect(@polygon.get_vertices.length).to be >= 3
12
+ end
13
+ end
14
+
15
+ describe '#set_vertices' do
16
+ it 'accepts an array of Vectors' do
17
+ vertices = [
18
+ Snow::Vec3[ 1, 0, 1],
19
+ Snow::Vec3[ 0, 1, 1],
20
+ Snow::Vec3[-1, 0, 1],
21
+ Snow::Vec3[ 0, -1, 1]
22
+ ]
23
+
24
+ polygon = Gosling::Polygon.new(@window)
25
+ expect { polygon.set_vertices(vertices) }.not_to raise_error
26
+ expect(polygon.get_vertices.length).to eq(vertices.length)
27
+ vertices.each_index do |i|
28
+ expect(polygon.get_vertices[i].x).to eq(vertices[i].x)
29
+ expect(polygon.get_vertices[i].y).to eq(vertices[i].y)
30
+ end
31
+
32
+ vertices = [
33
+ Snow::Vec2[ 1, 0],
34
+ Snow::Vec2[ 0, 1],
35
+ Snow::Vec2[-1, 0]
36
+ ]
37
+
38
+ expect { polygon.set_vertices(vertices) }.not_to raise_error
39
+ expect(polygon.get_vertices.length).to eq(vertices.length)
40
+ vertices.each_index do |i|
41
+ expect(polygon.get_vertices[i].x).to eq(vertices[i].x)
42
+ expect(polygon.get_vertices[i].y).to eq(vertices[i].y)
43
+ end
44
+ end
45
+
46
+ it 'accepts an array of arrays of numbers' do
47
+ vertices = [
48
+ [ 1, 0, 1],
49
+ [ 0, 1, 1],
50
+ [-1, 0, 1]
51
+ ]
52
+
53
+ polygon = Gosling::Polygon.new(@window)
54
+ expect { polygon.set_vertices(vertices) }.not_to raise_error
55
+ expect(polygon.get_vertices.length).to eq(vertices.length)
56
+ vertices.each_index do |i|
57
+ expect(polygon.get_vertices[i].x).to eq(vertices[i][0])
58
+ expect(polygon.get_vertices[i].y).to eq(vertices[i][1])
59
+ end
60
+
61
+ vertices = [
62
+ [ 1, 0],
63
+ [ 0, 1],
64
+ [-1, 0],
65
+ [ 0, -1]
66
+ ]
67
+
68
+ expect { polygon.set_vertices(vertices) }.not_to raise_error
69
+ expect(polygon.get_vertices.length).to eq(vertices.length)
70
+ vertices.each_index do |i|
71
+ expect(polygon.get_vertices[i].x).to eq(vertices[i][0])
72
+ expect(polygon.get_vertices[i].y).to eq(vertices[i][1])
73
+ end
74
+ end
75
+
76
+ it 'raises an error if the parameter is not an array' do
77
+ polygon = Gosling::Polygon.new(@window)
78
+ expect { polygon.set_vertices("foo") }.to raise_error(ArgumentError)
79
+ end
80
+
81
+ it 'raises an error if the parameter array does not contains vectors or equivalents' do
82
+ vertices = [
83
+ ['21', '3'],
84
+ ['7', '-3'],
85
+ ['4.212', '0.0']
86
+ ]
87
+ polygon = Gosling::Polygon.new(@window)
88
+ expect { polygon.set_vertices(vertices) }.to raise_error(ArgumentError)
89
+ end
90
+
91
+ it 'raises an error if the parameter array is too short' do
92
+ vertices = [
93
+ Snow::Vec3[ 1, 0, 1],
94
+ Snow::Vec3[ 0, 1, 1]
95
+ ]
96
+
97
+ polygon = Gosling::Polygon.new(@window)
98
+ expect { polygon.set_vertices(vertices) }.to raise_error(ArgumentError)
99
+ end
100
+
101
+ it 'raises an error if any vertices in the parameter array are not at least length 2' do
102
+ vertices = [
103
+ Snow::Vec3[ 1, 0, 1],
104
+ Snow::Vec3[ 0, 1, 0],
105
+ Snow::Vec2[-1, 0],
106
+ [0],
107
+ ]
108
+
109
+ polygon = Gosling::Polygon.new(@window)
110
+ expect { polygon.set_vertices(vertices) }.to raise_error(ArgumentError)
111
+ end
112
+ end
113
+
114
+ describe '#set_vertices_rect' do
115
+ it 'accepts two positive integers, width and height' do
116
+ polygon = Gosling::Polygon.new(@window)
117
+
118
+ expect { polygon.set_vertices_rect(1, 1) }.not_to raise_error
119
+ expect { polygon.set_vertices_rect(2, 3) }.not_to raise_error
120
+ expect { polygon.set_vertices_rect(5, 8) }.not_to raise_error
121
+ expect { polygon.set_vertices_rect(100000, 100000) }.not_to raise_error
122
+
123
+ expect { polygon.set_vertices_rect('two', 2) }.to raise_error(ArgumentError)
124
+ expect { polygon.set_vertices_rect(3, :three) }.to raise_error(ArgumentError)
125
+ expect { polygon.set_vertices_rect(-1, 1) }.to raise_error(ArgumentError)
126
+ expect { polygon.set_vertices_rect(1, 0) }.to raise_error(ArgumentError)
127
+ end
128
+
129
+ it 'sets the vertices to form a square with the given width and height' do
130
+ polygon = Gosling::Polygon.new(@window)
131
+ polygon.set_vertices_rect(13, 21)
132
+ expect(polygon.get_vertices).to match_array([
133
+ Snow::Vec3[0, 0, 0],
134
+ Snow::Vec3[13, 0, 0],
135
+ Snow::Vec3[13, 21, 0],
136
+ Snow::Vec3[0, 21, 0]
137
+ ])
138
+ end
139
+ end
140
+
141
+ describe '#get_global_vertices' do
142
+ before(:all) do
143
+ @global_polygon = Gosling::Polygon.new(@window)
144
+ @global_polygon.set_vertices([
145
+ Snow::Vec3[1, 1, 0],
146
+ Snow::Vec3[0, -1, 0],
147
+ Snow::Vec3[-1, -1, 0],
148
+ Snow::Vec3[-1, 2, 0]
149
+ ])
150
+ end
151
+
152
+ it 'returns a list of three or more vertices' do
153
+ result = @global_polygon.get_global_vertices
154
+ expect(result).to be_instance_of(Array)
155
+ expect(result[0]).to be_instance_of(Snow::Vec3)
156
+ expect(result.length).to be >= 3
157
+ end
158
+
159
+ it 'respects centering' do
160
+ @global_polygon.x = 0
161
+ @global_polygon.y = 0
162
+ @global_polygon.center_x = 10
163
+ @global_polygon.center_y = 2
164
+ @global_polygon.scale_x = 1
165
+ @global_polygon.scale_y = 1
166
+ @global_polygon.rotation = 0
167
+
168
+ vertices = @global_polygon.get_global_vertices
169
+ expect(vertices).to be == [
170
+ Snow::Vec3[-9, -1, 0],
171
+ Snow::Vec3[-10, -3, 0],
172
+ Snow::Vec3[-11, -3, 0],
173
+ Snow::Vec3[-11, 0, 0]
174
+ ]
175
+ end
176
+
177
+ it 'respects scaling' do
178
+ @global_polygon.x = 0
179
+ @global_polygon.y = 0
180
+ @global_polygon.center_x = 0
181
+ @global_polygon.center_y = 0
182
+ @global_polygon.scale_x = 3
183
+ @global_polygon.scale_y = 2
184
+ @global_polygon.rotation = 0
185
+
186
+ vertices = @global_polygon.get_global_vertices
187
+ expect(vertices).to be == [
188
+ Snow::Vec3[3, 2, 0],
189
+ Snow::Vec3[0, -2, 0],
190
+ Snow::Vec3[-3, -2, 0],
191
+ Snow::Vec3[-3, 4, 0]
192
+ ]
193
+ end
194
+
195
+ it 'respects rotation' do
196
+ @global_polygon.x = 0
197
+ @global_polygon.y = 0
198
+ @global_polygon.center_x = 0
199
+ @global_polygon.center_y = 0
200
+ @global_polygon.scale_x = 1
201
+ @global_polygon.scale_y = 1
202
+ @global_polygon.rotation = Math::PI / 2
203
+
204
+ vertices = @global_polygon.get_global_vertices
205
+ expect(vertices).to be == [
206
+ Snow::Vec3[1, -1, 0],
207
+ Snow::Vec3[-1, 0, 0],
208
+ Snow::Vec3[-1, 1, 0],
209
+ Snow::Vec3[2, 1, 0]
210
+ ]
211
+ end
212
+
213
+ it 'respects translation' do
214
+ @global_polygon.x = -50
215
+ @global_polygon.y = 10
216
+ @global_polygon.center_x = 0
217
+ @global_polygon.center_y = 0
218
+ @global_polygon.scale_x = 1
219
+ @global_polygon.scale_y = 1
220
+ @global_polygon.rotation = 0
221
+
222
+ vertices = @global_polygon.get_global_vertices
223
+ expect(vertices).to be == [
224
+ Snow::Vec3[-49, 11, 0],
225
+ Snow::Vec3[-50, 9, 0],
226
+ Snow::Vec3[-51, 9, 0],
227
+ Snow::Vec3[-51, 12, 0]
228
+ ]
229
+ end
230
+
231
+ context 'with a long ancestry' do
232
+ before do
233
+ @global_polygon.x = 0
234
+ @global_polygon.y = 0
235
+ @global_polygon.center_x = 0
236
+ @global_polygon.center_y = 0
237
+ @global_polygon.scale_x = 1
238
+ @global_polygon.scale_y = 1
239
+ @global_polygon.rotation = 0
240
+
241
+ centered_view = Gosling::Actor.new(@window)
242
+ centered_view.center_x = 10
243
+ centered_view.center_y = 2
244
+
245
+ scaled_view = Gosling::Actor.new(@window)
246
+ scaled_view.scale_x = 3
247
+ scaled_view.scale_y = 2
248
+
249
+ rotated_view = Gosling::Actor.new(@window)
250
+ rotated_view.rotation = Math::PI / 2
251
+
252
+ translated_view = Gosling::Actor.new(@window)
253
+ translated_view.x = -50
254
+ translated_view.y = 10
255
+
256
+ centered_view.add_child(scaled_view)
257
+ scaled_view.add_child(rotated_view)
258
+ rotated_view.add_child(translated_view)
259
+ translated_view.add_child(@global_polygon)
260
+
261
+ @ancestry = [
262
+ centered_view,
263
+ scaled_view,
264
+ rotated_view,
265
+ translated_view,
266
+ @global_polygon
267
+ ]
268
+ end
269
+
270
+ it 'respects all ancestors' do
271
+ vertices = @global_polygon.get_global_vertices
272
+ expect(vertices).to be == [
273
+ Snow::Vec3[(1 + 10) * 3 - 10, (1 - 50) * -2 - 2, 0],
274
+ Snow::Vec3[(-1 + 10) * 3 - 10, (0 - 50) * -2 - 2, 0],
275
+ Snow::Vec3[(-1 + 10) * 3 - 10, (-1 - 50) * -2 - 2, 0],
276
+ Snow::Vec3[(2 + 10) * 3 - 10, (-1 - 50) * -2 - 2, 0]
277
+ ]
278
+ end
279
+
280
+ after do
281
+ @ancestry.each { |actor| actor.parent.remove_child(actor) if actor.parent }
282
+ end
283
+ end
284
+ end
285
285
  end