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,154 @@
1
+ module Numerix
2
+
3
+ ##
4
+ # A structure encapsulating a 3D Plane.
5
+ class Plane < Structure
6
+
7
+ ##
8
+ # @return [Vector3] the normal vector of the plane.
9
+ attr_accessor :normal
10
+
11
+ ##
12
+ # @return [Float] the distance of the plane along its normal from the
13
+ # origin.
14
+ attr_accessor :distance
15
+
16
+ ##
17
+ # @overload initialize
18
+ # Creates a new plane will all values default to `0.0`.
19
+ #
20
+ # @overload initialize(vector)
21
+ # Constructs a Plane from the given Vector4.
22
+ #
23
+ # @param vector [Vector4] A vector whose first 3 elements describe the
24
+ # normal vector, and whose W component defines the distance along that
25
+ # normal from the origin.
26
+ #
27
+ # @overload initialize(normal, distance)
28
+ # Constructs a Plane from the given normal and distance along the normal
29
+ # from the origin.
30
+ #
31
+ # @param normal [Vector3] The normal vector of the plane.
32
+ # @param distance [Float] The distance of the plane along its normal from
33
+ # the origin.
34
+ #
35
+ # @overload initialize(x, y, z, distance)
36
+ # Constructs a plane from the X, Y, and Z components of its normal, and
37
+ # its distance from the origin on that normal.
38
+ #
39
+ # @param x [Float] The normal X component.
40
+ # @param y [Float] The normal Y component.
41
+ # @param z [Float] The normal Z component.
42
+ # @param distance [Float] The distance of the Plane along its normal from
43
+ # the origin.
44
+ def initialize(*args)
45
+ end
46
+
47
+ ##
48
+ # @note This plane must already be normalized, so that its normal vector is
49
+ # of unit length, before this method is called.
50
+ #
51
+ # Applies a transformation to the plane.
52
+ #
53
+ # @overload transform(matrix)
54
+ #
55
+ # Transforms a normalized plane by a matrix.
56
+ #
57
+ # @param matrix [Matrix4x4] The transformation matrix.
58
+ #
59
+ # @return [Plane] the transformed plane.
60
+ #
61
+ # @overload transform(rotation)
62
+ # Transforms a normalized plane by a quaternion rotation.
63
+ #
64
+ # @param rotation [Quaternion] The rotation to apply.
65
+ #
66
+ # @return [Plane] A new plane that results from applying the rotation.
67
+ def transform(other)
68
+ end
69
+
70
+ ##
71
+ # @note This plane must already be normalized, so that its normal vector is
72
+ # of unit length, before this method is called.
73
+ #
74
+ # Applies a transformation to the plane.
75
+ #
76
+ # @overload transform!(matrix)
77
+ #
78
+ # Transforms a normalized plane by a matrix.
79
+ #
80
+ # @param matrix [Matrix4x4] The transformation matrix.
81
+ #
82
+ # @overload transform!(rotation)
83
+ # Transforms a normalized plane by a quaternion rotation.
84
+ #
85
+ # @param rotation [Quaternion] The rotation to apply.
86
+ #
87
+ # @return [self]
88
+ def transform!(other)
89
+ end
90
+
91
+ ##
92
+ # Calculates the dot product of a plane and {Vector4}.
93
+ #
94
+ # @param other [Vector4] The vector to compute.
95
+ #
96
+ # @return [Float] the dot product.
97
+ def dot(other)
98
+ end
99
+
100
+ ##
101
+ # Returns the dot product of a specified {Vector3} and the normal vector of
102
+ # this Plane plus the distance value of the plane.
103
+ #
104
+ # @param other [Vector3] The vector to compute.
105
+ #
106
+ # @return [Float] the dot product.
107
+ def dot_coord(other)
108
+ end
109
+
110
+ ##
111
+ # Returns the dot product of a specified Vector3 and the normal vector of
112
+ # this plane.
113
+ #
114
+ # @param other [Vector3] The vector to compute.
115
+ #
116
+ # @return [Float]
117
+ def dot_norm(other)
118
+ end
119
+
120
+ ##
121
+ # Creates a new plane whose normal vector is the source plane's normal
122
+ # vector normalized.
123
+ #
124
+ # @return [Plane] newly created normalized plane.
125
+ def normalize
126
+ end
127
+
128
+ ##
129
+ # Normalizes this plane's normal vector.
130
+ #
131
+ # @return [self]
132
+ def normalize!
133
+ end
134
+
135
+ ##
136
+ # @return [String] a String representation of this instance.
137
+ def to_s
138
+ end
139
+
140
+ class << self
141
+
142
+ ##
143
+ # Creates a Plane that contains the three given points.
144
+ #
145
+ # @param pnt1 [Vector3] The first point defining the plane.
146
+ # @param pnt2 [Vector3] The second point defining the plane.
147
+ # @param pnt3 [Vector3] The third point defining the plane.
148
+ #
149
+ # @return [Plane] the plane containing the three points.
150
+ def from_vertices(pnt1, pnt2, pnt3)
151
+ end
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,355 @@
1
+ module Numerix
2
+
3
+ ##
4
+ # A structure encapsulating a four-dimensional vector (x,y,z,w), which is used
5
+ # to efficiently rotate an object about the (x,y,z) vector by the angle theta,
6
+ # where `w = cos(theta / 2)`.
7
+ class Quaternion < Structure
8
+
9
+ ##
10
+ # @return [Float] the X-value of the quaternion component of the quaternion.
11
+ attr_accessor :x
12
+
13
+ ##
14
+ # @return [Float] the Y-value of the quaternion component of the quaternion.
15
+ attr_accessor :y
16
+
17
+ ##
18
+ # @return [Float] the Z-value of the quaternion component of the quaternion.
19
+ attr_accessor :z
20
+
21
+ ##
22
+ # @return [Float] the rotation component of the quaternion.
23
+ attr_accessor :w
24
+
25
+ ##
26
+ # @overload initialize
27
+ # Constructs a default quaternion with all components set to `0.0`.
28
+ #
29
+ # @overload initialize(x, y, z, w)
30
+ # Constructs a Quaternion from the given components.
31
+ #
32
+ # @param x [Float] The X component of the quaternion.
33
+ # @param y [Float] The Y component of the quaternion.
34
+ # @param z [Float] The Z component of the quaternion.
35
+ # @param w [Float] The W component of the quaternion.
36
+ #
37
+ # @overload initialize(vector, scalar)
38
+ # Constructs a Quaternion from the given vector and rotation parts.
39
+ #
40
+ # @param vector [Vector3] The vector part of the quaternion.
41
+ # @param scalar [Float] The rotation part of the quaternion.
42
+ #
43
+ def initialize(*args) # TODO
44
+ end
45
+
46
+ ##
47
+ # @return [Boolean] `true` if the quaternion is the identity quaternion,
48
+ # otherwise `false`.
49
+ def identity?
50
+ end
51
+
52
+ ##
53
+ # @return [Float] the length of the quaternion.
54
+ def length
55
+ end
56
+
57
+ alias_method :magnitude, :length
58
+
59
+ ##
60
+ # @return [Float] the length of the quaternion squared.
61
+ def length_squared
62
+ end
63
+
64
+ ##
65
+ # Returns a new quaternion with the same direction as the given quaternion,
66
+ # but with a length of `1.0`.
67
+ #
68
+ # @return [Quaternion] a normalized quaternion.
69
+ def normalize
70
+ end
71
+
72
+ ##
73
+ # Alters this quaternion instance to maintain same direction, but adjust
74
+ # values so that quaternion has a length of `1.0`.
75
+ #
76
+ # @return [self]
77
+ def normalize!
78
+ end
79
+
80
+ ##
81
+ # Creates the conjugate of this quaternion.
82
+ #
83
+ # @return [Quaternion] the conjugate of the os instance.
84
+ #
85
+ # @see conjugate!
86
+ def conjugate
87
+ end
88
+
89
+ ##
90
+ # Alters this instance to be its conjugate.
91
+ #
92
+ # @return [self]
93
+ #
94
+ # @see conjugate
95
+ def conjugate!
96
+ end
97
+
98
+ ##
99
+ # @return [Quaternion] the inverse of this quaternion.
100
+ def inverse
101
+ end
102
+
103
+ ##
104
+ # Calculates the dot product of two quaternions.
105
+ #
106
+ # @param other [Quaternion] The source quaternion to compute product from.
107
+ #
108
+ # @return [Float] the dot product of the quaternions.
109
+ def dot(other)
110
+ end
111
+
112
+ ##
113
+ # Concatenates this quaternion and another, the result represents the this
114
+ # rotation followed by the given quaternion's rotation.
115
+ #
116
+ # @param other [Quaternion] The rotation to add in the series.
117
+ #
118
+ # @return [Quaternion] a new quaternion representing the concatenation this
119
+ # rotation followed by the other rotation.
120
+ #
121
+ # @see concatenate!
122
+ def concatenate(other)
123
+ end
124
+
125
+ ##
126
+ # @note This function is identical to {#concatenate}, but alters the values
127
+ # of this instance without creating a new object.
128
+ #
129
+ # Concatenates this quaternion and another, the result represents the this
130
+ # rotation followed by the given quaternion's rotation.
131
+ #
132
+ # @param other [Quaternion] The rotation to add in the series.
133
+ #
134
+ # @return [self]
135
+ #
136
+ # @see concatenate
137
+ def concatenate!(other)
138
+ end
139
+
140
+ ##
141
+ # Linearly interpolates between this quaternion and another based on the
142
+ # given weighting.
143
+ #
144
+ # @param quaternion [Quaternion] The source quaternion to interpolate
145
+ # between.
146
+ # @param amount [Float] Value between `0.0` and `1.0` indicating the weight
147
+ # of the given quaternion.
148
+ #
149
+ # @return [Quaternion] the interpolated quaternion.
150
+ #
151
+ # @see lerp!
152
+ def lerp(quaternion, amount)
153
+ end
154
+
155
+ ##
156
+ # Linearly interpolates between this quaternion and another based on the given
157
+ # weighting, altering the values of this quaternion.
158
+ #
159
+ # @param quaternion [Quaternion] The source quaternion to interpolate between.
160
+ # @param amount [Float] Value between `0.0` and `1.0` indicating the weight
161
+ # of the given quaternion.
162
+ #
163
+ # @return [self]
164
+ #
165
+ # @see lerp
166
+ def lerp!(quaternion, amount)
167
+ end
168
+
169
+ ##
170
+ # Interpolates between this quaternion and another using spherical linear
171
+ # interpolation.
172
+ #
173
+ # @param quaternion [Quaternion] The source quaternion to interpolate between.
174
+ # @param amount [Float] Value between `0.0` and `1.0` indicating the weight
175
+ # of the given quaternion.
176
+ #
177
+ # @return [Quaternion] the interpolated quaternion.
178
+ #
179
+ # @see slerp!
180
+ def slerp(quaternion, amount)
181
+ end
182
+
183
+ ##
184
+ # @note This function is identical to {#slerp}, but alters the values of
185
+ # this instance without creating a new object.
186
+ #
187
+ # Interpolates between this quaternion and another using spherical linear
188
+ # interpolation.
189
+ #
190
+ # @param quaternion [Quaternion] The source quaternion to interpolate between.
191
+ # @param amount [Float] Value between `0.0` and `1.0` indicating the weight
192
+ # of the given quaternion.
193
+ #
194
+ # @return [self]
195
+ #
196
+ # @see slerp
197
+ def slerp!(quaternion, amount)
198
+ end
199
+
200
+ ##
201
+ # @return [String] a String representation of this instance.
202
+ def to_s
203
+ end
204
+
205
+ ##
206
+ # @return [Array<Float>] an Array representation of this instance.
207
+ def to_a
208
+ end
209
+
210
+ alias_method :elements, :to_a
211
+
212
+ ##
213
+ # @return [Hash{Symbol => Float}] a Hash representation of this instance.
214
+ def to_h
215
+ end
216
+
217
+ ##
218
+ # @return [Vector4] a {Vector4} representation of this instance.
219
+ def to_vec4
220
+ end
221
+
222
+ ##
223
+ # Performs unary negation on this quaternion instance.
224
+ #
225
+ # @return [Quaternion] the vector with swapped +/- values.
226
+ def -@
227
+ end
228
+
229
+ ##
230
+ # Adds this quaternion with another.
231
+ #
232
+ # @param other [Quaternion] The quaternion to add.
233
+ #
234
+ # @return [Quaternion] the sum of the quaternions.
235
+ def +(other)
236
+ end
237
+
238
+ # Gets the difference of this quaternion and another.
239
+ #
240
+ # @param other [Quaternion] The quaternion to subtract.
241
+ #
242
+ # @return [Quaternion] the difference of the quaternions.
243
+ def -(other)
244
+ end
245
+
246
+ ##
247
+ # Quaternion multiplication.
248
+ #
249
+ # @overload *(scalar)
250
+ # Scalar quaternion multiplication.
251
+ #
252
+ # @param scalar [Float] The scalar value.
253
+ #
254
+ # @overload *(other)
255
+ # Multiplies this quaternion by another.
256
+ #
257
+ # @param other [Quaternion] The source quaternion to multiply.
258
+ #
259
+ # @return [Quaternion] the product quaternion.
260
+ def *(other)
261
+ end
262
+
263
+ ##
264
+ # Quaternion division.
265
+ #
266
+ # @overload *(scalar)
267
+ # Scalar quaternion division.
268
+ #
269
+ # @param scalar [Float] The scalar value.
270
+ #
271
+ # @overload *(other)
272
+ # Divides this quaternion by another.
273
+ #
274
+ # @param other [Quaternion] The source quaternion to divide.
275
+ #
276
+ # @return [Quaternion] the resulting quaternion.
277
+ def /(other)
278
+ end
279
+
280
+ ##
281
+ # Returns flag if this quaternion instance is equal to the given object.
282
+ #
283
+ # @param other [Object] The object to compare.
284
+ #
285
+ # @return [Boolean] `true` if objects are equal, otherwise `false`.
286
+ def ==(other)
287
+ end
288
+
289
+ class << self
290
+
291
+ ##
292
+ # @return [Quaternion] a quaternion representing no rotation.
293
+ def identity
294
+ end
295
+
296
+ ##
297
+ # Creates a quaternion from a vector and an angle to rotate about the
298
+ # vector.
299
+ #
300
+ # @param axis [Vector3] The vector to rotate around.
301
+ # @param angle [Float] The angle, in radians, to rotate around the vector.
302
+ #
303
+ # @return [Quaternion] the created quaternion.
304
+ def from_axis_angle(axis, angle)
305
+ end
306
+
307
+ ##
308
+ # Creates a new quaternion from the given yaw, pitch, and roll, in
309
+ # radians.
310
+ #
311
+ # @param yaw [Float] The yaw angle, in radians, around the Y-axis.
312
+ # @param pitch [Float] The pitch angle, in radians, around the X-axis.
313
+ # @param roll [Float] The roll angle, in radians, around the Z-axis.
314
+ #
315
+ # @return [Quaternion] the created quaternion.
316
+ def from_yaw_pitch_roll(yaw, pitch, roll)
317
+ end
318
+
319
+ ##
320
+ # Creates a quaternion from the given rotation matrix.
321
+ #
322
+ # @param matrix [Matrix4x4] The rotation matrix
323
+ #
324
+ # @return [Quaternion] the created quaternion.
325
+ def from_rotation_matrix(matrix)
326
+ end
327
+
328
+ ##
329
+ # Interpolates between two quaternions, using spherical linear
330
+ # interpolation.
331
+ #
332
+ # @param quaternion1 [Quaternion] The first source quaternion.
333
+ # @param quaternion2 [Quaternion] The second source quaternion.
334
+ # @param amount [Float] Value between `0.0` and `1.0` indicating the
335
+ # weight of the second source quaternion.
336
+ #
337
+ # @return [Quaternion] the interpolated quaternion.
338
+ def slerp(quaternion1, quaternion2, amount)
339
+ end
340
+
341
+ ##
342
+ # Linearly interpolates between two quaternions based on the given
343
+ # weighting.
344
+ #
345
+ # @param quaternion1 [Quaternion] The first source quaternion.
346
+ # @param quaternion2 [Quaternion] The second source quaternion.
347
+ # @param amount [Float] Value between `0.0` and `1.0` indicating the
348
+ # weight of the second source quaternion.
349
+ #
350
+ # @return [Quaternion] the interpolated quaternion.
351
+ def lerp(quaternion1, quaternion2, amount)
352
+ end
353
+ end
354
+ end
355
+ end
@@ -0,0 +1,124 @@
1
+
2
+ module Numerix
3
+
4
+ ##
5
+ # @abstract Abstract class providing common functionality to the base classes.
6
+ #
7
+ # This class cannot be instantiated, it of only for providing a common base
8
+ # class for all Numerix types and provide common functionality.
9
+ class Structure
10
+
11
+ private_class_method :new
12
+
13
+ ##
14
+ # @return [Object] an exact duplicate of the object.
15
+ def dup
16
+ end
17
+
18
+ ##
19
+ # @return [Integer] the address of the internal C-struct in memory.
20
+ def address
21
+ end
22
+
23
+ ##
24
+ # Enumerates over the components of the structure.
25
+ #
26
+ # @overload each
27
+ # When called with a block, enumerates through each component of the
28
+ # structure, yielding each before returning self;
29
+ #
30
+ # @yield [component] Yields a component to the block.
31
+ # @yieldparam component [Float] The current component.
32
+ #
33
+ # @return [self]
34
+ #
35
+ # @overload each
36
+ #
37
+ # When called without a block, returned an Enumerator for the structure.
38
+ #
39
+ # @return [Enumerator] the enumerator for the structure.
40
+ def each
41
+ end
42
+
43
+ ##
44
+ # Retrieves the component of the structure at the specified position.
45
+ #
46
+ # @param index [Integer] The position of the component to retrieve.
47
+ #
48
+ # @return [Float, nil] the value at the given position, or +nil+ if _index_
49
+ # is out of range.
50
+ #
51
+ # @see []=
52
+ def [](index)
53
+ end
54
+
55
+ ##
56
+ # Sets the component of the structure at the specified position.
57
+ #
58
+ # If _index_ is out of range, the method does nothing.
59
+ #
60
+ # @param index [Integer] The position of the component to set.
61
+ # @param value [Float] The value to set.
62
+ #
63
+ # @return [Float] the value
64
+ #
65
+ # @see []
66
+ def []=(index, value)
67
+ end
68
+
69
+ ##
70
+ # Packs the structures memory into a binary string.
71
+ #
72
+ # This is the equivalent of taking its values into an array and calling
73
+ # `array.pack('f*')` on it, though considerably faster as the parser is
74
+ # bypassed and done directly in C by accessing the memory directly.
75
+ #
76
+ # @return [String] the packed binary string.
77
+ #
78
+ # @see pack
79
+ def pack
80
+ end
81
+
82
+ alias_method :_dump, :pack
83
+
84
+ if RUBY_VERSION >= '2.0'
85
+
86
+ require 'fiddle'
87
+
88
+ ##
89
+ # @note This method only exists in Ruby 2.0 and higher, and will not be
90
+ # present in lower versions.
91
+ #
92
+ # @return [Fiddle::Pointer] a sized pointer to the structure in memory.
93
+ #
94
+ # @see address
95
+ def ptr
96
+ end
97
+ end
98
+
99
+ class << self
100
+
101
+ ##
102
+ # @return [Integer] the size, in bytes, the structure contains in memory.
103
+ def size
104
+ end
105
+
106
+ ##
107
+ # Unpacks a binary string of data into a structure.
108
+ #
109
+ # This is the equivalent of calling `binary.unpack('f*')` on the string
110
+ # and using the values to create a new structure, but much faster as it
111
+ # bypasses the parser and is done in C directly with a pointer in memory.
112
+ #
113
+ # @param binary [String] Binary string of data.
114
+ #
115
+ # @return [Object] the unpacked structure.
116
+ #
117
+ # @see pack
118
+ def unpack(binary)
119
+ end
120
+
121
+ alias_method :_load, :unpack
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,13 @@
1
+
2
+ module Numerix
3
+
4
+ ##
5
+ # Analog of Ruby's standard library `Vector` class implemented in `C`.
6
+ #
7
+ # @note This class is not fully implemented integrated into the "core"
8
+ # Numerix classes as of version `1.0.0`. This will likely change in future
9
+ # releases.
10
+ class Vector
11
+ # @todo Document
12
+ end
13
+ end