rubysketch 0.3.3 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +62 -0
- data/.github/workflows/test.yml +27 -0
- data/ChangeLog.md +34 -0
- data/Gemfile +4 -0
- data/VERSION +1 -1
- data/examples/breakout.rb +212 -0
- data/examples/camera.rb +14 -0
- data/lib/rubysketch-processing.rb +11 -3
- data/lib/rubysketch/processing.rb +558 -286
- data/rubysketch.gemspec +0 -8
- data/test/helper.rb +24 -0
- data/test/processing/test_utility.rb +38 -0
- data/test/processing/test_vector.rb +139 -137
- metadata +15 -77
data/rubysketch.gemspec
CHANGED
@@ -28,17 +28,9 @@ Gem::Specification.new do |s|
|
|
28
28
|
s.platform = Gem::Platform::RUBY
|
29
29
|
s.required_ruby_version = '~> 2'
|
30
30
|
|
31
|
-
s.add_runtime_dependency 'yard'
|
32
|
-
s.add_runtime_dependency 'xot', '~> 0.1'
|
33
|
-
s.add_runtime_dependency 'beeps', '~> 0.1'
|
34
|
-
s.add_runtime_dependency 'rucy', '~> 0.1'
|
35
|
-
s.add_runtime_dependency 'rays', '~> 0.1'
|
36
31
|
s.add_runtime_dependency 'reflexion', '~> 0.1'
|
37
32
|
|
38
33
|
s.files = `git ls-files`.split $/
|
39
34
|
s.test_files = s.files.grep %r{^(test|spec|features)/}
|
40
35
|
s.extra_rdoc_files = rdocs.to_a
|
41
|
-
s.has_rdoc = true
|
42
|
-
|
43
|
-
s.extensions << 'Rakefile'
|
44
36
|
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
%w[../xot ../rucy ../rays ../reflex .]
|
5
|
+
.map {|s| File.expand_path "../../#{s}/lib", __FILE__}
|
6
|
+
.each {|s| $:.unshift s if !$:.include?(s) && File.directory?(s)}
|
7
|
+
|
8
|
+
require 'test/unit'
|
9
|
+
require 'xot/test'
|
10
|
+
require 'rubysketch'
|
11
|
+
|
12
|
+
include Xot::Test
|
13
|
+
|
14
|
+
|
15
|
+
unless $RAYS_NOAUTOINIT
|
16
|
+
#def Rays.fin! () end
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def assert_equal_vector (v1, v2, delta = 0.000001)
|
21
|
+
assert_in_delta v1.x, v2.x, delta
|
22
|
+
assert_in_delta v1.y, v2.y, delta
|
23
|
+
assert_in_delta v1.z, v2.z, delta
|
24
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
|
4
|
+
require_relative '../helper'
|
5
|
+
|
6
|
+
|
7
|
+
class TestProcessingUtility < Test::Unit::TestCase
|
8
|
+
|
9
|
+
class Context
|
10
|
+
include RubySketch::Processing::Context
|
11
|
+
end
|
12
|
+
|
13
|
+
def context
|
14
|
+
Context.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_random ()
|
18
|
+
c = context
|
19
|
+
|
20
|
+
assert_equal Float, c.random(1).class
|
21
|
+
assert_equal Float, c.random(1.0).class
|
22
|
+
assert_equal Symbol, c.random((:a..:z).to_a).class
|
23
|
+
|
24
|
+
assert_not_equal c.random, c.random
|
25
|
+
|
26
|
+
10000.times do
|
27
|
+
n = c.random
|
28
|
+
assert 0 <= n && n < 1
|
29
|
+
|
30
|
+
n = c.random 1
|
31
|
+
assert 0 <= n && n < 1
|
32
|
+
|
33
|
+
n = c.random 1, 2
|
34
|
+
assert 1.0 <= n && n < 2.0
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end# TestProcessingUtility
|
@@ -6,7 +6,9 @@ require_relative '../helper'
|
|
6
6
|
|
7
7
|
class TestProcessingVector < Test::Unit::TestCase
|
8
8
|
|
9
|
-
|
9
|
+
P = RubySketch::Processing
|
10
|
+
|
11
|
+
V = P::Vector
|
10
12
|
|
11
13
|
M = Math
|
12
14
|
|
@@ -21,76 +23,76 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
21
23
|
end
|
22
24
|
|
23
25
|
def test_initialize ()
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
assert_equal_vector vec(0, 0, 0), vec()
|
27
|
+
assert_equal_vector vec(1, 0, 0), vec(1)
|
28
|
+
assert_equal_vector vec(1, 2, 0), vec(1, 2)
|
29
|
+
assert_equal_vector vec(1, 2, 3), vec(1, 2, 3)
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
assert_equal_vector vec(0, 0, 0), vec([])
|
32
|
+
assert_equal_vector vec(1, 0, 0), vec([1])
|
33
|
+
assert_equal_vector vec(1, 2, 0), vec([1, 2])
|
34
|
+
assert_equal_vector vec(1, 2, 3), vec([1, 2, 3])
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
+
assert_equal_vector vec(1, 2, 3), vec(vec 1, 2, 3)
|
37
|
+
assert_equal_vector vec(1, 2, 3), vec(point 1, 2, 3)
|
36
38
|
end
|
37
39
|
|
38
40
|
def test_set ()
|
39
41
|
v0 = vec 9, 9, 9
|
40
42
|
|
41
|
-
v = v0.dup; v.set;
|
42
|
-
v = v0.dup; v.set 1;
|
43
|
-
v = v0.dup; v.set 1, 2;
|
44
|
-
v = v0.dup; v.set 1, 2, 3;
|
43
|
+
v = v0.dup; v.set; assert_equal_vector vec(0, 0, 0), v
|
44
|
+
v = v0.dup; v.set 1; assert_equal_vector vec(1, 0, 0), v
|
45
|
+
v = v0.dup; v.set 1, 2; assert_equal_vector vec(1, 2, 0), v
|
46
|
+
v = v0.dup; v.set 1, 2, 3; assert_equal_vector vec(1, 2, 3), v
|
45
47
|
|
46
|
-
v = v0.dup; v.set [];
|
47
|
-
v = v0.dup; v.set [1];
|
48
|
-
v = v0.dup; v.set [1, 2];
|
49
|
-
v = v0.dup; v.set [1, 2, 3];
|
48
|
+
v = v0.dup; v.set []; assert_equal_vector vec(0, 0, 0), v
|
49
|
+
v = v0.dup; v.set [1]; assert_equal_vector vec(1, 0, 0), v
|
50
|
+
v = v0.dup; v.set [1, 2]; assert_equal_vector vec(1, 2, 0), v
|
51
|
+
v = v0.dup; v.set [1, 2, 3]; assert_equal_vector vec(1, 2, 3), v
|
50
52
|
|
51
|
-
v = v0.dup; v.set vec(1, 2, 3);
|
52
|
-
v = v0.dup; v.set point(1, 2, 3);
|
53
|
+
v = v0.dup; v.set vec(1, 2, 3); assert_equal_vector vec(1, 2, 3), v
|
54
|
+
v = v0.dup; v.set point(1, 2, 3); assert_equal_vector vec(1, 2, 3), v
|
53
55
|
end
|
54
56
|
|
55
57
|
def test_dup ()
|
56
58
|
v1 = vec 1, 2, 3
|
57
|
-
|
59
|
+
assert_equal_vector vec(1, 2, 3), v1
|
58
60
|
|
59
61
|
v2 = v1.dup
|
60
|
-
|
61
|
-
|
62
|
+
assert_equal_vector vec(1, 2, 3), v1
|
63
|
+
assert_equal_vector vec(1, 2, 3), v2
|
62
64
|
|
63
65
|
v1.set 7, 8, 9
|
64
|
-
|
65
|
-
|
66
|
+
assert_equal_vector vec(7, 8, 9), v1
|
67
|
+
assert_equal_vector vec(1, 2, 3), v2
|
66
68
|
end
|
67
69
|
|
68
70
|
def test_copy ()
|
69
71
|
v1 = vec 1, 2, 3
|
70
|
-
|
72
|
+
assert_equal_vector vec(1, 2, 3), v1
|
71
73
|
|
72
74
|
v2 = v1.copy
|
73
|
-
|
74
|
-
|
75
|
+
assert_equal_vector vec(1, 2, 3), v1
|
76
|
+
assert_equal_vector vec(1, 2, 3), v2
|
75
77
|
|
76
78
|
v1.set 7, 8, 9
|
77
|
-
|
78
|
-
|
79
|
+
assert_equal_vector vec(7, 8, 9), v1
|
80
|
+
assert_equal_vector vec(1, 2, 3), v2
|
79
81
|
end
|
80
82
|
|
81
83
|
def test_xyz ()
|
82
84
|
v = vec 1, 2, 3
|
83
|
-
|
84
|
-
assert_equal
|
85
|
+
assert_equal_vector vec(1, 2, 3), v
|
86
|
+
assert_equal [1, 2, 3], [v.x, v.y, v.z]
|
85
87
|
|
86
88
|
v.x = 7
|
87
|
-
|
89
|
+
assert_equal_vector vec(7, 2, 3), v
|
88
90
|
|
89
91
|
v.y = 8
|
90
|
-
|
92
|
+
assert_equal_vector vec(7, 8, 3), v
|
91
93
|
|
92
94
|
v.z = 9
|
93
|
-
|
95
|
+
assert_equal_vector vec(7, 8, 9), v
|
94
96
|
end
|
95
97
|
|
96
98
|
def test_array ()
|
@@ -100,135 +102,135 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
100
102
|
def test_add ()
|
101
103
|
v = vec 1, 2, 3
|
102
104
|
v.add 4, 5, 6
|
103
|
-
|
105
|
+
assert_equal_vector vec(5, 7, 9), v
|
104
106
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
107
|
+
assert_equal_vector vec(1, 2, 3), vec(1, 2, 3).add()
|
108
|
+
assert_equal_vector vec(5, 2, 3), vec(1, 2, 3).add(4)
|
109
|
+
assert_equal_vector vec(5, 7, 3), vec(1, 2, 3).add(4, 5)
|
110
|
+
assert_equal_vector vec(5, 7, 9), vec(1, 2, 3).add(4, 5, 6)
|
109
111
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
112
|
+
assert_equal_vector vec(1, 2, 3), vec(1, 2, 3).add([])
|
113
|
+
assert_equal_vector vec(5, 2, 3), vec(1, 2, 3).add([4])
|
114
|
+
assert_equal_vector vec(5, 7, 3), vec(1, 2, 3).add([4, 5])
|
115
|
+
assert_equal_vector vec(5, 7, 9), vec(1, 2, 3).add([4, 5, 6])
|
114
116
|
|
115
|
-
|
116
|
-
|
117
|
+
assert_equal_vector vec(5, 7, 9), vec(1, 2, 3).add( vec(4, 5, 6))
|
118
|
+
assert_equal_vector vec(5, 7, 9), vec(1, 2, 3).add(point(4, 5, 6))
|
117
119
|
end
|
118
120
|
|
119
121
|
def test_sub ()
|
120
122
|
v = vec 9, 8, 7
|
121
123
|
v.sub 1, 2, 3
|
122
|
-
|
124
|
+
assert_equal_vector vec(8, 6, 4), v
|
123
125
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
126
|
+
assert_equal_vector vec(9, 8, 7), vec(9, 8, 7).sub()
|
127
|
+
assert_equal_vector vec(8, 8, 7), vec(9, 8, 7).sub(1)
|
128
|
+
assert_equal_vector vec(8, 6, 7), vec(9, 8, 7).sub(1, 2)
|
129
|
+
assert_equal_vector vec(8, 6, 4), vec(9, 8, 7).sub(1, 2, 3)
|
128
130
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
131
|
+
assert_equal_vector vec(9, 8, 7), vec(9, 8, 7).sub([])
|
132
|
+
assert_equal_vector vec(8, 8, 7), vec(9, 8, 7).sub([1])
|
133
|
+
assert_equal_vector vec(8, 6, 7), vec(9, 8, 7).sub([1, 2])
|
134
|
+
assert_equal_vector vec(8, 6, 4), vec(9, 8, 7).sub([1, 2, 3])
|
133
135
|
|
134
|
-
|
135
|
-
|
136
|
+
assert_equal_vector vec(8, 6, 4), vec(9, 8, 7).sub( vec(1, 2, 3))
|
137
|
+
assert_equal_vector vec(8, 6, 4), vec(9, 8, 7).sub(point(1, 2, 3))
|
136
138
|
end
|
137
139
|
|
138
140
|
def test_mult ()
|
139
141
|
v = vec 1, 2, 3
|
140
142
|
v.mult 2
|
141
|
-
|
143
|
+
assert_equal_vector vec(2, 4, 6), v
|
142
144
|
end
|
143
145
|
|
144
146
|
def test_div ()
|
145
147
|
v = vec 2, 4, 6
|
146
148
|
v.div 2
|
147
|
-
|
149
|
+
assert_equal_vector vec(1, 2, 3), v
|
148
150
|
end
|
149
151
|
|
150
152
|
def test_op_add ()
|
151
153
|
v1 = vec 1, 2, 3
|
152
154
|
v2 = vec 4, 5, 6
|
153
|
-
|
154
|
-
|
155
|
-
|
155
|
+
assert_equal_vector vec(5, 7, 9), v1 + v2
|
156
|
+
assert_equal_vector vec(1, 2, 3), v1
|
157
|
+
assert_equal_vector vec(4, 5, 6), v2
|
156
158
|
|
157
|
-
|
159
|
+
assert_equal_vector vec(5, 2, 3), vec(1, 2, 3) + 4
|
158
160
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
161
|
+
assert_equal_vector vec(1, 2, 3), vec(1, 2, 3) + []
|
162
|
+
assert_equal_vector vec(5, 2, 3), vec(1, 2, 3) + [4]
|
163
|
+
assert_equal_vector vec(5, 7, 3), vec(1, 2, 3) + [4, 5]
|
164
|
+
assert_equal_vector vec(5, 7, 9), vec(1, 2, 3) + [4, 5, 6]
|
163
165
|
|
164
|
-
|
165
|
-
|
166
|
+
assert_equal_vector vec(5, 7, 9), vec(1, 2, 3) + vec(4, 5, 6)
|
167
|
+
assert_equal_vector vec(5, 7, 9), vec(1, 2, 3) + point(4, 5, 6)
|
166
168
|
end
|
167
169
|
|
168
170
|
def test_op_sub ()
|
169
171
|
v1 = vec 9, 8, 7
|
170
172
|
v2 = vec 1, 2, 3
|
171
|
-
|
172
|
-
|
173
|
-
|
173
|
+
assert_equal_vector vec(8, 6, 4), v1 - v2
|
174
|
+
assert_equal_vector vec(9, 8, 7), v1
|
175
|
+
assert_equal_vector vec(1, 2, 3), v2
|
174
176
|
|
175
|
-
|
177
|
+
assert_equal_vector vec(8, 8, 7), vec(9, 8, 7) - 1
|
176
178
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
179
|
+
assert_equal_vector vec(9, 8, 7), vec(9, 8, 7) - []
|
180
|
+
assert_equal_vector vec(8, 8, 7), vec(9, 8, 7) - [1]
|
181
|
+
assert_equal_vector vec(8, 6, 7), vec(9, 8, 7) - [1, 2]
|
182
|
+
assert_equal_vector vec(8, 6, 4), vec(9, 8, 7) - [1, 2, 3]
|
181
183
|
|
182
|
-
|
183
|
-
|
184
|
+
assert_equal_vector vec(8, 6, 4), vec(9, 8, 7) - vec(1, 2, 3)
|
185
|
+
assert_equal_vector vec(8, 6, 4), vec(9, 8, 7) - point(1, 2, 3)
|
184
186
|
end
|
185
187
|
|
186
188
|
def test_op_mult ()
|
187
189
|
v = vec 1, 2, 3
|
188
|
-
|
189
|
-
|
190
|
+
assert_equal_vector vec(2, 4, 6), v * 2
|
191
|
+
assert_equal_vector vec(1, 2, 3), v
|
190
192
|
end
|
191
193
|
|
192
194
|
def test_op_div ()
|
193
195
|
v = vec 2, 4, 6
|
194
|
-
|
195
|
-
|
196
|
+
assert_equal_vector vec(1, 2, 3), v / 2
|
197
|
+
assert_equal_vector vec(2, 4, 6), v
|
196
198
|
end
|
197
199
|
|
198
200
|
def test_fun_add ()
|
199
201
|
v1 = vec 1, 2, 3
|
200
202
|
v2 = vec 4, 5, 6
|
201
203
|
result = vec
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
204
|
+
assert_equal_vector vec(5, 7, 9), V.add(v1, v2, result)
|
205
|
+
assert_equal_vector vec(1, 2, 3), v1
|
206
|
+
assert_equal_vector vec(4, 5, 6), v2
|
207
|
+
assert_equal_vector vec(5, 7, 9), result
|
206
208
|
end
|
207
209
|
|
208
210
|
def test_fun_sub ()
|
209
211
|
v1 = vec 9, 8, 7
|
210
212
|
v2 = vec 1, 2, 3
|
211
213
|
result = vec
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
214
|
+
assert_equal_vector vec(8, 6, 4), V.sub(v1, v2, result)
|
215
|
+
assert_equal_vector vec(9, 8, 7), v1
|
216
|
+
assert_equal_vector vec(1, 2, 3), v2
|
217
|
+
assert_equal_vector vec(8, 6, 4), result
|
216
218
|
end
|
217
219
|
|
218
220
|
def test_fun_mult ()
|
219
221
|
v1 = vec 1, 2, 3
|
220
222
|
result = vec
|
221
|
-
|
222
|
-
|
223
|
-
|
223
|
+
assert_equal_vector vec(2, 4, 6), V.mult(v1, 2, result)
|
224
|
+
assert_equal_vector vec(1, 2, 3), v1
|
225
|
+
assert_equal_vector vec(2, 4, 6), result
|
224
226
|
end
|
225
227
|
|
226
228
|
def test_fun_div ()
|
227
229
|
v1 = vec 2, 4, 6
|
228
230
|
result = vec
|
229
|
-
|
230
|
-
|
231
|
-
|
231
|
+
assert_equal_vector vec(1, 2, 3), V.div(v1, 2, result)
|
232
|
+
assert_equal_vector vec(2, 4, 6), v1
|
233
|
+
assert_equal_vector vec(1, 2, 3), result
|
232
234
|
end
|
233
235
|
|
234
236
|
def test_mag ()
|
@@ -243,27 +245,27 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
243
245
|
|
244
246
|
def test_setMag ()
|
245
247
|
v = vec 3, 4, 0
|
246
|
-
|
247
|
-
|
248
|
+
assert_equal_vector vec(6, 8, 0), v.setMag(10)
|
249
|
+
assert_equal_vector vec(6, 8, 0), v
|
248
250
|
|
249
251
|
v = vec 3, 4, 0
|
250
252
|
result = vec
|
251
|
-
|
252
|
-
|
253
|
-
|
253
|
+
assert_equal_vector vec(6, 8, 0), v.setMag(result, 10)
|
254
|
+
assert_equal_vector vec(3, 4, 0), v
|
255
|
+
assert_equal_vector vec(6, 8, 0), result
|
254
256
|
end
|
255
257
|
|
256
258
|
def test_normalize ()
|
257
259
|
v = vec 1, 2, 3
|
258
260
|
normal = v / v.mag
|
259
|
-
|
260
|
-
|
261
|
+
assert_equal_vector normal, v.normalize
|
262
|
+
assert_equal_vector normal, v
|
261
263
|
|
262
264
|
v = vec 1, 2, 3
|
263
265
|
result = vec
|
264
|
-
|
265
|
-
|
266
|
-
|
266
|
+
assert_equal_vector normal, v.normalize(result)
|
267
|
+
assert_equal_vector vec(1, 2, 3), v
|
268
|
+
assert_equal_vector normal, result
|
267
269
|
end
|
268
270
|
|
269
271
|
def test_limit ()
|
@@ -282,12 +284,12 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
282
284
|
v2 = vec 4, 5, 6
|
283
285
|
|
284
286
|
assert_in_delta M.sqrt((4-1)**2 + (5-2)**2 + (6-3)**2), v1.dist(v2), 0.000001
|
285
|
-
|
286
|
-
|
287
|
+
assert_equal_vector vec(1, 2, 3), v1
|
288
|
+
assert_equal_vector vec(4, 5, 6), v2
|
287
289
|
|
288
290
|
assert_in_delta M.sqrt((4-1)**2 + (5-2)**2 + (6-3)**2), V.dist(v1, v2), 0.000001
|
289
|
-
|
290
|
-
|
291
|
+
assert_equal_vector vec(1, 2, 3), v1
|
292
|
+
assert_equal_vector vec(4, 5, 6), v2
|
291
293
|
end
|
292
294
|
|
293
295
|
def test_dot ()
|
@@ -295,55 +297,55 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
295
297
|
v2 = vec 4, 5, 6
|
296
298
|
|
297
299
|
assert_equal 1*4 + 2*5 + 3*6, v1.dot(4, 5, 6)
|
298
|
-
|
300
|
+
assert_equal_vector vec(1, 2, 3), v1
|
299
301
|
|
300
302
|
assert_equal 1*4 + 2*5 + 3*6, v1.dot(v2)
|
301
|
-
|
302
|
-
|
303
|
+
assert_equal_vector vec(1, 2, 3), v1
|
304
|
+
assert_equal_vector vec(4, 5, 6), v2
|
303
305
|
|
304
306
|
assert_equal 1*4 + 2*5 + 3*6, V.dot(v1, v2)
|
305
|
-
|
306
|
-
|
307
|
+
assert_equal_vector vec(1, 2, 3), v1
|
308
|
+
assert_equal_vector vec(4, 5, 6), v2
|
307
309
|
end
|
308
310
|
|
309
311
|
def test_cross ()
|
310
312
|
v1 = vec 1, 0, 0
|
311
313
|
v2 = vec 0, 1, 0
|
312
314
|
|
313
|
-
|
314
|
-
|
315
|
+
assert_equal_vector vec(0, 0, 1), v1.cross(0, 1, 0)
|
316
|
+
assert_equal_vector vec(1, 0, 0), v1
|
315
317
|
|
316
318
|
result = vec 1, 2, 3
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
319
|
+
assert_equal_vector vec(0, 0, 1), v1.cross(v2, result)
|
320
|
+
assert_equal_vector vec(1, 0, 0), v1
|
321
|
+
assert_equal_vector vec(0, 1, 0), v2
|
322
|
+
assert_equal_vector vec(0, 0, 1), result
|
321
323
|
|
322
324
|
result = vec 1, 2, 3
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
325
|
+
assert_equal_vector vec(0, 0, 1), V.cross(v1, v2, result)
|
326
|
+
assert_equal_vector vec(1, 0, 0), v1
|
327
|
+
assert_equal_vector vec(0, 1, 0), v2
|
328
|
+
assert_equal_vector vec(0, 0, 1), result
|
327
329
|
end
|
328
330
|
|
329
331
|
def test_rotate ()
|
330
332
|
angle = PI * 2 * 0.1
|
331
|
-
context = Object.new.tap {|o| def o.toAngle__ (
|
333
|
+
context = Object.new.tap {|o| def o.toAngle__ (a); a * 2 * P::RAD2DEG__; end}
|
332
334
|
|
333
335
|
v = vec 1, 0, 0
|
334
|
-
|
335
|
-
|
336
|
+
assert_equal_vector vec(M.cos(angle), M.sin(angle), 0), v.rotate(angle)
|
337
|
+
assert_equal_vector vec(M.cos(angle), M.sin(angle), 0), v
|
336
338
|
|
337
339
|
v = vec 1, 0, 0, context: context
|
338
|
-
|
340
|
+
assert_equal_vector vec(M.cos(angle * 2), M.sin(angle * 2), 0), v.rotate(angle)
|
339
341
|
end
|
340
342
|
|
341
343
|
def test_fromAngle ()
|
342
344
|
angle = PI * 2 * 0.1
|
343
345
|
result = vec
|
344
|
-
|
345
|
-
|
346
|
-
|
346
|
+
assert_equal_vector vec(M.cos(angle), M.sin(angle), 0), V.fromAngle(angle)
|
347
|
+
assert_equal_vector vec(M.cos(angle), M.sin(angle), 0), V.fromAngle(angle, result)
|
348
|
+
assert_equal_vector vec(M.cos(angle), M.sin(angle), 0), result
|
347
349
|
end
|
348
350
|
|
349
351
|
def test_heading ()
|
@@ -359,9 +361,9 @@ class TestProcessingVector < Test::Unit::TestCase
|
|
359
361
|
end
|
360
362
|
|
361
363
|
def test_lerp ()
|
362
|
-
|
363
|
-
|
364
|
-
|
364
|
+
assert_equal_vector vec(0.5, 0.5, 0.5), vec(0, 0, 0).lerp(vec(1, 1, 1), 0.5)
|
365
|
+
assert_equal_vector vec(0.5, 0.5, 0.5), vec(0, 0, 0).lerp( 1, 1, 1, 0.5)
|
366
|
+
assert_equal_vector vec(0.5, 0.5, 0.5), V.lerp(vec(0, 0, 0), vec(1, 1, 1), 0.5)
|
365
367
|
end
|
366
368
|
|
367
369
|
def test_random2D ()
|