numerix 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.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/.travis.yml +5 -0
  4. data/.yardopts +5 -0
  5. data/CODE_OF_CONDUCT.md +74 -0
  6. data/Gemfile +6 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +66 -0
  9. data/Rakefile +18 -0
  10. data/TODO.txt +25 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/ext/numerix/common.h +107 -0
  14. data/ext/numerix/extconf.rb +3 -0
  15. data/ext/numerix/matrix3x2.c +638 -0
  16. data/ext/numerix/matrix3x2.h +52 -0
  17. data/ext/numerix/matrix4x4.c +1807 -0
  18. data/ext/numerix/matrix4x4.h +90 -0
  19. data/ext/numerix/matrix_base.c +307 -0
  20. data/ext/numerix/matrix_base.h +70 -0
  21. data/ext/numerix/numerix.c +33 -0
  22. data/ext/numerix/numerix.h +19 -0
  23. data/ext/numerix/plane.c +311 -0
  24. data/ext/numerix/plane.h +34 -0
  25. data/ext/numerix/quaternion.c +712 -0
  26. data/ext/numerix/quaternion.h +53 -0
  27. data/ext/numerix/structure.c +154 -0
  28. data/ext/numerix/structure.h +24 -0
  29. data/ext/numerix/vector.c +326 -0
  30. data/ext/numerix/vector.h +57 -0
  31. data/ext/numerix/vector2.c +641 -0
  32. data/ext/numerix/vector2.h +64 -0
  33. data/ext/numerix/vector3.c +805 -0
  34. data/ext/numerix/vector3.h +68 -0
  35. data/ext/numerix/vector4.c +727 -0
  36. data/ext/numerix/vector4.h +63 -0
  37. data/ext/numerix/vector_base.c +94 -0
  38. data/ext/numerix/vector_base.h +30 -0
  39. data/extra/numerix128.png +0 -0
  40. data/extra/numerix24.png +0 -0
  41. data/extra/numerix32.png +0 -0
  42. data/extra/numerix320.png +0 -0
  43. data/extra/numerix48.png +0 -0
  44. data/extra/numerix96.png +0 -0
  45. data/lib/numerix/error.rb +36 -0
  46. data/lib/numerix/matrix3x2.rb +420 -0
  47. data/lib/numerix/matrix4x4.rb +676 -0
  48. data/lib/numerix/matrix_base.rb +14 -0
  49. data/lib/numerix/plane.rb +154 -0
  50. data/lib/numerix/quaternion.rb +355 -0
  51. data/lib/numerix/structure.rb +124 -0
  52. data/lib/numerix/vector.rb +13 -0
  53. data/lib/numerix/vector2.rb +534 -0
  54. data/lib/numerix/vector3.rb +572 -0
  55. data/lib/numerix/vector4.rb +551 -0
  56. data/lib/numerix/vector_base.rb +14 -0
  57. data/lib/numerix/version.rb +6 -0
  58. data/lib/numerix.rb +10 -0
  59. data/numerix.gemspec +30 -0
  60. metadata +167 -0
@@ -0,0 +1,534 @@
1
+ module Numerix
2
+
3
+ ##
4
+ # A structure encapsulating two single precision floating point values.
5
+ class Vector2 < VectorBase
6
+
7
+ ##
8
+ # @return [Float] the X component of the vector.
9
+ attr_accessor :x
10
+
11
+ ##
12
+ # @return [Float] the Y component of the vector.
13
+ attr_accessor :y
14
+
15
+ def initialize(*args) # TODO
16
+ end
17
+
18
+ ##
19
+ # @return [Float] the length of the vector squared.
20
+ def length_squared
21
+ end
22
+
23
+ ##
24
+ # @return [Boolean] flag indicating if all values of the vector are equal
25
+ # to `1.0`.
26
+ def one?
27
+ end
28
+
29
+ ##
30
+ # @return [Boolean] flag indicating if all values of the vector are equal
31
+ # to `0.0`.
32
+ def zero?
33
+ end
34
+
35
+ ##
36
+ # @return [Float] the lowest value of the vector's components.
37
+ def min_value
38
+ end
39
+
40
+ ##
41
+ # @return [Float] the greatest value of the vector's components.
42
+ def max_value
43
+ end
44
+
45
+ ##
46
+ # Returns the Euclidean distance between this vector and another.
47
+ #
48
+ # @param vector [Vector2] The point to get distance between.
49
+ #
50
+ # @return [Float] the distance.
51
+ def distance(vector)
52
+ end
53
+
54
+ # Returns the squared Euclidean distance between this vector and another.
55
+ #
56
+ # @param vector [Vector2] The point to get distance between.
57
+ #
58
+ # @return [Float] the distance squared.
59
+ def distance_squared(vector)
60
+ end
61
+
62
+ ##
63
+ # Returns a new vector with the same direction as the given vector, but with
64
+ # a length of `1.0`.
65
+ #
66
+ # @return [Vector2] a normalized vector.
67
+ def normalize
68
+ end
69
+
70
+ ##
71
+ # Alters this vector instance to maintain same direction, but adjust values
72
+ # so that vector has a length of `1.0`.
73
+ #
74
+ # @return [self]
75
+ def normalize!
76
+ end
77
+
78
+ ##
79
+ # Linearly interpolates between this vector and another based on the given
80
+ # weighting.
81
+ #
82
+ # @param vector [Vector2] The source vector to interpolate between.
83
+ # @param amount [Float] Value between `0.0` and `1.0` indicating the weight
84
+ # of the given vector.
85
+ #
86
+ # @return [Vector2] the interpolated vector.
87
+ #
88
+ # @see lerp!
89
+ def lerp(vector, amount)
90
+ end
91
+
92
+ ##
93
+ # Linearly interpolates between this vector and another based on the given
94
+ # weighting, altering the values of this vector.
95
+ #
96
+ # @param vector [Vector2] The source vector to interpolate between.
97
+ # @param amount [Float] Value between `0.0` and `1.0` indicating the weight
98
+ # of the given vector.
99
+ #
100
+ # @return [self]
101
+ #
102
+ # @see lerp
103
+ def lerp!(vector, amount)
104
+ end
105
+
106
+ ##
107
+ # @return [Vector2] a vector whose elements are the absolute values of each
108
+ # of this vector's elements.
109
+ def abs
110
+ end
111
+
112
+ ##
113
+ # @return [Vector2] a vector whose elements are the square root of each of
114
+ # this vector's elements.
115
+ def sqrt
116
+ end
117
+
118
+ ##
119
+ # Returns the dot product of this vector and another.
120
+ #
121
+ # @param other [Vector2] the source vector to compute dot product of.
122
+ #
123
+ # @return [Float] the dot product.
124
+ def dot(other)
125
+ end
126
+
127
+ ##
128
+ # Returns a vector that is result of clamping this vector between the
129
+ # specified minimum and maximum values.
130
+ #
131
+ # @overload clamp(min, max)
132
+ # Clamps the vector's components between the specified values.
133
+ #
134
+ # @param min [Float] The minimum value.
135
+ # @param max [Float] The maximum value.
136
+ #
137
+ # @overload clamp(min, max)
138
+ # Clamps the vector's on a component-wise basis between the minimum and
139
+ # maximum values of the specified vectors.
140
+ #
141
+ # @param min [Vector2] The minimum value.
142
+ # @param max [Vector2] The maximum value.
143
+ #
144
+ # @return [Vector2] the result of clamping this vector.
145
+ #
146
+ # @see clamp!
147
+ def clamp(min, max)
148
+ end
149
+
150
+ ##
151
+ # Clamps this vector between the specified minimum and maximum values.
152
+ #
153
+ # @overload clamp!(min, max)
154
+ # Clamps the vector's components between the specified values.
155
+ #
156
+ # @param min [Float] The minimum value.
157
+ # @param max [Float] The maximum value.
158
+ #
159
+ # @overload clamp!(min, max)
160
+ # Clamps the vector's on a component-wise basis between the minimum and
161
+ # maximum values of the specified vectors.
162
+ #
163
+ # @param min [Vector2] The minimum value.
164
+ # @param max [Vector2] The maximum value.
165
+ #
166
+ # @return [Vector2]
167
+ #
168
+ # @see clamp
169
+ def clamp!(min, max)
170
+ end
171
+
172
+ ##
173
+ # @return [String] a String representation of this instance.
174
+ def to_s
175
+ end
176
+
177
+ ##
178
+ # @return [Array<Float>] an Array representation of this instance.
179
+ def to_a
180
+ end
181
+
182
+ alias_method :elements, :to_a
183
+
184
+ ##
185
+ # @return [Hash{Symbol => Float}] a Hash representation of this instance.
186
+ def to_h
187
+ end
188
+
189
+ ##
190
+ # @return [Quaternion] a {Quaternion} representation of this instance.
191
+ def to_quaternion
192
+ end
193
+
194
+ ##
195
+ # @return [Plane] a {Plane} representation of this instance.
196
+ def to_plane
197
+ end
198
+
199
+ ##
200
+ # @return [Vector3] a {Vector3} representation of this instance.
201
+ def to_vec3
202
+ end
203
+
204
+ ##
205
+ # @return [Vector4] a {Vector4} representation of this instance.
206
+ def to_vec4
207
+ end
208
+
209
+ ##
210
+ # The equivalent of `Enumerable#map`, but returns a vector object instead of
211
+ # an Array.
212
+ #
213
+ # Invokes the given block once for each element of `self`.
214
+ #
215
+ # Creates a new vector containing the values returned by the block.
216
+ #
217
+ # @yield [component] Yields a component of the vector to the block.
218
+ # @yieldparam component [Float] The yielded component.
219
+ #
220
+ # @return [Vector2]
221
+
222
+ # @see map!
223
+ def map
224
+ end
225
+
226
+ ##
227
+ # Invokes the given block once for each element of self, replacing the
228
+ # element with the value returned by the block.
229
+ #
230
+ # The values of the vector are altered without creating a ne object.
231
+ #
232
+ # @yield [component] Yields a component of the vector to the block.
233
+ # @yieldparam component [Float] The yielded component.
234
+ #
235
+ # @return [self]
236
+ #
237
+ # @see map
238
+ def map!
239
+ end
240
+
241
+ alias_method :collect, :map
242
+ alias_method :collect!, :map!
243
+
244
+ ##
245
+ # Raises the vector to the given power.
246
+ #
247
+ # @param exponent [Float] The power to raise the vector to.
248
+ #
249
+ # @return [Vector2] New vector that is result of the operation.
250
+ def **(exponent)
251
+ end
252
+
253
+ ##
254
+ # Adds this vector with another.
255
+ #
256
+ # @param other [Vector2] The vector to add.
257
+ #
258
+ # @return [Vector2] the sum of the vectors.
259
+ def +(other)
260
+ end
261
+
262
+ ##
263
+ # Gets the difference of this vector and another.
264
+ #
265
+ # @param other [Vector2] The vector to subtract.
266
+ #
267
+ # @return [Vector2] the difference of the vectors.
268
+ def -(other)
269
+ end
270
+
271
+ ##
272
+ # Vector multiplication.
273
+ #
274
+ # @overload *(scalar)
275
+ # Scalar vector multiplication.
276
+ #
277
+ # @param scalar [Float] The scalar value.
278
+ #
279
+ # @overload *(other)
280
+ # Multiplies this vector by another.
281
+ #
282
+ # @param other [Vector2] The source vector to multiply.
283
+ #
284
+ # @return [Vector2] the product vector.
285
+ def *(other)
286
+ end
287
+
288
+ ##
289
+ # Vector division.
290
+ #
291
+ # @overload *(scalar)
292
+ # Scalar vector division.
293
+ #
294
+ # @param scalar [Float] The scalar value.
295
+ #
296
+ # @overload *(other)
297
+ # Divides this vector by another.
298
+ #
299
+ # @param other [Vector2] The source vector to divide.
300
+ #
301
+ # @return [Vector2] the resulting vector.
302
+ def /(other)
303
+ end
304
+
305
+ ##
306
+ # Returns flag if this vector instance is equal to the given object.
307
+ #
308
+ # @param other [Object] The object to compare.
309
+ #
310
+ # @return [Boolean] `true` if objects are equal, otherwise `false`.
311
+ def ==(other)
312
+ end
313
+
314
+ ##
315
+ # Performs unary negation on this vector instance.
316
+ #
317
+ # @return [Vector2] the vector with swapped +/- values.
318
+ def -@
319
+ end
320
+
321
+ ##
322
+ # Alters this vector to be the reflection of the specified normal.
323
+ #
324
+ # @param other [Vector2] The normal of the surface being reflected off.
325
+ #
326
+ # @return [Vector2] a newly created reflected vector.
327
+ def reflect(other)
328
+ end
329
+
330
+ ##
331
+ # Returns the reflection of a vector off a surface that has the specified
332
+ # normal.
333
+ #
334
+ # @param other [Vector2] The normal of the surface being reflected off.
335
+ #
336
+ # @return [self]
337
+ def reflect!(other)
338
+ end
339
+
340
+ ##
341
+ # Computes the angle between this vector and another.
342
+ #
343
+ # @param other [Vector2] The vector to calculate angle from.
344
+ #
345
+ # @return [Float] the angle, in degrees, between the two vectors.
346
+ def angle(other)
347
+ end
348
+
349
+ ##
350
+ # Returns the cross-product between this vector and another.
351
+ #
352
+ # @param other [Vector2] The source vector.
353
+ #
354
+ # @return [Float] the cross product.
355
+ def cross_product(other)
356
+ end
357
+
358
+ ##
359
+ # Returns a new vector by applying a transformation.
360
+ #
361
+ # @overload transform(matrix)
362
+ # Transforms this vector by the given matrix.
363
+ #
364
+ # @param matrix [Matrix4x4] The transformation matrix.
365
+ #
366
+ # @overload transform(matrix)
367
+ # Transforms this vector by the given matrix.
368
+ #
369
+ # @param matrix [Matrix3x2] The transformation matrix.
370
+ #
371
+ # @overload transform(rotation)
372
+ # Transforms this vector by the specified rotation value.
373
+ #
374
+ # @param rotation [Quaternion] The rotation to apply.
375
+ #
376
+ # @return [Vector2] new transformed vector.
377
+ #
378
+ # @see transform!
379
+ def transform(other)
380
+ end
381
+
382
+ ##
383
+ # Transforms this vector by the given matrix.
384
+ #
385
+ # @overload transform(matrix)
386
+ # Transforms this vector by the given matrix.
387
+ #
388
+ # @param matrix [Matrix4x4] The transformation matrix.
389
+ #
390
+ # @overload transform(matrix)
391
+ # Transforms this vector by the given matrix.
392
+ #
393
+ # @param matrix [Matrix3x2] The transformation matrix.
394
+ #
395
+ # @overload transform(rotation)
396
+ # Transforms this vector by the specified rotation value.
397
+ #
398
+ # @param rotation [Quaternion] The rotation to apply.
399
+ #
400
+ # @return [self]
401
+ #
402
+ # @see transform
403
+ def transform!(other)
404
+ end
405
+
406
+ ##
407
+ # Transforms a vector normal by the given matrix.
408
+ #
409
+ # @param matrix [Matrix4x4, Matrix3x2] The transformation matrix.
410
+ #
411
+ # @return [Vector2] new transformed vector.
412
+ def transform_normal(matrix)
413
+ end
414
+
415
+ ##
416
+ # Transforms a vector normal by the given matrix.
417
+ #
418
+ # @param matrix [Matrix4x4, Matrix3x2] The transformation matrix.
419
+ #
420
+ # @return [self]
421
+ def transform_normal!(matrix)
422
+ end
423
+
424
+ class << self
425
+
426
+ ##
427
+ # @return [Vector2] the vector `<0.0, 0.0>`.
428
+ def zero
429
+ end
430
+
431
+ ##
432
+ # @return [Vector2] the vector `<1.0, 1.0>`.
433
+ def one
434
+ end
435
+
436
+ ##
437
+ # @return [Vector2] the vector `<1.0, 0.0>`.
438
+ def unit_x
439
+ end
440
+
441
+ ##
442
+ # @return [Vector2] the vector `<0.0, 1.0>`.
443
+ def unit_y
444
+ end
445
+
446
+ ##
447
+ # Creates and returns a normalized vector from the specified components.
448
+ #
449
+ # This is more efficient than creating and then normalizing.
450
+ #
451
+ # @param x [Float] The X component of the vector.
452
+ # @param y [Float] The Y component of the vector.
453
+ #
454
+ # @return [Vector2] the newly created normalized vector.
455
+ def create_norm(x, y)
456
+ end
457
+
458
+ ##
459
+ # Returns a vector that is result of clamping a vector between the
460
+ # specified minimum and maximum values.
461
+ #
462
+ # @overload clamp(min, max)
463
+ # Clamps the vector's components between the specified values.
464
+ #
465
+ # @param min [Float] The minimum value.
466
+ # @param max [Float] The maximum value.
467
+ #
468
+ # @overload clamp(min, max)
469
+ # Clamps the vector's on a component-wise basis between the minimum and
470
+ # maximum values of the specified vectors.
471
+ #
472
+ # @param min [Vector2] The minimum value.
473
+ # @param max [Vector2] The maximum value.
474
+ #
475
+ # @return [Vector2] the result of clamping this vector.
476
+ def clamp(vector, min, max)
477
+ end
478
+
479
+ ##
480
+ # Linearly interpolates between two vectors based on the given weighting.
481
+ #
482
+ # @param vector1 [Vector2] The first source vector.
483
+ # @param vector2 [Vector2] The second source vector.
484
+ # @param amount [Float] Value between `0.0` and `1.0` indicating the
485
+ # weight of the second source vector.
486
+ #
487
+ # @return [Vector2] the interpolated vector.
488
+ def lerp(vector1, vector2, amount)
489
+ end
490
+
491
+ ##
492
+ # Returns a vector with a minimum set of values.
493
+ #
494
+ # @overload min(vector, other)
495
+ # Returns a vector whose elements are the minimum of each of the pairs
496
+ # of elements in the two source vectors.
497
+ #
498
+ # @param vector [Vector2] The first source vector.
499
+ # @param other [Vector2] The second source vector.
500
+ #
501
+ # @overload min(vector, value)
502
+ # Returns a vector whose elements are the minimum of each of vector
503
+ # element and the specified value.
504
+ #
505
+ # @param vector [Vector2] The source vector.
506
+ # @param value [Float] The minimum value.
507
+ #
508
+ # @return [Vector2] the minimized vector.
509
+ def min(vector, other)
510
+ end
511
+
512
+ ##
513
+ # Returns a vector with a maximum set of values.
514
+ #
515
+ # @overload max(vector, other)
516
+ # Returns a vector whose elements are the maximum of each of the pairs
517
+ # of elements in the two source vectors.
518
+ #
519
+ # @param vector [Vector2] The first source vector.
520
+ # @param other [Vector2] The second source vector.
521
+ #
522
+ # @overload max(vector, value)
523
+ # Returns a vector whose elements are the maximum of each of vector
524
+ # element and the specified value.
525
+ #
526
+ # @param vector [Vector2] The source vector.
527
+ # @param value [Float] The maximum value.
528
+ #
529
+ # @return [Vector2] the maximized vector.
530
+ def max(vector, other)
531
+ end
532
+ end
533
+ end
534
+ end