larb 0.1.0 → 1.0.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +14 -1
- data/ext/larb/color.c +446 -0
- data/ext/larb/color.h +35 -0
- data/ext/larb/extconf.rb +11 -0
- data/ext/larb/larb.c +27 -0
- data/ext/larb/larb.h +8 -0
- data/ext/larb/mat2.c +300 -0
- data/ext/larb/mat2.h +30 -0
- data/ext/larb/mat2d.c +380 -0
- data/ext/larb/mat2d.h +35 -0
- data/ext/larb/mat3.c +469 -0
- data/ext/larb/mat3.h +33 -0
- data/ext/larb/mat4.c +671 -0
- data/ext/larb/mat4.h +31 -0
- data/ext/larb/quat.c +523 -0
- data/ext/larb/quat.h +39 -0
- data/ext/larb/quat2.c +473 -0
- data/ext/larb/quat2.h +39 -0
- data/ext/larb/vec2.c +342 -0
- data/ext/larb/vec2.h +43 -0
- data/ext/larb/vec3.c +503 -0
- data/ext/larb/vec3.h +52 -0
- data/ext/larb/vec4.c +340 -0
- data/ext/larb/vec4.h +38 -0
- data/lib/larb/version.rb +5 -0
- data/lib/larb.rb +2 -14
- data/test/larb/color_test.rb +278 -0
- data/test/larb/mat2_test.rb +144 -0
- data/test/larb/mat2d_test.rb +172 -0
- data/test/larb/mat3_test.rb +147 -0
- data/test/larb/mat4_test.rb +270 -0
- data/test/larb/quat2_test.rb +161 -0
- data/test/larb/quat_test.rb +224 -0
- data/test/larb/vec2_test.rb +251 -0
- data/test/larb/vec3_test.rb +310 -0
- data/test/larb/vec4_test.rb +189 -0
- data/test/test_helper.rb +4 -0
- metadata +53 -14
- data/Rakefile +0 -11
- data/lib/larb/color.rb +0 -148
- data/lib/larb/mat2.rb +0 -119
- data/lib/larb/mat2d.rb +0 -180
- data/lib/larb/mat3.rb +0 -238
- data/lib/larb/mat4.rb +0 -329
- data/lib/larb/quat.rb +0 -238
- data/lib/larb/quat2.rb +0 -193
- data/lib/larb/vec2.rb +0 -150
- data/lib/larb/vec3.rb +0 -218
- data/lib/larb/vec4.rb +0 -125
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../test_helper"
|
|
4
|
+
|
|
5
|
+
class Vec3Test < Test::Unit::TestCase
|
|
6
|
+
def test_new_with_default_values
|
|
7
|
+
v = Larb::Vec3.new
|
|
8
|
+
assert_equal 0.0, v.x
|
|
9
|
+
assert_equal 0.0, v.y
|
|
10
|
+
assert_equal 0.0, v.z
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_new_with_given_values
|
|
14
|
+
v = Larb::Vec3.new(1, 2, 3)
|
|
15
|
+
assert_equal 1.0, v.x
|
|
16
|
+
assert_equal 2.0, v.y
|
|
17
|
+
assert_equal 3.0, v.z
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_bracket_syntax
|
|
21
|
+
v = Larb::Vec3[1, 2, 3]
|
|
22
|
+
assert_equal 1.0, v.x
|
|
23
|
+
assert_equal 2.0, v.y
|
|
24
|
+
assert_equal 3.0, v.z
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_zero
|
|
28
|
+
assert_equal Larb::Vec3.new(0, 0, 0), Larb::Vec3.zero
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_one
|
|
32
|
+
assert_equal Larb::Vec3.new(1, 1, 1), Larb::Vec3.one
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_up
|
|
36
|
+
assert_equal Larb::Vec3.new(0, 1, 0), Larb::Vec3.up
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_down
|
|
40
|
+
assert_equal Larb::Vec3.new(0, -1, 0), Larb::Vec3.down
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_forward
|
|
44
|
+
assert_equal Larb::Vec3.new(0, 0, -1), Larb::Vec3.forward
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_back
|
|
48
|
+
assert_equal Larb::Vec3.new(0, 0, 1), Larb::Vec3.back
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_right
|
|
52
|
+
assert_equal Larb::Vec3.new(1, 0, 0), Larb::Vec3.right
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_left
|
|
56
|
+
assert_equal Larb::Vec3.new(-1, 0, 0), Larb::Vec3.left
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def test_add
|
|
60
|
+
v1 = Larb::Vec3.new(1, 2, 3)
|
|
61
|
+
v2 = Larb::Vec3.new(4, 5, 6)
|
|
62
|
+
assert_equal Larb::Vec3.new(5, 7, 9), v1 + v2
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_subtract
|
|
66
|
+
v1 = Larb::Vec3.new(4, 5, 6)
|
|
67
|
+
v2 = Larb::Vec3.new(1, 2, 3)
|
|
68
|
+
assert_equal Larb::Vec3.new(3, 3, 3), v1 - v2
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def test_multiply_by_scalar
|
|
72
|
+
v = Larb::Vec3.new(1, 2, 3)
|
|
73
|
+
assert_equal Larb::Vec3.new(2, 4, 6), v * 2
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_multiply_by_vec3
|
|
77
|
+
v1 = Larb::Vec3.new(1, 2, 3)
|
|
78
|
+
v2 = Larb::Vec3.new(2, 3, 4)
|
|
79
|
+
assert_equal Larb::Vec3.new(2, 6, 12), v1 * v2
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_divide_by_scalar
|
|
83
|
+
v = Larb::Vec3.new(2, 4, 6)
|
|
84
|
+
assert_equal Larb::Vec3.new(1, 2, 3), v / 2
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def test_negate
|
|
88
|
+
v = Larb::Vec3.new(1, -2, 3)
|
|
89
|
+
assert_equal Larb::Vec3.new(-1, 2, -3), -v
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def test_dot
|
|
93
|
+
v1 = Larb::Vec3.new(1, 2, 3)
|
|
94
|
+
v2 = Larb::Vec3.new(4, 5, 6)
|
|
95
|
+
assert_equal 32.0, v1.dot(v2)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def test_cross
|
|
99
|
+
v1 = Larb::Vec3.new(1, 0, 0)
|
|
100
|
+
v2 = Larb::Vec3.new(0, 1, 0)
|
|
101
|
+
assert_equal Larb::Vec3.new(0, 0, 1), v1.cross(v2)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def test_cross_arbitrary
|
|
105
|
+
v1 = Larb::Vec3.new(1, 2, 3)
|
|
106
|
+
v2 = Larb::Vec3.new(4, 5, 6)
|
|
107
|
+
assert_equal Larb::Vec3.new(-3, 6, -3), v1.cross(v2)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def test_length
|
|
111
|
+
v = Larb::Vec3.new(2, 3, 6)
|
|
112
|
+
assert_equal 7.0, v.length
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def test_length_squared
|
|
116
|
+
v = Larb::Vec3.new(2, 3, 6)
|
|
117
|
+
assert_equal 49.0, v.length_squared
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def test_normalize
|
|
121
|
+
v = Larb::Vec3.new(0, 3, 4)
|
|
122
|
+
result = v.normalize
|
|
123
|
+
assert_in_delta 0.0, result.x, 1e-10
|
|
124
|
+
assert_in_delta 0.6, result.y, 1e-10
|
|
125
|
+
assert_in_delta 0.8, result.z, 1e-10
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def test_reflect
|
|
129
|
+
v = Larb::Vec3.new(1, -1, 0).normalize
|
|
130
|
+
normal = Larb::Vec3.new(0, 1, 0)
|
|
131
|
+
result = v.reflect(normal)
|
|
132
|
+
assert_in_delta v.x, result.x, 1e-10
|
|
133
|
+
assert_in_delta(-v.y, result.y, 1e-10)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
def test_xy
|
|
137
|
+
v = Larb::Vec3.new(1, 2, 3)
|
|
138
|
+
result = v.xy
|
|
139
|
+
assert_instance_of Larb::Vec2, result
|
|
140
|
+
assert_equal 1.0, result.x
|
|
141
|
+
assert_equal 2.0, result.y
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
def test_xz
|
|
145
|
+
v = Larb::Vec3.new(1, 2, 3)
|
|
146
|
+
result = v.xz
|
|
147
|
+
assert_instance_of Larb::Vec2, result
|
|
148
|
+
assert_equal 1.0, result.x
|
|
149
|
+
assert_equal 3.0, result.y
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def test_yz
|
|
153
|
+
v = Larb::Vec3.new(1, 2, 3)
|
|
154
|
+
result = v.yz
|
|
155
|
+
assert_instance_of Larb::Vec2, result
|
|
156
|
+
assert_equal 2.0, result.x
|
|
157
|
+
assert_equal 3.0, result.y
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
def test_lerp
|
|
161
|
+
v1 = Larb::Vec3.new(0, 0, 0)
|
|
162
|
+
v2 = Larb::Vec3.new(10, 20, 30)
|
|
163
|
+
assert_equal Larb::Vec3.new(5, 10, 15), v1.lerp(v2, 0.5)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def test_to_a
|
|
167
|
+
v = Larb::Vec3.new(1, 2, 3)
|
|
168
|
+
assert_equal [1.0, 2.0, 3.0], v.to_a
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def test_to_vec4
|
|
172
|
+
v = Larb::Vec3.new(1, 2, 3)
|
|
173
|
+
result = v.to_vec4
|
|
174
|
+
assert_instance_of Larb::Vec4, result
|
|
175
|
+
assert_equal 1.0, result.x
|
|
176
|
+
assert_equal 2.0, result.y
|
|
177
|
+
assert_equal 3.0, result.z
|
|
178
|
+
assert_equal 1.0, result.w
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
def test_to_vec4_with_custom_w
|
|
182
|
+
v = Larb::Vec3.new(1, 2, 3)
|
|
183
|
+
result = v.to_vec4(0.5)
|
|
184
|
+
assert_equal 0.5, result.w
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def test_index_access
|
|
188
|
+
v = Larb::Vec3.new(1, 2, 3)
|
|
189
|
+
assert_equal 1.0, v[0]
|
|
190
|
+
assert_equal 2.0, v[1]
|
|
191
|
+
assert_equal 3.0, v[2]
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
def test_equality
|
|
195
|
+
v1 = Larb::Vec3.new(1, 2, 3)
|
|
196
|
+
v2 = Larb::Vec3.new(1, 2, 3)
|
|
197
|
+
assert_equal v1, v2
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def test_inequality
|
|
201
|
+
v1 = Larb::Vec3.new(1, 2, 3)
|
|
202
|
+
v2 = Larb::Vec3.new(1, 2, 4)
|
|
203
|
+
assert_not_equal v1, v2
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
def test_not_equal_to_array
|
|
207
|
+
v = Larb::Vec3.new(1, 2, 3)
|
|
208
|
+
assert_not_equal v, [1, 2, 3]
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def test_near
|
|
212
|
+
v1 = Larb::Vec3.new(1.0, 2.0, 3.0)
|
|
213
|
+
v2 = Larb::Vec3.new(1.0000001, 2.0000001, 3.0000001)
|
|
214
|
+
assert v1.near?(v2)
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def test_distance
|
|
218
|
+
v1 = Larb::Vec3.new(0, 0, 0)
|
|
219
|
+
v2 = Larb::Vec3.new(2, 3, 6)
|
|
220
|
+
assert_equal 7.0, v1.distance(v2)
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
def test_distance_squared
|
|
224
|
+
v1 = Larb::Vec3.new(0, 0, 0)
|
|
225
|
+
v2 = Larb::Vec3.new(2, 3, 6)
|
|
226
|
+
assert_equal 49.0, v1.distance_squared(v2)
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
def test_angle_between
|
|
230
|
+
v1 = Larb::Vec3.new(1, 0, 0)
|
|
231
|
+
v2 = Larb::Vec3.new(0, 1, 0)
|
|
232
|
+
assert_in_delta Math::PI / 2, v1.angle_between(v2), 1e-10
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
def test_project
|
|
236
|
+
v = Larb::Vec3.new(3, 4, 0)
|
|
237
|
+
onto = Larb::Vec3.new(1, 0, 0)
|
|
238
|
+
result = v.project(onto)
|
|
239
|
+
assert_equal 3.0, result.x
|
|
240
|
+
assert_equal 0.0, result.y
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def test_reject
|
|
244
|
+
v = Larb::Vec3.new(3, 4, 0)
|
|
245
|
+
from = Larb::Vec3.new(1, 0, 0)
|
|
246
|
+
result = v.reject(from)
|
|
247
|
+
assert_equal 0.0, result.x
|
|
248
|
+
assert_equal 4.0, result.y
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
def test_clamp_length
|
|
252
|
+
v = Larb::Vec3.new(2, 3, 6)
|
|
253
|
+
result = v.clamp_length(3.5)
|
|
254
|
+
assert_in_delta 3.5, result.length, 1e-10
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def test_clamp_length_under_limit
|
|
258
|
+
v = Larb::Vec3.new(1, 1, 1)
|
|
259
|
+
result = v.clamp_length(10)
|
|
260
|
+
assert_equal v, result
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
def test_normalize!
|
|
264
|
+
v = Larb::Vec3.new(0, 3, 4)
|
|
265
|
+
v.normalize!
|
|
266
|
+
assert_in_delta 1.0, v.length, 1e-10
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
def test_min
|
|
270
|
+
v1 = Larb::Vec3.new(1, 5, 3)
|
|
271
|
+
v2 = Larb::Vec3.new(2, 3, 4)
|
|
272
|
+
assert_equal Larb::Vec3.new(1, 3, 3), v1.min(v2)
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
def test_max
|
|
276
|
+
v1 = Larb::Vec3.new(1, 5, 3)
|
|
277
|
+
v2 = Larb::Vec3.new(2, 3, 4)
|
|
278
|
+
assert_equal Larb::Vec3.new(2, 5, 4), v1.max(v2)
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
def test_abs
|
|
282
|
+
v = Larb::Vec3.new(-1, -2, 3)
|
|
283
|
+
assert_equal Larb::Vec3.new(1, 2, 3), v.abs
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
def test_floor
|
|
287
|
+
v = Larb::Vec3.new(1.7, 2.3, 3.9)
|
|
288
|
+
assert_equal Larb::Vec3.new(1, 2, 3), v.floor
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
def test_ceil
|
|
292
|
+
v = Larb::Vec3.new(1.1, 2.5, 3.9)
|
|
293
|
+
assert_equal Larb::Vec3.new(2, 3, 4), v.ceil
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
def test_round
|
|
297
|
+
v = Larb::Vec3.new(1.4, 2.5, 3.6)
|
|
298
|
+
assert_equal Larb::Vec3.new(1, 3, 4), v.round
|
|
299
|
+
end
|
|
300
|
+
|
|
301
|
+
def test_inspect
|
|
302
|
+
v = Larb::Vec3.new(1, 2, 3)
|
|
303
|
+
assert_equal "Vec3[1.0, 2.0, 3.0]", v.inspect
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
def test_to_s
|
|
307
|
+
v = Larb::Vec3.new(1, 2, 3)
|
|
308
|
+
assert_equal v.inspect, v.to_s
|
|
309
|
+
end
|
|
310
|
+
end
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../test_helper"
|
|
4
|
+
|
|
5
|
+
class Vec4Test < Test::Unit::TestCase
|
|
6
|
+
def test_new_with_default_values
|
|
7
|
+
v = Larb::Vec4.new
|
|
8
|
+
assert_equal 0.0, v.x
|
|
9
|
+
assert_equal 0.0, v.y
|
|
10
|
+
assert_equal 0.0, v.z
|
|
11
|
+
assert_equal 1.0, v.w
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_new_with_given_values
|
|
15
|
+
v = Larb::Vec4.new(1, 2, 3, 4)
|
|
16
|
+
assert_equal 1.0, v.x
|
|
17
|
+
assert_equal 2.0, v.y
|
|
18
|
+
assert_equal 3.0, v.z
|
|
19
|
+
assert_equal 4.0, v.w
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_bracket_syntax
|
|
23
|
+
v = Larb::Vec4[1, 2, 3, 4]
|
|
24
|
+
assert_equal 1.0, v.x
|
|
25
|
+
assert_equal 2.0, v.y
|
|
26
|
+
assert_equal 3.0, v.z
|
|
27
|
+
assert_equal 4.0, v.w
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def test_bracket_syntax_default_w
|
|
31
|
+
v = Larb::Vec4[1, 2, 3]
|
|
32
|
+
assert_equal 1.0, v.w
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_zero
|
|
36
|
+
assert_equal Larb::Vec4.new(0, 0, 0, 0), Larb::Vec4.zero
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def test_one
|
|
40
|
+
assert_equal Larb::Vec4.new(1, 1, 1, 1), Larb::Vec4.one
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_add
|
|
44
|
+
v1 = Larb::Vec4.new(1, 2, 3, 4)
|
|
45
|
+
v2 = Larb::Vec4.new(5, 6, 7, 8)
|
|
46
|
+
assert_equal Larb::Vec4.new(6, 8, 10, 12), v1 + v2
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_subtract
|
|
50
|
+
v1 = Larb::Vec4.new(5, 6, 7, 8)
|
|
51
|
+
v2 = Larb::Vec4.new(1, 2, 3, 4)
|
|
52
|
+
assert_equal Larb::Vec4.new(4, 4, 4, 4), v1 - v2
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def test_multiply_by_scalar
|
|
56
|
+
v = Larb::Vec4.new(1, 2, 3, 4)
|
|
57
|
+
assert_equal Larb::Vec4.new(2, 4, 6, 8), v * 2
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def test_divide_by_scalar
|
|
61
|
+
v = Larb::Vec4.new(2, 4, 6, 8)
|
|
62
|
+
assert_equal Larb::Vec4.new(1, 2, 3, 4), v / 2
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def test_perspective_divide
|
|
66
|
+
v = Larb::Vec4.new(2, 4, 6, 2)
|
|
67
|
+
result = v.perspective_divide
|
|
68
|
+
assert_instance_of Larb::Vec3, result
|
|
69
|
+
assert_equal 1.0, result.x
|
|
70
|
+
assert_equal 2.0, result.y
|
|
71
|
+
assert_equal 3.0, result.z
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def test_perspective_divide_w_is_1
|
|
75
|
+
v = Larb::Vec4.new(1, 2, 3, 1)
|
|
76
|
+
assert_equal Larb::Vec3.new(1, 2, 3), v.perspective_divide
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def test_perspective_divide_w_is_0
|
|
80
|
+
v = Larb::Vec4.new(1, 2, 3, 0)
|
|
81
|
+
assert_equal Larb::Vec3.new(1, 2, 3), v.perspective_divide
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def test_xyz
|
|
85
|
+
v = Larb::Vec4.new(1, 2, 3, 4)
|
|
86
|
+
result = v.xyz
|
|
87
|
+
assert_instance_of Larb::Vec3, result
|
|
88
|
+
assert_equal Larb::Vec3.new(1, 2, 3), result
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def test_xy
|
|
92
|
+
v = Larb::Vec4.new(1, 2, 3, 4)
|
|
93
|
+
result = v.xy
|
|
94
|
+
assert_instance_of Larb::Vec2, result
|
|
95
|
+
assert_equal Larb::Vec2.new(1, 2), result
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def test_rgb
|
|
99
|
+
v = Larb::Vec4.new(0.5, 0.6, 0.7, 1.0)
|
|
100
|
+
result = v.rgb
|
|
101
|
+
assert_instance_of Larb::Vec3, result
|
|
102
|
+
assert_equal Larb::Vec3.new(0.5, 0.6, 0.7), result
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def test_to_a
|
|
106
|
+
v = Larb::Vec4.new(1, 2, 3, 4)
|
|
107
|
+
assert_equal [1.0, 2.0, 3.0, 4.0], v.to_a
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def test_index_access
|
|
111
|
+
v = Larb::Vec4.new(1, 2, 3, 4)
|
|
112
|
+
assert_equal 1.0, v[0]
|
|
113
|
+
assert_equal 2.0, v[1]
|
|
114
|
+
assert_equal 3.0, v[2]
|
|
115
|
+
assert_equal 4.0, v[3]
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def test_negate
|
|
119
|
+
v = Larb::Vec4.new(1, -2, 3, -4)
|
|
120
|
+
assert_equal Larb::Vec4.new(-1, 2, -3, 4), -v
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def test_dot
|
|
124
|
+
v1 = Larb::Vec4.new(1, 2, 3, 4)
|
|
125
|
+
v2 = Larb::Vec4.new(5, 6, 7, 8)
|
|
126
|
+
assert_equal 70.0, v1.dot(v2)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def test_length
|
|
130
|
+
v = Larb::Vec4.new(1, 2, 2, 0)
|
|
131
|
+
assert_equal 3.0, v.length
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def test_length_squared
|
|
135
|
+
v = Larb::Vec4.new(1, 2, 2, 0)
|
|
136
|
+
assert_equal 9.0, v.length_squared
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def test_normalize
|
|
140
|
+
v = Larb::Vec4.new(1, 2, 2, 0)
|
|
141
|
+
result = v.normalize
|
|
142
|
+
assert_in_delta 1.0, result.length, 1e-10
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def test_normalize!
|
|
146
|
+
v = Larb::Vec4.new(1, 2, 2, 0)
|
|
147
|
+
v.normalize!
|
|
148
|
+
assert_in_delta 1.0, v.length, 1e-10
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def test_equality
|
|
152
|
+
v1 = Larb::Vec4.new(1, 2, 3, 4)
|
|
153
|
+
v2 = Larb::Vec4.new(1, 2, 3, 4)
|
|
154
|
+
assert_equal v1, v2
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def test_inequality
|
|
158
|
+
v1 = Larb::Vec4.new(1, 2, 3, 4)
|
|
159
|
+
v2 = Larb::Vec4.new(1, 2, 3, 5)
|
|
160
|
+
assert_not_equal v1, v2
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def test_not_equal_to_array
|
|
164
|
+
v = Larb::Vec4.new(1, 2, 3, 4)
|
|
165
|
+
assert_not_equal v, [1, 2, 3, 4]
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
def test_near
|
|
169
|
+
v1 = Larb::Vec4.new(1.0, 2.0, 3.0, 4.0)
|
|
170
|
+
v2 = Larb::Vec4.new(1.0000001, 2.0000001, 3.0000001, 4.0000001)
|
|
171
|
+
assert v1.near?(v2)
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def test_lerp
|
|
175
|
+
v1 = Larb::Vec4.new(0, 0, 0, 0)
|
|
176
|
+
v2 = Larb::Vec4.new(10, 20, 30, 40)
|
|
177
|
+
assert_equal Larb::Vec4.new(5, 10, 15, 20), v1.lerp(v2, 0.5)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def test_inspect
|
|
181
|
+
v = Larb::Vec4.new(1, 2, 3, 4)
|
|
182
|
+
assert_equal "Vec4[1.0, 2.0, 3.0, 4.0]", v.inspect
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def test_to_s
|
|
186
|
+
v = Larb::Vec4.new(1, 2, 3, 4)
|
|
187
|
+
assert_equal v.inspect, v.to_s
|
|
188
|
+
end
|
|
189
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
|
@@ -1,37 +1,76 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: larb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Yudai Takada
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
-
dependencies:
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rake-compiler
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.2'
|
|
19
|
+
type: :development
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '1.2'
|
|
12
26
|
description: Larb provides vectors, matrices, quaternions, and Color classes for 2D/3D
|
|
13
27
|
graphics and mathematical computations
|
|
14
28
|
email:
|
|
15
29
|
- t.yudai92@gmail.com
|
|
16
30
|
executables: []
|
|
17
|
-
extensions:
|
|
31
|
+
extensions:
|
|
32
|
+
- ext/larb/extconf.rb
|
|
18
33
|
extra_rdoc_files: []
|
|
19
34
|
files:
|
|
20
35
|
- CHANGELOG.md
|
|
21
36
|
- LICENSE
|
|
22
37
|
- README.md
|
|
23
|
-
-
|
|
38
|
+
- ext/larb/color.c
|
|
39
|
+
- ext/larb/color.h
|
|
40
|
+
- ext/larb/extconf.rb
|
|
41
|
+
- ext/larb/larb.c
|
|
42
|
+
- ext/larb/larb.h
|
|
43
|
+
- ext/larb/mat2.c
|
|
44
|
+
- ext/larb/mat2.h
|
|
45
|
+
- ext/larb/mat2d.c
|
|
46
|
+
- ext/larb/mat2d.h
|
|
47
|
+
- ext/larb/mat3.c
|
|
48
|
+
- ext/larb/mat3.h
|
|
49
|
+
- ext/larb/mat4.c
|
|
50
|
+
- ext/larb/mat4.h
|
|
51
|
+
- ext/larb/quat.c
|
|
52
|
+
- ext/larb/quat.h
|
|
53
|
+
- ext/larb/quat2.c
|
|
54
|
+
- ext/larb/quat2.h
|
|
55
|
+
- ext/larb/vec2.c
|
|
56
|
+
- ext/larb/vec2.h
|
|
57
|
+
- ext/larb/vec3.c
|
|
58
|
+
- ext/larb/vec3.h
|
|
59
|
+
- ext/larb/vec4.c
|
|
60
|
+
- ext/larb/vec4.h
|
|
24
61
|
- lib/larb.rb
|
|
25
|
-
- lib/larb/
|
|
26
|
-
-
|
|
27
|
-
-
|
|
28
|
-
-
|
|
29
|
-
-
|
|
30
|
-
-
|
|
31
|
-
-
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
62
|
+
- lib/larb/version.rb
|
|
63
|
+
- test/larb/color_test.rb
|
|
64
|
+
- test/larb/mat2_test.rb
|
|
65
|
+
- test/larb/mat2d_test.rb
|
|
66
|
+
- test/larb/mat3_test.rb
|
|
67
|
+
- test/larb/mat4_test.rb
|
|
68
|
+
- test/larb/quat2_test.rb
|
|
69
|
+
- test/larb/quat_test.rb
|
|
70
|
+
- test/larb/vec2_test.rb
|
|
71
|
+
- test/larb/vec3_test.rb
|
|
72
|
+
- test/larb/vec4_test.rb
|
|
73
|
+
- test/test_helper.rb
|
|
35
74
|
homepage: https://github.com/ydah/larb
|
|
36
75
|
licenses:
|
|
37
76
|
- MIT
|