@@ -2,7 +2,6 @@ module raylib.raymathext;
2
2
3
3
import raylib;
4
4
import core.stdc.math ;
5
- import std.traits : FieldNameTuple;
6
5
7
6
pragma (inline, true ):
8
7
@@ -15,15 +14,15 @@ struct Bivector2
15
14
enum zero = Bivector2(0.0f );
16
15
enum one = Bivector2(1.0f );
17
16
18
- @safe @nogc nothrow :
17
+ @safe @nogc nothrow pure :
19
18
20
- inout Bivector2 opUnary (string op)() if (op == " +" || op == " -" ) {
19
+ Bivector2 opUnary (string op)() const if (op == " +" || op == " -" ) {
21
20
return Bivector2 (
22
21
mixin (op, " xy" ),
23
22
);
24
23
}
25
24
26
- inout Bivector2 opBinary (string op)(inout Bivector2 rhs) if (op == " +" || op == " -" ) {
25
+ Bivector2 opBinary (string op)(inout Bivector2 rhs) const if (op == " +" || op == " -" ) {
27
26
return Bivector2 (
28
27
mixin (" xy" , op, " rhs.xy" ),
29
28
);
@@ -34,13 +33,13 @@ struct Bivector2
34
33
return this ;
35
34
}
36
35
37
- inout Bivector2 opBinary (string op)(inout float rhs) if (op == " +" || op == " -" || op == " *" || op == " /" ) {
36
+ Bivector2 opBinary (string op)(inout float rhs) const if (op == " +" || op == " -" || op == " *" || op == " /" ) {
38
37
return Bivector2 (
39
38
mixin (" xy" , op, " rhs" ),
40
39
);
41
40
}
42
41
43
- inout Bivector2 opBinaryRight (string op)(inout float lhs) if (op == " +" || op == " -" || op == " *" || op == " /" ) {
42
+ Bivector2 opBinaryRight (string op)(inout float lhs) const if (op == " +" || op == " -" || op == " *" || op == " /" ) {
44
43
return Bivector2 (
45
44
mixin (" lhs" , op, " xy" ),
46
45
);
@@ -64,17 +63,17 @@ struct Bivector3
64
63
enum zero = Bivector3(0.0f , 0.0f , 0.0f );
65
64
enum one = Bivector3(1.0f , 1.0f , 1.0f );
66
65
67
- @safe @nogc nothrow :
66
+ @safe @nogc nothrow pure :
68
67
69
- inout Bivector3 opUnary (string op)() if (op == " +" || op == " -" ) {
68
+ Bivector3 opUnary (string op)() const if (op == " +" || op == " -" ) {
70
69
return Bivector3 (
71
70
mixin (op, " xy" ),
72
71
mixin (op, " yz" ),
73
72
mixin (op, " zx" ),
74
73
);
75
74
}
76
75
77
- inout Bivector3 opBinary (string op)(inout Bivector3 rhs) if (op == " +" || op == " -" ) {
76
+ Bivector3 opBinary (string op)(inout Bivector3 rhs) const if (op == " +" || op == " -" ) {
78
77
return Bivector3 (
79
78
mixin (" xy" , op, " rhs.xy" ),
80
79
mixin (" yz" , op, " rhs.yz" ),
@@ -89,15 +88,15 @@ struct Bivector3
89
88
return this ;
90
89
}
91
90
92
- inout Bivector3 opBinary (string op)(inout float rhs) if (op == " +" || op == " -" || op == " *" || op == " /" ) {
91
+ Bivector3 opBinary (string op)(inout float rhs) const if (op == " +" || op == " -" || op == " *" || op == " /" ) {
93
92
return Bivector3 (
94
93
mixin (" xy" , op, " rhs" ),
95
94
mixin (" yz" , op, " rhs" ),
96
95
mixin (" zx" , op, " rhs" ),
97
96
);
98
97
}
99
98
100
- inout Bivector3 opBinaryRight (string op)(inout float lhs) if (op == " +" || op == " -" || op == " *" || op == " /" ) {
99
+ Bivector3 opBinaryRight (string op)(inout float lhs) const if (op == " +" || op == " -" || op == " *" || op == " /" ) {
101
100
return Bivector3 (
102
101
mixin (" lhs" , op, " xy" ),
103
102
mixin (" lhs" , op, " yz" ),
@@ -128,9 +127,9 @@ struct Rotor3
128
127
alias j = zx;
129
128
alias k = xy;
130
129
131
- @safe @nogc nothrow :
130
+ @safe @nogc nothrow pure :
132
131
133
- @property Bivector3 b()
132
+ @property Bivector3 b() const
134
133
{
135
134
return Bivector3 (xy, yz, zx);
136
135
}
@@ -143,21 +142,23 @@ struct Rotor3
143
142
return _b;
144
143
}
145
144
146
- this (float _a, Bivector3 _b)
145
+ this (float _a, Bivector3 _b) inout
147
146
{
148
147
a = _a;
149
- b = _b;
148
+ xy = _b.xy;
149
+ yz = _b.yz;
150
+ zx = _b.zx;
150
151
}
151
152
152
- this (float _a, float _xy, float _yz, float _zx)
153
+ this (float _a, float _xy, float _yz, float _zx) inout
153
154
{
154
155
a = _a;
155
156
xy = _xy;
156
157
yz = _yz;
157
158
zx = _zx;
158
159
}
159
160
160
- inout Rotor3 opUnary (string op)() if (op == " +" || op == " -" ) {
161
+ Rotor3 opUnary (string op)() const if (op == " +" || op == " -" ) {
161
162
return Rotor3 (
162
163
mixin (op, " a" ),
163
164
mixin (op, " xy" ),
@@ -167,7 +168,7 @@ struct Rotor3
167
168
}
168
169
169
170
// / Returns a rotor equivalent to first apply p, then apply q
170
- inout Rotor3 opBinary (string op)(inout Rotor3 q) if (op == " *" ) {
171
+ Rotor3 opBinary (string op)(inout Rotor3 q) const if (op == " *" ) {
171
172
alias p = this ;
172
173
Rotor3 r;
173
174
r.a = p.a * q.a - p.i * q.i - p.j * q.j - p.k * q.k;
@@ -177,23 +178,23 @@ struct Rotor3
177
178
return r;
178
179
}
179
180
180
- inout Vector3 opBinary (string op)(inout Vector3 v) if (op == " *" ) {
181
+ Vector3 opBinary (string op)(inout Vector3 v) const if (op == " *" ) {
181
182
Vector3 rv;
182
183
rv.x = a * v.x + xy * v.y - zx * v.z;
183
184
rv.y = a * v.y + yz * v.z - xy * v.x;
184
185
rv.z = a * v.z + zx * v.x - yz * v.y;
185
186
return rv;
186
187
}
187
188
188
- inout Vector3 opBinaryRight (string op)(inout Vector3 v) if (op == " *" ) {
189
+ Vector3 opBinaryRight (string op)(inout Vector3 v) const if (op == " *" ) {
189
190
Vector3 vr;
190
191
vr.x = v.x * a - v.y * xy + v.z * zx;
191
192
vr.y = v.y * a - v.z * yz + v.x * xy;
192
193
vr.z = v.z * a - v.x * zx + v.y * yz;
193
194
return vr;
194
195
}
195
196
196
- inout Rotor3 opBinary (string op)(inout float rhs) if (op == " +" || op == " -" || op == " *" || op == " /" ) {
197
+ Rotor3 opBinary (string op)(inout float rhs) const if (op == " +" || op == " -" || op == " *" || op == " /" ) {
197
198
return Rotor3 (
198
199
mixin (" a" , op, " rhs" ),
199
200
mixin (" xy" , op, " rhs" ),
@@ -202,7 +203,7 @@ struct Rotor3
202
203
);
203
204
}
204
205
205
- inout Rotor3 opBinaryRight (string op)(inout float lhs) if (op == " +" || op == " -" || op == " *" || op == " /" ) {
206
+ Rotor3 opBinaryRight (string op)(inout float lhs) const if (op == " +" || op == " -" || op == " *" || op == " /" ) {
206
207
return Rotor3 (
207
208
mixin (" lhs" , op, " a" ),
208
209
mixin (" lhs" , op, " xy" ),
@@ -247,6 +248,7 @@ unittest
247
248
float length (T)(T v)
248
249
{
249
250
enum fragment = () {
251
+ import std.traits : FieldNameTuple;
250
252
string result;
251
253
foreach (string fn; FieldNameTuple! T)
252
254
result ~= fn ~ " *" ~ fn ~ " +" ;
@@ -268,6 +270,7 @@ float distance(T)(T lhs, T rhs)
268
270
float dot (T)(T lhs, T rhs)
269
271
{
270
272
enum fragment = {
273
+ import std.traits : FieldNameTuple;
271
274
string result;
272
275
foreach (fn; FieldNameTuple! T)
273
276
result ~= " lhs." ~ fn ~ " *" ~ " rhs." ~ fn ~ " +" ;
0 commit comments