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.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +5 -0
- data/.yardopts +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +66 -0
- data/Rakefile +18 -0
- data/TODO.txt +25 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/ext/numerix/common.h +107 -0
- data/ext/numerix/extconf.rb +3 -0
- data/ext/numerix/matrix3x2.c +638 -0
- data/ext/numerix/matrix3x2.h +52 -0
- data/ext/numerix/matrix4x4.c +1807 -0
- data/ext/numerix/matrix4x4.h +90 -0
- data/ext/numerix/matrix_base.c +307 -0
- data/ext/numerix/matrix_base.h +70 -0
- data/ext/numerix/numerix.c +33 -0
- data/ext/numerix/numerix.h +19 -0
- data/ext/numerix/plane.c +311 -0
- data/ext/numerix/plane.h +34 -0
- data/ext/numerix/quaternion.c +712 -0
- data/ext/numerix/quaternion.h +53 -0
- data/ext/numerix/structure.c +154 -0
- data/ext/numerix/structure.h +24 -0
- data/ext/numerix/vector.c +326 -0
- data/ext/numerix/vector.h +57 -0
- data/ext/numerix/vector2.c +641 -0
- data/ext/numerix/vector2.h +64 -0
- data/ext/numerix/vector3.c +805 -0
- data/ext/numerix/vector3.h +68 -0
- data/ext/numerix/vector4.c +727 -0
- data/ext/numerix/vector4.h +63 -0
- data/ext/numerix/vector_base.c +94 -0
- data/ext/numerix/vector_base.h +30 -0
- data/extra/numerix128.png +0 -0
- data/extra/numerix24.png +0 -0
- data/extra/numerix32.png +0 -0
- data/extra/numerix320.png +0 -0
- data/extra/numerix48.png +0 -0
- data/extra/numerix96.png +0 -0
- data/lib/numerix/error.rb +36 -0
- data/lib/numerix/matrix3x2.rb +420 -0
- data/lib/numerix/matrix4x4.rb +676 -0
- data/lib/numerix/matrix_base.rb +14 -0
- data/lib/numerix/plane.rb +154 -0
- data/lib/numerix/quaternion.rb +355 -0
- data/lib/numerix/structure.rb +124 -0
- data/lib/numerix/vector.rb +13 -0
- data/lib/numerix/vector2.rb +534 -0
- data/lib/numerix/vector3.rb +572 -0
- data/lib/numerix/vector4.rb +551 -0
- data/lib/numerix/vector_base.rb +14 -0
- data/lib/numerix/version.rb +6 -0
- data/lib/numerix.rb +10 -0
- data/numerix.gemspec +30 -0
- metadata +167 -0
@@ -0,0 +1,63 @@
|
|
1
|
+
#ifndef NUMERIX_VECTOR4_H
|
2
|
+
#define NUMERIX_VECTOR4_H 1
|
3
|
+
|
4
|
+
#include "common.h"
|
5
|
+
#include "vector_base.h"
|
6
|
+
|
7
|
+
void Init_vector4(VALUE outer);
|
8
|
+
static VALUE rb_vector4_alloc(VALUE klass);
|
9
|
+
VALUE rb_vector4_initialize(int argc, VALUE *argv, VALUE self);
|
10
|
+
|
11
|
+
// Instance
|
12
|
+
VALUE rb_vector4_length(VALUE self);
|
13
|
+
VALUE rb_vector4_length_squared(VALUE self);
|
14
|
+
VALUE rb_vector4_add(VALUE self, VALUE other);
|
15
|
+
VALUE rb_vector4_subtract(VALUE self, VALUE other);
|
16
|
+
VALUE rb_vector4_multiply(VALUE self, VALUE other);
|
17
|
+
VALUE rb_vector4_divide(VALUE self, VALUE other);
|
18
|
+
VALUE rb_vector4_equal(VALUE self, VALUE other);
|
19
|
+
VALUE rb_vector4_negate(VALUE self);
|
20
|
+
VALUE rb_vector4_one_p(VALUE self);
|
21
|
+
VALUE rb_vector4_zero_p(VALUE self);
|
22
|
+
VALUE rb_vector4_min_value(VALUE self);
|
23
|
+
VALUE rb_vector4_max_value(VALUE self);
|
24
|
+
VALUE rb_vector4_distance(VALUE self, VALUE other);
|
25
|
+
VALUE rb_vector4_distance_squared(VALUE self, VALUE other);
|
26
|
+
VALUE rb_vector4_normalize(VALUE self);
|
27
|
+
VALUE rb_vector4_normalize_bang(VALUE self);
|
28
|
+
VALUE rb_vector4_lerp(VALUE self, VALUE other, VALUE amount);
|
29
|
+
VALUE rb_vector4_lerp_bang(VALUE self, VALUE other, VALUE amount);
|
30
|
+
VALUE rb_vector4_transform(VALUE self, VALUE other);
|
31
|
+
VALUE rb_vector4_transform_bang(VALUE self, VALUE other);
|
32
|
+
VALUE rb_vector4_abs(VALUE self);
|
33
|
+
VALUE rb_vector4_sqrt(VALUE self);
|
34
|
+
VALUE rb_vector4_pow(VALUE self, VALUE exponent);
|
35
|
+
VALUE rb_vector4_dot(VALUE self, VALUE other);
|
36
|
+
VALUE rb_vector4_clamp(VALUE self, VALUE min, VALUE max);
|
37
|
+
VALUE rb_vector4_clamp_bang(VALUE self, VALUE min, VALUE max);
|
38
|
+
VALUE rb_vector4_map(VALUE self);
|
39
|
+
VALUE rb_vector4_map_bang(VALUE self);
|
40
|
+
|
41
|
+
// Conversion
|
42
|
+
VALUE rb_vector4_to_s(VALUE self);
|
43
|
+
VALUE rb_vector4_to_a(VALUE self);
|
44
|
+
VALUE rb_vector4_to_h(VALUE self);
|
45
|
+
VALUE rb_vector4_to_vec2(VALUE self);
|
46
|
+
VALUE rb_vector4_to_vec3(VALUE self);
|
47
|
+
VALUE rb_vector4_to_quaternion(VALUE self);
|
48
|
+
VALUE rb_vector4_to_plane(VALUE self);
|
49
|
+
|
50
|
+
// Class
|
51
|
+
VALUE rb_vector4_one(VALUE klass);
|
52
|
+
VALUE rb_vector4_unit_x(VALUE klass);
|
53
|
+
VALUE rb_vector4_unit_y(VALUE klass);
|
54
|
+
VALUE rb_vector4_unit_z(VALUE klass);
|
55
|
+
VALUE rb_vector4_unit_w(VALUE klass);
|
56
|
+
VALUE rb_vector4_create_norm(VALUE klass, VALUE x, VALUE y, VALUE z, VALUE w);
|
57
|
+
static inline VALUE rb_vector4_clamp_s(VALUE klass, VALUE vector, VALUE minimum, VALUE maximum);
|
58
|
+
static inline VALUE rb_vector4_lerp_s(VALUE klass, VALUE vec1, VALUE vec2, VALUE amount);
|
59
|
+
static inline VALUE rb_vector4_transform_s(VALUE klass, VALUE vector, VALUE matrix);
|
60
|
+
static inline VALUE rb_vector4_min_s(VALUE klass, VALUE vec1, VALUE vec2);
|
61
|
+
static inline VALUE rb_vector4_max_s(VALUE klass, VALUE vec1, VALUE vec2);
|
62
|
+
|
63
|
+
#endif /* NUMERIX_VECTOR4_H */
|
@@ -0,0 +1,94 @@
|
|
1
|
+
|
2
|
+
#include "vector_base.h"
|
3
|
+
|
4
|
+
VALUE rb_cVectorBase;
|
5
|
+
VALUE rb_cVector2;
|
6
|
+
VALUE rb_cVector3;
|
7
|
+
VALUE rb_cVector4;
|
8
|
+
VALUE rb_cQuaternion;
|
9
|
+
|
10
|
+
void Init_vector_base(VALUE outer) {
|
11
|
+
rb_cVectorBase = rb_define_class_under(outer, "VectorBase", rb_cNumerixStruct);
|
12
|
+
rb_cVector2 = rb_define_class_under(outer, "Vector2", rb_cVectorBase);
|
13
|
+
rb_cVector3 = rb_define_class_under(outer, "Vector3", rb_cVectorBase);
|
14
|
+
rb_cVector4 = rb_define_class_under(outer, "Vector4", rb_cVectorBase);
|
15
|
+
rb_cQuaternion = rb_define_class_under(outer, "Quaternion", rb_cNumerixStruct);
|
16
|
+
|
17
|
+
rb_define_method(rb_cVectorBase, "initialize", rb_numerix_abstract_initialize, 0);
|
18
|
+
|
19
|
+
rb_define_method(rb_cVector2, "x", rb_vector_base_x, 0);
|
20
|
+
rb_define_method(rb_cVector2, "y", rb_vector_base_y, 0);
|
21
|
+
rb_define_method(rb_cVector2, "x=", rb_vector_base_x_set, 1);
|
22
|
+
rb_define_method(rb_cVector2, "y=", rb_vector_base_y_set, 1);
|
23
|
+
|
24
|
+
rb_define_method(rb_cVector3, "x", rb_vector_base_x, 0);
|
25
|
+
rb_define_method(rb_cVector3, "y", rb_vector_base_y, 0);
|
26
|
+
rb_define_method(rb_cVector3, "z", rb_vector_base_z, 0);
|
27
|
+
rb_define_method(rb_cVector3, "x=", rb_vector_base_x_set, 1);
|
28
|
+
rb_define_method(rb_cVector3, "y=", rb_vector_base_y_set, 1);
|
29
|
+
rb_define_method(rb_cVector3, "z=", rb_vector_base_z_set, 1);
|
30
|
+
|
31
|
+
rb_define_method(rb_cVector4, "x", rb_vector_base_x, 0);
|
32
|
+
rb_define_method(rb_cVector4, "y", rb_vector_base_y, 0);
|
33
|
+
rb_define_method(rb_cVector4, "z", rb_vector_base_z, 0);
|
34
|
+
rb_define_method(rb_cVector4, "w", rb_vector_base_w, 0);
|
35
|
+
rb_define_method(rb_cVector4, "x=", rb_vector_base_x_set, 1);
|
36
|
+
rb_define_method(rb_cVector4, "y=", rb_vector_base_y_set, 1);
|
37
|
+
rb_define_method(rb_cVector4, "z=", rb_vector_base_z_set, 1);
|
38
|
+
rb_define_method(rb_cVector4, "w=", rb_vector_base_w_set, 1);
|
39
|
+
|
40
|
+
rb_define_method(rb_cQuaternion, "x", rb_vector_base_x, 0);
|
41
|
+
rb_define_method(rb_cQuaternion, "y", rb_vector_base_y, 0);
|
42
|
+
rb_define_method(rb_cQuaternion, "z", rb_vector_base_z, 0);
|
43
|
+
rb_define_method(rb_cQuaternion, "w", rb_vector_base_w, 0);
|
44
|
+
rb_define_method(rb_cQuaternion, "x=", rb_vector_base_x_set, 1);
|
45
|
+
rb_define_method(rb_cQuaternion, "y=", rb_vector_base_y_set, 1);
|
46
|
+
rb_define_method(rb_cQuaternion, "z=", rb_vector_base_z_set, 1);
|
47
|
+
rb_define_method(rb_cQuaternion, "w=", rb_vector_base_w_set, 1);
|
48
|
+
|
49
|
+
rb_include_module(rb_cVectorBase, rb_mEnumerable);
|
50
|
+
}
|
51
|
+
|
52
|
+
VALUE rb_vector_base_x(VALUE self) {
|
53
|
+
VECTOR2();
|
54
|
+
return DBL2NUM(v->x);
|
55
|
+
}
|
56
|
+
|
57
|
+
VALUE rb_vector_base_y(VALUE self) {
|
58
|
+
VECTOR2();
|
59
|
+
return DBL2NUM(v->y);
|
60
|
+
}
|
61
|
+
|
62
|
+
VALUE rb_vector_base_z(VALUE self) {
|
63
|
+
VECTOR3();
|
64
|
+
return DBL2NUM(v->z);
|
65
|
+
}
|
66
|
+
|
67
|
+
VALUE rb_vector_base_w(VALUE self) {
|
68
|
+
VECTOR4();
|
69
|
+
return DBL2NUM(v->w);
|
70
|
+
}
|
71
|
+
|
72
|
+
VALUE rb_vector_base_x_set(VALUE self, VALUE value) {
|
73
|
+
VECTOR2();
|
74
|
+
v->x = NUM2FLT(value);
|
75
|
+
return value;
|
76
|
+
}
|
77
|
+
|
78
|
+
VALUE rb_vector_base_y_set(VALUE self, VALUE value) {
|
79
|
+
VECTOR2();
|
80
|
+
v->y = NUM2FLT(value);
|
81
|
+
return value;
|
82
|
+
}
|
83
|
+
|
84
|
+
VALUE rb_vector_base_z_set(VALUE self, VALUE value) {
|
85
|
+
VECTOR3();
|
86
|
+
v->z = NUM2FLT(value);
|
87
|
+
return value;
|
88
|
+
}
|
89
|
+
|
90
|
+
VALUE rb_vector_base_w_set(VALUE self, VALUE value) {
|
91
|
+
VECTOR4();
|
92
|
+
v->w = NUM2FLT(value);
|
93
|
+
return value;
|
94
|
+
}
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#ifndef NUMERIX_VECTOR_BASE_H
|
2
|
+
#define NUMERIX_VECTOR_BASE_H 1
|
3
|
+
|
4
|
+
#include "common.h"
|
5
|
+
|
6
|
+
#define VECTOR2() \
|
7
|
+
Vector2 *v; \
|
8
|
+
Data_Get_Struct(self, Vector2, v)
|
9
|
+
|
10
|
+
#define VECTOR3() \
|
11
|
+
Vector3 *v; \
|
12
|
+
Data_Get_Struct(self, Vector3, v)
|
13
|
+
|
14
|
+
#define VECTOR4() \
|
15
|
+
Vector4 *v; \
|
16
|
+
Data_Get_Struct(self, Vector4, v)
|
17
|
+
|
18
|
+
void Init_vector_base(VALUE outer);
|
19
|
+
|
20
|
+
VALUE rb_vector_base_x(VALUE self);
|
21
|
+
VALUE rb_vector_base_y(VALUE self);
|
22
|
+
VALUE rb_vector_base_z(VALUE self);
|
23
|
+
VALUE rb_vector_base_w(VALUE self);
|
24
|
+
|
25
|
+
VALUE rb_vector_base_x_set(VALUE self, VALUE value);
|
26
|
+
VALUE rb_vector_base_y_set(VALUE self, VALUE value);
|
27
|
+
VALUE rb_vector_base_z_set(VALUE self, VALUE value);
|
28
|
+
VALUE rb_vector_base_w_set(VALUE self, VALUE value);
|
29
|
+
|
30
|
+
#endif /* NUMERIX_VECTOR_BASE_H */
|
Binary file
|
data/extra/numerix24.png
ADDED
Binary file
|
data/extra/numerix32.png
ADDED
Binary file
|
Binary file
|
data/extra/numerix48.png
ADDED
Binary file
|
data/extra/numerix96.png
ADDED
Binary file
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
module Numerix
|
3
|
+
|
4
|
+
##
|
5
|
+
# Size of the internal {Vector2} struct, in bytes.
|
6
|
+
SIZEOF_VECTOR2 = SIZEOF_FLOAT * 2
|
7
|
+
|
8
|
+
##
|
9
|
+
# Size of the internal {Vector3} struct, in bytes.
|
10
|
+
SIZEOF_VECTOR3 = SIZEOF_FLOAT * 3
|
11
|
+
|
12
|
+
##
|
13
|
+
# Size of the internal {Vector4} struct, in bytes.
|
14
|
+
SIZEOF_VECTOR4 = SIZEOF_FLOAT * 4
|
15
|
+
|
16
|
+
##
|
17
|
+
# Size of the internal {Matrix3x2} struct, in bytes.
|
18
|
+
SIZEOF_MATRIX3X2 = SIZEOF_FLOAT * 6
|
19
|
+
|
20
|
+
##
|
21
|
+
# Size of the internal {Matrix4x4} struct, in bytes.
|
22
|
+
SIZEOF_MATRIX4X4 = SIZEOF_FLOAT * 16
|
23
|
+
|
24
|
+
##
|
25
|
+
# Size of the internal {Plane} struct, in bytes.
|
26
|
+
SIZEOF_PLANE = SIZEOF_FLOAT * 4
|
27
|
+
|
28
|
+
##
|
29
|
+
# Size of the internal {Quaternion} struct, in bytes.
|
30
|
+
SIZEOF_QUATERNION = SIZEOF_FLOAT * 4
|
31
|
+
|
32
|
+
##
|
33
|
+
# Exception class for Numerix specific errors.
|
34
|
+
class NumerixError < StandardError
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,420 @@
|
|
1
|
+
module Numerix
|
2
|
+
|
3
|
+
##
|
4
|
+
# A structure encapsulating a 3x2 matrix.
|
5
|
+
class Matrix3x2 < MatrixBase
|
6
|
+
|
7
|
+
##
|
8
|
+
# @return [Float] the first element of the first row.
|
9
|
+
attr_accessor :m11
|
10
|
+
|
11
|
+
##
|
12
|
+
# @return [Float] the second element of the first row.
|
13
|
+
attr_accessor :m12
|
14
|
+
|
15
|
+
##
|
16
|
+
# @return [Float] the first element of the second row.
|
17
|
+
attr_accessor :m21
|
18
|
+
|
19
|
+
##
|
20
|
+
# @return [Float] the second element of the second row.
|
21
|
+
attr_accessor :m22
|
22
|
+
|
23
|
+
##
|
24
|
+
# @return [Float] the first element of the third row.
|
25
|
+
attr_accessor :m31
|
26
|
+
|
27
|
+
##
|
28
|
+
# @return [Float] the second element of the third row.
|
29
|
+
attr_accessor :m32
|
30
|
+
|
31
|
+
##
|
32
|
+
# @return [Vector2] the translation component of this matrix.
|
33
|
+
attr_accessor :translation
|
34
|
+
|
35
|
+
##
|
36
|
+
# @overload initialize
|
37
|
+
# Creates a new matrix with all values set to `0.0`.
|
38
|
+
#
|
39
|
+
# @overload initialize(m11, m12, m21, m22, m31, m32)
|
40
|
+
# Constructs a Matrix3x2 from the given components.
|
41
|
+
#
|
42
|
+
# @param m11 [Float] The first element of the first row.
|
43
|
+
# @param m12 [Float] The second element of the first row.
|
44
|
+
# @param m21 [Float] The first element of the second row.
|
45
|
+
# @param m22 [Float] The second element of the second row.
|
46
|
+
# @param m31 [Float] The first element of the third row.
|
47
|
+
# @param m32 [Float] The second element of the third row.
|
48
|
+
#
|
49
|
+
# @see create_translation
|
50
|
+
# @see create_scale
|
51
|
+
# @see create_skew
|
52
|
+
# @see create_rotation
|
53
|
+
# @see identity
|
54
|
+
def initialize(*args)
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# The equivalent of `Enumerable#map`, but returns a matrix object instead of
|
59
|
+
# an Array.
|
60
|
+
#
|
61
|
+
# Invokes the given block once for each element of `self`.
|
62
|
+
#
|
63
|
+
# Creates a new matrix containing the values returned by the block.
|
64
|
+
#
|
65
|
+
# @yield [component] Yields a component of the matrix to the block.
|
66
|
+
# @yieldparam component [Float] The yielded component.
|
67
|
+
#
|
68
|
+
# @return [Matrix3x2]
|
69
|
+
#
|
70
|
+
# @see map!
|
71
|
+
def map
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
# Invokes the given block once for each element of self, replacing the
|
76
|
+
# element with the value returned by the block.
|
77
|
+
#
|
78
|
+
# The values of the matrix are altered without creating a ne object.
|
79
|
+
#
|
80
|
+
# @yield [component] Yields a component of the matrix to the block.
|
81
|
+
# @yieldparam component [Float] The yielded component.
|
82
|
+
#
|
83
|
+
# @return [self]
|
84
|
+
#
|
85
|
+
# @see map
|
86
|
+
def map!
|
87
|
+
end
|
88
|
+
|
89
|
+
alias_method :collect, :map
|
90
|
+
alias_method :collect!, :map!
|
91
|
+
|
92
|
+
##
|
93
|
+
# Raises the matrix to the given power.
|
94
|
+
#
|
95
|
+
# @param exponent [Float] The power to raise the matrix to.
|
96
|
+
#
|
97
|
+
# @return [Matrix3x2] New matrix that is result of the operation.
|
98
|
+
def **(exponent)
|
99
|
+
end
|
100
|
+
|
101
|
+
##
|
102
|
+
# @return [Boolean] `true` if the matrix is the identity matrix, otherwise
|
103
|
+
# `false`.
|
104
|
+
def identity?
|
105
|
+
end
|
106
|
+
|
107
|
+
##
|
108
|
+
# Calculates the determinant for this matrix.
|
109
|
+
#
|
110
|
+
# The determinant is calculated by expanding the matrix with a third column
|
111
|
+
# whose values are (0,0,1).
|
112
|
+
#
|
113
|
+
# @return [Float] the determinant.
|
114
|
+
def determinant
|
115
|
+
end
|
116
|
+
|
117
|
+
##
|
118
|
+
# Returns the specified matrix row as an array.
|
119
|
+
#
|
120
|
+
# @param index [Integer] The row index to retrieve.
|
121
|
+
#
|
122
|
+
# @return [Array<Float>, nil] the requested row, or `nil` if index is out of
|
123
|
+
# range.
|
124
|
+
#
|
125
|
+
# @see column
|
126
|
+
def row(index)
|
127
|
+
end
|
128
|
+
|
129
|
+
##
|
130
|
+
# Returns the specified matrix column as an array.
|
131
|
+
#
|
132
|
+
# @param index [Integer] The column index to retrieve.
|
133
|
+
#
|
134
|
+
# @return [Array<Float>, nil] the requested column, or `nil` if index is out
|
135
|
+
# of range.
|
136
|
+
#
|
137
|
+
# @see row
|
138
|
+
def column(index)
|
139
|
+
end
|
140
|
+
|
141
|
+
##
|
142
|
+
# Enumerates the rows of the matrix.
|
143
|
+
#
|
144
|
+
# @yield [row] Yields a row to the block.
|
145
|
+
# @yieldparam row [Array<Float>] The current row as an array.
|
146
|
+
#
|
147
|
+
# @return [self]
|
148
|
+
#
|
149
|
+
# see each_column
|
150
|
+
def each_row
|
151
|
+
end
|
152
|
+
|
153
|
+
##
|
154
|
+
# Enumerates the columns of the matrix.
|
155
|
+
#
|
156
|
+
# @yield [column] Yields a column to the block.
|
157
|
+
# @yieldparam column [Array<Float>] The current column as an array.
|
158
|
+
#
|
159
|
+
# @return [self]
|
160
|
+
#
|
161
|
+
# @see each_row
|
162
|
+
def each_column
|
163
|
+
end
|
164
|
+
|
165
|
+
##
|
166
|
+
# Attempts to invert the given matrix.
|
167
|
+
#
|
168
|
+
# @note Some matrices cannot be inverted, in which case the returned matrix
|
169
|
+
# will have all values set to `NaN`.
|
170
|
+
#
|
171
|
+
# @return [Matrix3x2] A new matrix that is this matrix inverted.
|
172
|
+
def invert
|
173
|
+
end
|
174
|
+
|
175
|
+
##
|
176
|
+
# Linearly interpolates from this matrix to another, based on the amount.
|
177
|
+
#
|
178
|
+
# @param matrix [Matrix3x2] The source matrix to interpolate between.
|
179
|
+
# @param amount [Float] The relative weighting of the given matrix, clamped
|
180
|
+
# between `0.0` and `1.0`.
|
181
|
+
#
|
182
|
+
# @return [Matrix3x2] a newly created interpolated matrix.
|
183
|
+
#
|
184
|
+
# @see lerp!
|
185
|
+
def lerp(matrix, amount)
|
186
|
+
end
|
187
|
+
|
188
|
+
##
|
189
|
+
# @note This method is the same as {#lerp}, but alters the values of this
|
190
|
+
# matrix instead of creating a new instance.
|
191
|
+
#
|
192
|
+
# Linearly interpolates from this matrix to another, based on the amount.
|
193
|
+
#
|
194
|
+
# @param matrix [Matrix3x2] The source matrix to interpolate between.
|
195
|
+
# @param amount [Float] The relative weighting of the given matrix, clamped
|
196
|
+
# between `0.0` and `1.0`.
|
197
|
+
#
|
198
|
+
# @return [self]
|
199
|
+
#
|
200
|
+
# @see lerp
|
201
|
+
def lerp!(matrix, amount)
|
202
|
+
end
|
203
|
+
|
204
|
+
##
|
205
|
+
# @return [String] a String representation of this instance.
|
206
|
+
def to_s
|
207
|
+
end
|
208
|
+
|
209
|
+
##
|
210
|
+
# @return [Array<Array<Float>>] an Array representation of this instance.
|
211
|
+
def to_a
|
212
|
+
end
|
213
|
+
|
214
|
+
alias_method :elements, :to_a
|
215
|
+
|
216
|
+
##
|
217
|
+
# @return [Hash{Symbol => Float}] a Hash representation of this instance.
|
218
|
+
def to_h
|
219
|
+
end
|
220
|
+
|
221
|
+
##
|
222
|
+
# Negates the given matrix by multiplying all values by `-1.0`.
|
223
|
+
#
|
224
|
+
# @return [Matrix3x2] the negated matrix.
|
225
|
+
def -@
|
226
|
+
end
|
227
|
+
|
228
|
+
##
|
229
|
+
# Adds each matrix element in value1 with its corresponding element in the
|
230
|
+
# specified matrix.
|
231
|
+
#
|
232
|
+
# @param other [Matrix3x2] The matrix to add.
|
233
|
+
#
|
234
|
+
# @return [Matrix3x2] A matrix containing the summed values.
|
235
|
+
def +(other)
|
236
|
+
end
|
237
|
+
|
238
|
+
##
|
239
|
+
# Subtracts each matrix element in the specified matrix from its
|
240
|
+
# corresponding element in this matrix to form a new matrix of the
|
241
|
+
# difference.
|
242
|
+
#
|
243
|
+
# @param other [Matrix3x2] The matrix to subtract.
|
244
|
+
#
|
245
|
+
# @return [Matrix3x2] The matrix containing the resulting values.
|
246
|
+
def -(other)
|
247
|
+
end
|
248
|
+
|
249
|
+
##
|
250
|
+
# Multiplies this matrix by the specified value.
|
251
|
+
#
|
252
|
+
# @overload *(scalar)
|
253
|
+
# Scales all elements in a matrix by the given scalar factor.
|
254
|
+
#
|
255
|
+
# @param scalar [Float] The scaling value to use.
|
256
|
+
#
|
257
|
+
# @overload *(other)
|
258
|
+
# Multiplies two matrices together and returns the resulting matrix.
|
259
|
+
#
|
260
|
+
# @param other [Matrix3x2] The source matrix to multiply.
|
261
|
+
#
|
262
|
+
# @return [Matrix3x2] the product matrix.
|
263
|
+
def *(other)
|
264
|
+
end
|
265
|
+
|
266
|
+
##
|
267
|
+
# Returns flag if this matrix instance is equal to the given object.
|
268
|
+
#
|
269
|
+
# @param other [Object] The object to compare.
|
270
|
+
#
|
271
|
+
# @return [Boolean] `true` if objects are equal, otherwise `false`.
|
272
|
+
def ==(other)
|
273
|
+
end
|
274
|
+
|
275
|
+
##
|
276
|
+
# Accesses the matrix component using the zero-based row/column indices.
|
277
|
+
#
|
278
|
+
# @param row [Integer] The zero-based row index.
|
279
|
+
# @param column [Integer] The zero-based column index.
|
280
|
+
#
|
281
|
+
# @return [Float, nil] the value at the specified location, or `nil` if an
|
282
|
+
# index is out of range.
|
283
|
+
def [](row, column)
|
284
|
+
end
|
285
|
+
|
286
|
+
##
|
287
|
+
# Sets the matrix component using the zero-based row/column indices.
|
288
|
+
#
|
289
|
+
# @param row [Integer] The zero-based row index.
|
290
|
+
# @param column [Integer] The zero-based column index.
|
291
|
+
# @param value [Float] The value to set.
|
292
|
+
#
|
293
|
+
# @return [Float] the value.
|
294
|
+
def []=(row, column, value)
|
295
|
+
end
|
296
|
+
|
297
|
+
class << self
|
298
|
+
|
299
|
+
##
|
300
|
+
# @return [Matrix3x2] the multiplicative identity matrix.
|
301
|
+
def identity
|
302
|
+
end
|
303
|
+
|
304
|
+
##
|
305
|
+
# Creates a translation matrix.
|
306
|
+
#
|
307
|
+
# @overload create_translation(position)
|
308
|
+
# Creates a translation matrix from the given vector.
|
309
|
+
#
|
310
|
+
# @param position [Vector] The translation position.
|
311
|
+
#
|
312
|
+
# @overload create_translation(x, y)
|
313
|
+
# Creates a translation matrix from the given X and Y components.
|
314
|
+
#
|
315
|
+
# @param x [Float] The X position.
|
316
|
+
# @param y [Float] The Y position.
|
317
|
+
#
|
318
|
+
# @return [Matrix3x2] a translation matrix.
|
319
|
+
def create_translation(other)
|
320
|
+
end
|
321
|
+
|
322
|
+
##
|
323
|
+
# Creates a scale matrix.
|
324
|
+
#
|
325
|
+
# @overload create_scale(x, y)
|
326
|
+
# Creates a scale matrix from the given X and Y components.
|
327
|
+
#
|
328
|
+
# @param x [Float] Value to scale by on the X-axis.
|
329
|
+
# @param y [Float] Value to scale by on the Y-axis.
|
330
|
+
#
|
331
|
+
# @overload create_scale(x, y, center)
|
332
|
+
# Creates a scale matrix that is offset by a given center point.
|
333
|
+
#
|
334
|
+
# @param x [Float] Value to scale by on the X-axis.
|
335
|
+
# @param y [Float] Value to scale by on the Y-axis.
|
336
|
+
# @param center [Vector2] The center point.
|
337
|
+
#
|
338
|
+
# @overload create_scale(scales)
|
339
|
+
# Creates a scale matrix from the given vector scale.
|
340
|
+
#
|
341
|
+
# @param scales [Vector2] The scale to use.
|
342
|
+
#
|
343
|
+
# @overload create_scale(scales, center)
|
344
|
+
# Creates a scale matrix from the given vector scale with an offset from
|
345
|
+
# the given center point.
|
346
|
+
#
|
347
|
+
# @param scales [Vector2] The scale to use.
|
348
|
+
# @param center [Vector2] The center point.
|
349
|
+
#
|
350
|
+
# @overload create_scale(scale)
|
351
|
+
# Creates a scale matrix that scales uniformly with the given scale.
|
352
|
+
#
|
353
|
+
# @param scale [Float] The uniform scale to use.
|
354
|
+
#
|
355
|
+
# @overload create_scale(scale, center)
|
356
|
+
# Creates a scale matrix that scales uniformly with the given scale with
|
357
|
+
# an offset from the given center.
|
358
|
+
#
|
359
|
+
# @param scale [Float] The uniform scale to use.
|
360
|
+
# @param center [Vector2] The center point.
|
361
|
+
#
|
362
|
+
# @return [Matrix3x2] a scaling matrix.
|
363
|
+
def create_scale(*args)
|
364
|
+
end
|
365
|
+
|
366
|
+
##
|
367
|
+
# Creates a skew matrix.
|
368
|
+
#
|
369
|
+
# @overload create_skew(x, y)
|
370
|
+
# Creates a skew matrix from the given angles in radians.
|
371
|
+
#
|
372
|
+
# @param x [Float] The X angle, in radians
|
373
|
+
# @param y [Float] The Y angle, in radians
|
374
|
+
#
|
375
|
+
# @overload create_skew(x, y, center)
|
376
|
+
# Creates a skew matrix from the given angles in radians and a center
|
377
|
+
# point.
|
378
|
+
#
|
379
|
+
# @param x [Float] The X angle, in radians
|
380
|
+
# @param y [Float] The Y angle, in radians
|
381
|
+
# @param center [Vector2] The center point.
|
382
|
+
#
|
383
|
+
# @return [Matrix3x2] a skew matrix.
|
384
|
+
def create_skew(*args)
|
385
|
+
end
|
386
|
+
|
387
|
+
##
|
388
|
+
# Creates a rotation matrix.
|
389
|
+
#
|
390
|
+
# @overload create_rotation(radians)
|
391
|
+
# Creates a rotation matrix using the given rotation in radians.
|
392
|
+
#
|
393
|
+
# @param radians [Float] The amount of rotation, in radians.
|
394
|
+
#
|
395
|
+
# @overload create_rotation(radians, center)
|
396
|
+
# Creates a rotation matrix using the given rotation in radians and a
|
397
|
+
# center point.
|
398
|
+
#
|
399
|
+
# @param radians [Float] The amount of rotation, in radians.
|
400
|
+
# @param center [Vector2] The center point
|
401
|
+
#
|
402
|
+
# @return [Matrix3x2] a rotation matrix.
|
403
|
+
def create_rotation
|
404
|
+
end
|
405
|
+
|
406
|
+
##
|
407
|
+
# Linearly interpolates from _matrix1_ to _matrix2_, based on the third
|
408
|
+
# parameter.
|
409
|
+
#
|
410
|
+
# @param matrix1 [Matrix3x2] The first source matrix.
|
411
|
+
# @param matrix2 [Matrix3x2] The second source matrix.
|
412
|
+
# @param amount [Float] The relative weighting of _matrix2_, clamped
|
413
|
+
# between `0.0` and `1.0`.
|
414
|
+
#
|
415
|
+
# @return [Matrix3x2] the interpolated matrix.
|
416
|
+
def lerp(matrix1, matrix2, amount)
|
417
|
+
end
|
418
|
+
end
|
419
|
+
end
|
420
|
+
end
|