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