rubysketch 0.3.22 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/{release.yml → release-gem.yml} +21 -21
  3. data/.github/workflows/tag.yml +35 -0
  4. data/.github/workflows/test.yml +8 -9
  5. data/.github/workflows/utils.rb +55 -0
  6. data/ChangeLog.md +7 -164
  7. data/LICENSE +1 -1
  8. data/README.md +1 -1
  9. data/Rakefile +10 -34
  10. data/RubySketch.podspec +4 -3
  11. data/VERSION +1 -1
  12. data/examples/hello.rb +6 -6
  13. data/lib/rubysketch/all.rb +9 -0
  14. data/lib/rubysketch/context.rb +47 -0
  15. data/lib/rubysketch/{module.rb → extension.rb} +3 -3
  16. data/lib/rubysketch/graphics_context.rb +37 -0
  17. data/lib/rubysketch/helper.rb +5 -0
  18. data/lib/rubysketch/sprite.rb +101 -0
  19. data/lib/rubysketch.rb +30 -12
  20. data/rubysketch.gemspec +15 -8
  21. data/src/{RubySketch.h → RubyProcessing.h} +0 -4
  22. data/src/RubyProcessing.mm +25 -0
  23. data/test/helper.rb +3 -10
  24. data/test/test_sprite.rb +23 -0
  25. metadata +119 -35
  26. data/examples/breakout.rb +0 -212
  27. data/examples/camera.rb +0 -14
  28. data/examples/clock.rb +0 -57
  29. data/examples/delay_camera.rb +0 -33
  30. data/examples/glsl.rb +0 -14
  31. data/examples/image.rb +0 -13
  32. data/examples/shapes.rb +0 -121
  33. data/lib/rubysketch/app.rb +0 -13
  34. data/lib/rubysketch/glsl.rb +0 -44
  35. data/lib/rubysketch/processing.rb +0 -3191
  36. data/lib/rubysketch/window.rb +0 -232
  37. data/lib/rubysketch-glsl.rb +0 -12
  38. data/lib/rubysketch-processing.rb +0 -25
  39. data/src/RubySketch.mm +0 -55
  40. data/test/processing/helper.rb +0 -11
  41. data/test/processing/test_graphics.rb +0 -21
  42. data/test/processing/test_shader.rb +0 -47
  43. data/test/processing/test_utility.rb +0 -41
  44. data/test/processing/test_vector.rb +0 -394
@@ -1,394 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
-
4
- require_relative 'helper'
5
-
6
-
7
- class TestProcessingVector < Test::Unit::TestCase
8
-
9
- P = RubySketch::Processing
10
- V = P::Vector
11
- M = Math
12
- PI = M::PI
13
-
14
- def vec(*args, **kwargs)
15
- V.new(*args, **kwargs)
16
- end
17
-
18
- def point(*args, **kwargs)
19
- Rays::Point.new(*args, **kwargs)
20
- end
21
-
22
- def test_initialize()
23
- assert_equal_vector vec(0, 0, 0), vec()
24
- assert_equal_vector vec(1, 0, 0), vec(1)
25
- assert_equal_vector vec(1, 2, 0), vec(1, 2)
26
- assert_equal_vector vec(1, 2, 3), vec(1, 2, 3)
27
-
28
- assert_equal_vector vec(0, 0, 0), vec([])
29
- assert_equal_vector vec(1, 0, 0), vec([1])
30
- assert_equal_vector vec(1, 2, 0), vec([1, 2])
31
- assert_equal_vector vec(1, 2, 3), vec([1, 2, 3])
32
-
33
- assert_equal_vector vec(1, 2, 3), vec(vec 1, 2, 3)
34
- assert_equal_vector vec(1, 2, 3), vec(point 1, 2, 3)
35
- end
36
-
37
- def test_set()
38
- v0 = vec 9, 9, 9
39
-
40
- v = v0.dup; v.set; assert_equal_vector vec(0, 0, 0), v
41
- v = v0.dup; v.set 1; assert_equal_vector vec(1, 0, 0), v
42
- v = v0.dup; v.set 1, 2; assert_equal_vector vec(1, 2, 0), v
43
- v = v0.dup; v.set 1, 2, 3; assert_equal_vector vec(1, 2, 3), v
44
-
45
- v = v0.dup; v.set []; assert_equal_vector vec(0, 0, 0), v
46
- v = v0.dup; v.set [1]; assert_equal_vector vec(1, 0, 0), v
47
- v = v0.dup; v.set [1, 2]; assert_equal_vector vec(1, 2, 0), v
48
- v = v0.dup; v.set [1, 2, 3]; assert_equal_vector vec(1, 2, 3), v
49
-
50
- v = v0.dup; v.set vec(1, 2, 3); assert_equal_vector vec(1, 2, 3), v
51
- v = v0.dup; v.set point(1, 2, 3); assert_equal_vector vec(1, 2, 3), v
52
- end
53
-
54
- def test_dup()
55
- v1 = vec 1, 2, 3
56
- assert_equal_vector vec(1, 2, 3), v1
57
-
58
- v2 = v1.dup
59
- assert_equal_vector vec(1, 2, 3), v1
60
- assert_equal_vector vec(1, 2, 3), v2
61
-
62
- v1.set 7, 8, 9
63
- assert_equal_vector vec(7, 8, 9), v1
64
- assert_equal_vector vec(1, 2, 3), v2
65
- end
66
-
67
- def test_copy()
68
- v1 = vec 1, 2, 3
69
- assert_equal_vector vec(1, 2, 3), v1
70
-
71
- v2 = v1.copy
72
- assert_equal_vector vec(1, 2, 3), v1
73
- assert_equal_vector vec(1, 2, 3), v2
74
-
75
- v1.set 7, 8, 9
76
- assert_equal_vector vec(7, 8, 9), v1
77
- assert_equal_vector vec(1, 2, 3), v2
78
- end
79
-
80
- def test_xyz()
81
- v = vec 1, 2, 3
82
- assert_equal_vector vec(1, 2, 3), v
83
- assert_equal [1, 2, 3], [v.x, v.y, v.z]
84
-
85
- v.x = 7
86
- assert_equal_vector vec(7, 2, 3), v
87
-
88
- v.y = 8
89
- assert_equal_vector vec(7, 8, 3), v
90
-
91
- v.z = 9
92
- assert_equal_vector vec(7, 8, 9), v
93
- end
94
-
95
- def test_array()
96
- assert_equal [1, 2, 3], vec(1, 2, 3).array
97
- end
98
-
99
- def test_add()
100
- v = vec 1, 2, 3
101
- v.add 4, 5, 6
102
- assert_equal_vector vec(5, 7, 9), v
103
-
104
- assert_equal_vector vec(1, 2, 3), vec(1, 2, 3).add()
105
- assert_equal_vector vec(5, 2, 3), vec(1, 2, 3).add(4)
106
- assert_equal_vector vec(5, 7, 3), vec(1, 2, 3).add(4, 5)
107
- assert_equal_vector vec(5, 7, 9), vec(1, 2, 3).add(4, 5, 6)
108
-
109
- assert_equal_vector vec(1, 2, 3), vec(1, 2, 3).add([])
110
- assert_equal_vector vec(5, 2, 3), vec(1, 2, 3).add([4])
111
- assert_equal_vector vec(5, 7, 3), vec(1, 2, 3).add([4, 5])
112
- assert_equal_vector vec(5, 7, 9), vec(1, 2, 3).add([4, 5, 6])
113
-
114
- assert_equal_vector vec(5, 7, 9), vec(1, 2, 3).add( vec(4, 5, 6))
115
- assert_equal_vector vec(5, 7, 9), vec(1, 2, 3).add(point(4, 5, 6))
116
- end
117
-
118
- def test_sub()
119
- v = vec 9, 8, 7
120
- v.sub 1, 2, 3
121
- assert_equal_vector vec(8, 6, 4), v
122
-
123
- assert_equal_vector vec(9, 8, 7), vec(9, 8, 7).sub()
124
- assert_equal_vector vec(8, 8, 7), vec(9, 8, 7).sub(1)
125
- assert_equal_vector vec(8, 6, 7), vec(9, 8, 7).sub(1, 2)
126
- assert_equal_vector vec(8, 6, 4), vec(9, 8, 7).sub(1, 2, 3)
127
-
128
- assert_equal_vector vec(9, 8, 7), vec(9, 8, 7).sub([])
129
- assert_equal_vector vec(8, 8, 7), vec(9, 8, 7).sub([1])
130
- assert_equal_vector vec(8, 6, 7), vec(9, 8, 7).sub([1, 2])
131
- assert_equal_vector vec(8, 6, 4), vec(9, 8, 7).sub([1, 2, 3])
132
-
133
- assert_equal_vector vec(8, 6, 4), vec(9, 8, 7).sub( vec(1, 2, 3))
134
- assert_equal_vector vec(8, 6, 4), vec(9, 8, 7).sub(point(1, 2, 3))
135
- end
136
-
137
- def test_mult()
138
- v = vec 1, 2, 3
139
- v.mult 2
140
- assert_equal_vector vec(2, 4, 6), v
141
- end
142
-
143
- def test_div()
144
- v = vec 2, 4, 6
145
- v.div 2
146
- assert_equal_vector vec(1, 2, 3), v
147
- end
148
-
149
- def test_op_add()
150
- v1 = vec 1, 2, 3
151
- v2 = vec 4, 5, 6
152
- assert_equal_vector vec(5, 7, 9), v1 + v2
153
- assert_equal_vector vec(1, 2, 3), v1
154
- assert_equal_vector vec(4, 5, 6), v2
155
-
156
- assert_equal_vector vec(5, 2, 3), vec(1, 2, 3) + 4
157
-
158
- assert_equal_vector vec(1, 2, 3), vec(1, 2, 3) + []
159
- assert_equal_vector vec(5, 2, 3), vec(1, 2, 3) + [4]
160
- assert_equal_vector vec(5, 7, 3), vec(1, 2, 3) + [4, 5]
161
- assert_equal_vector vec(5, 7, 9), vec(1, 2, 3) + [4, 5, 6]
162
-
163
- assert_equal_vector vec(5, 7, 9), vec(1, 2, 3) + vec(4, 5, 6)
164
- assert_equal_vector vec(5, 7, 9), vec(1, 2, 3) + point(4, 5, 6)
165
- end
166
-
167
- def test_op_sub()
168
- v1 = vec 9, 8, 7
169
- v2 = vec 1, 2, 3
170
- assert_equal_vector vec(8, 6, 4), v1 - v2
171
- assert_equal_vector vec(9, 8, 7), v1
172
- assert_equal_vector vec(1, 2, 3), v2
173
-
174
- assert_equal_vector vec(8, 8, 7), vec(9, 8, 7) - 1
175
-
176
- assert_equal_vector vec(9, 8, 7), vec(9, 8, 7) - []
177
- assert_equal_vector vec(8, 8, 7), vec(9, 8, 7) - [1]
178
- assert_equal_vector vec(8, 6, 7), vec(9, 8, 7) - [1, 2]
179
- assert_equal_vector vec(8, 6, 4), vec(9, 8, 7) - [1, 2, 3]
180
-
181
- assert_equal_vector vec(8, 6, 4), vec(9, 8, 7) - vec(1, 2, 3)
182
- assert_equal_vector vec(8, 6, 4), vec(9, 8, 7) - point(1, 2, 3)
183
- end
184
-
185
- def test_op_mult()
186
- v = vec 1, 2, 3
187
- assert_equal_vector vec(2, 4, 6), v * 2
188
- assert_equal_vector vec(1, 2, 3), v
189
- end
190
-
191
- def test_op_div()
192
- v = vec 2, 4, 6
193
- assert_equal_vector vec(1, 2, 3), v / 2
194
- assert_equal_vector vec(2, 4, 6), v
195
- end
196
-
197
- def test_fun_add()
198
- v1 = vec 1, 2, 3
199
- v2 = vec 4, 5, 6
200
- result = vec
201
- assert_equal_vector vec(5, 7, 9), V.add(v1, v2, result)
202
- assert_equal_vector vec(1, 2, 3), v1
203
- assert_equal_vector vec(4, 5, 6), v2
204
- assert_equal_vector vec(5, 7, 9), result
205
- end
206
-
207
- def test_fun_sub()
208
- v1 = vec 9, 8, 7
209
- v2 = vec 1, 2, 3
210
- result = vec
211
- assert_equal_vector vec(8, 6, 4), V.sub(v1, v2, result)
212
- assert_equal_vector vec(9, 8, 7), v1
213
- assert_equal_vector vec(1, 2, 3), v2
214
- assert_equal_vector vec(8, 6, 4), result
215
- end
216
-
217
- def test_fun_mult()
218
- v1 = vec 1, 2, 3
219
- result = vec
220
- assert_equal_vector vec(2, 4, 6), V.mult(v1, 2, result)
221
- assert_equal_vector vec(1, 2, 3), v1
222
- assert_equal_vector vec(2, 4, 6), result
223
- end
224
-
225
- def test_fun_div()
226
- v1 = vec 2, 4, 6
227
- result = vec
228
- assert_equal_vector vec(1, 2, 3), V.div(v1, 2, result)
229
- assert_equal_vector vec(2, 4, 6), v1
230
- assert_equal_vector vec(1, 2, 3), result
231
- end
232
-
233
- def test_mag()
234
- assert_in_delta M.sqrt(5), vec(1, 2) .mag, 0.000001
235
- assert_in_delta M.sqrt(14), vec(1, 2, 3).mag, 0.000001
236
- end
237
-
238
- def test_magSq()
239
- assert_equal 5, vec(1, 2) .magSq
240
- assert_equal 14, vec(1, 2, 3).magSq
241
- end
242
-
243
- def test_setMag()
244
- v = vec 3, 4, 0
245
- assert_equal_vector vec(6, 8, 0), v.setMag(10)
246
- assert_equal_vector vec(6, 8, 0), v
247
-
248
- v = vec 3, 4, 0
249
- result = vec
250
- assert_equal_vector vec(6, 8, 0), v.setMag(result, 10)
251
- assert_equal_vector vec(3, 4, 0), v
252
- assert_equal_vector vec(6, 8, 0), result
253
- end
254
-
255
- def test_normalize()
256
- v = vec 1, 2, 3
257
- normal = v / v.mag
258
- assert_equal_vector normal, v.normalize
259
- assert_equal_vector normal, v
260
-
261
- v = vec 1, 2, 3
262
- result = vec
263
- assert_equal_vector normal, v.normalize(result)
264
- assert_equal_vector vec(1, 2, 3), v
265
- assert_equal_vector normal, result
266
- end
267
-
268
- def test_limit()
269
- v = vec 1, 2, 3
270
- assert_in_delta 1, v.limit(1).mag, 0.000001
271
- assert_in_delta 1, v .mag, 0.000001
272
-
273
- assert_in_delta 1, vec(1, 2, 3).limit(1).mag, 0.000001
274
- assert_in_delta 2, vec(1, 2, 3).limit(2).mag, 0.000001
275
- assert_in_delta 3, vec(1, 2, 3).limit(3).mag, 0.000001
276
- assert_in_delta vec(1, 2, 3).mag, vec(1, 2, 3).limit(4).mag, 0.000001
277
- end
278
-
279
- def test_dist()
280
- v1 = vec 1, 2, 3
281
- v2 = vec 4, 5, 6
282
-
283
- assert_in_delta M.sqrt((4-1)**2 + (5-2)**2 + (6-3)**2), v1.dist(v2), 0.000001
284
- assert_equal_vector vec(1, 2, 3), v1
285
- assert_equal_vector vec(4, 5, 6), v2
286
-
287
- assert_in_delta M.sqrt((4-1)**2 + (5-2)**2 + (6-3)**2), V.dist(v1, v2), 0.000001
288
- assert_equal_vector vec(1, 2, 3), v1
289
- assert_equal_vector vec(4, 5, 6), v2
290
- end
291
-
292
- def test_dot()
293
- v1 = vec 1, 2, 3
294
- v2 = vec 4, 5, 6
295
-
296
- assert_equal 1*4 + 2*5 + 3*6, v1.dot(4, 5, 6)
297
- assert_equal_vector vec(1, 2, 3), v1
298
-
299
- assert_equal 1*4 + 2*5 + 3*6, v1.dot(v2)
300
- assert_equal_vector vec(1, 2, 3), v1
301
- assert_equal_vector vec(4, 5, 6), v2
302
-
303
- assert_equal 1*4 + 2*5 + 3*6, V.dot(v1, v2)
304
- assert_equal_vector vec(1, 2, 3), v1
305
- assert_equal_vector vec(4, 5, 6), v2
306
- end
307
-
308
- def test_cross()
309
- v1 = vec 1, 0, 0
310
- v2 = vec 0, 1, 0
311
-
312
- assert_equal_vector vec(0, 0, 1), v1.cross(0, 1, 0)
313
- assert_equal_vector vec(1, 0, 0), v1
314
-
315
- result = vec 1, 2, 3
316
- assert_equal_vector vec(0, 0, 1), v1.cross(v2, result)
317
- assert_equal_vector vec(1, 0, 0), v1
318
- assert_equal_vector vec(0, 1, 0), v2
319
- assert_equal_vector vec(0, 0, 1), result
320
-
321
- result = vec 1, 2, 3
322
- assert_equal_vector vec(0, 0, 1), V.cross(v1, v2, result)
323
- assert_equal_vector vec(1, 0, 0), v1
324
- assert_equal_vector vec(0, 1, 0), v2
325
- assert_equal_vector vec(0, 0, 1), result
326
- end
327
-
328
- def test_rotate()
329
- angle = PI * 2 * 0.1
330
- context = Object.new.tap {|o| def o.toAngle__(a); a * 2 * P::RAD2DEG__; end}
331
-
332
- v = vec 1, 0, 0
333
- assert_equal_vector vec(M.cos(angle), M.sin(angle), 0), v.rotate(angle)
334
- assert_equal_vector vec(M.cos(angle), M.sin(angle), 0), v
335
-
336
- v = vec 1, 0, 0, context: context
337
- assert_equal_vector vec(M.cos(angle * 2), M.sin(angle * 2), 0), v.rotate(angle)
338
- end
339
-
340
- def test_fromAngle()
341
- angle = PI * 2 * 0.1
342
- result = vec
343
- assert_equal_vector vec(M.cos(angle), M.sin(angle), 0), V.fromAngle(angle)
344
- assert_equal_vector vec(M.cos(angle), M.sin(angle), 0), V.fromAngle(angle, result)
345
- assert_equal_vector vec(M.cos(angle), M.sin(angle), 0), result
346
- end
347
-
348
- def test_heading()
349
- angle = PI * 1 * 0.1
350
- assert_in_delta( angle, V.fromAngle( angle).heading, 0.000001)
351
- assert_in_delta(-angle, V.fromAngle(-angle).heading, 0.000001)
352
- end
353
-
354
- def test_angleBetween()
355
- v1 = V.fromAngle PI * 0.25
356
- v2 = V.fromAngle PI * 0.75
357
- assert_in_delta PI / 2, V.angleBetween(v1, v2), 0.000001
358
- end
359
-
360
- def test_lerp()
361
- assert_equal_vector vec(0.5, 0.5, 0.5), vec(0, 0, 0).lerp(vec(1, 1, 1), 0.5)
362
- assert_equal_vector vec(0.5, 0.5, 0.5), vec(0, 0, 0).lerp( 1, 1, 1, 0.5)
363
- assert_equal_vector vec(0.5, 0.5, 0.5), V.lerp(vec(0, 0, 0), vec(1, 1, 1), 0.5)
364
- end
365
-
366
- def test_random2D()
367
- v1 = V.random2D
368
- v2 = V.random2D
369
- assert v1.x != 0
370
- assert v1.y != 0
371
- assert_equal 0, v1.z
372
- assert v2.x != 0
373
- assert v2.y != 0
374
- assert_equal 0, v2.z
375
- assert_not_equal v1, v2
376
- assert_in_delta 1, v1.mag, 0.000001
377
- assert_in_delta 1, v2.mag, 0.000001
378
- end
379
-
380
- def test_random3D()
381
- v1 = V.random3D
382
- v2 = V.random3D
383
- assert v1.x != 0
384
- assert v1.y != 0
385
- assert v1.z != 0
386
- assert v2.x != 0
387
- assert v2.y != 0
388
- assert v2.z != 0
389
- assert_not_equal v1, v2
390
- assert_in_delta 1, v1.mag, 0.000001
391
- assert_in_delta 1, v2.mag, 0.000001
392
- end
393
-
394
- end# TestProcessingVector