Skip to content

Commit 1cc76b8

Browse files
authored
Merge pull request #65 from schveiguy/fixctorattrs
Attribute and various fixes
2 parents 1381ca2 + 3d29cd9 commit 1cc76b8

File tree

2 files changed

+48
-45
lines changed

2 files changed

+48
-45
lines changed

source/raylib/raylib_types.d

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ struct Vector2
1212
enum zero = Vector2(0.0f, 0.0f);
1313
enum one = Vector2(1.0f, 1.0f);
1414

15-
@safe @nogc nothrow:
15+
@safe @nogc nothrow pure:
1616

17-
inout Vector2 opUnary(string op)() if (op == "+" || op == "-") {
17+
Vector2 opUnary(string op)() const if (op == "+" || op == "-") {
1818
return Vector2(
1919
mixin(op, "x"),
2020
mixin(op, "y"),
2121
);
2222
}
2323

24-
inout Vector2 opBinary(string op)(inout Vector2 rhs) if (op == "+" || op == "-") {
24+
Vector2 opBinary(string op)(inout Vector2 rhs) const if (op == "+" || op == "-") {
2525
return Vector2(
2626
mixin("x", op, "rhs.x"),
2727
mixin("y", op, "rhs.y"),
@@ -34,14 +34,14 @@ struct Vector2
3434
return this;
3535
}
3636

37-
inout Vector2 opBinary(string op)(inout float rhs) if (op == "+" || op == "-" || op == "*" || op == "/") {
37+
Vector2 opBinary(string op)(inout float rhs) const if (op == "+" || op == "-" || op == "*" || op == "/") {
3838
return Vector2(
3939
mixin("x", op, "rhs"),
4040
mixin("y", op, "rhs"),
4141
);
4242
}
4343

44-
inout Vector2 opBinaryRight(string op)(inout float lhs) if (op == "+" || op == "-" || op == "*" || op == "/") {
44+
Vector2 opBinaryRight(string op)(inout float lhs) const if (op == "+" || op == "-" || op == "*" || op == "/") {
4545
return Vector2(
4646
mixin("lhs", op, "x"),
4747
mixin("lhs", op, "y"),
@@ -65,17 +65,17 @@ struct Vector3
6565
enum zero = Vector3(0.0f, 0.0f, 0.0f);
6666
enum one = Vector3(1.0f, 1.0f, 1.0f);
6767

68-
@safe @nogc nothrow:
68+
@safe @nogc nothrow pure:
6969

70-
inout Vector3 opUnary(string op)() if (op == "+" || op == "-") {
70+
Vector3 opUnary(string op)() const if (op == "+" || op == "-") {
7171
return Vector3(
7272
mixin(op, "x"),
7373
mixin(op, "y"),
7474
mixin(op, "z"),
7575
);
7676
}
7777

78-
inout Vector3 opBinary(string op)(inout Vector3 rhs) if (op == "+" || op == "-") {
78+
Vector3 opBinary(string op)(inout Vector3 rhs) const if (op == "+" || op == "-") {
7979
return Vector3(
8080
mixin("x", op, "rhs.x"),
8181
mixin("y", op, "rhs.y"),
@@ -90,15 +90,15 @@ struct Vector3
9090
return this;
9191
}
9292

93-
inout Vector3 opBinary(string op)(inout float rhs) if (op == "+" || op == "-" || op == "*" || op == "/") {
93+
Vector3 opBinary(string op)(inout float rhs) const if (op == "+" || op == "-" || op == "*" || op == "/") {
9494
return Vector3(
9595
mixin("x", op, "rhs"),
9696
mixin("y", op, "rhs"),
9797
mixin("z", op, "rhs"),
9898
);
9999
}
100100

101-
inout Vector3 opBinaryRight(string op)(inout float lhs) if (op == "+" || op == "-" || op == "*" || op == "/") {
101+
Vector3 opBinaryRight(string op)(inout float lhs) const if (op == "+" || op == "-" || op == "*" || op == "/") {
102102
return Vector3(
103103
mixin("lhs", op, "x"),
104104
mixin("lhs", op, "y"),
@@ -125,9 +125,9 @@ struct Vector4
125125
enum zero = Vector4(0.0f, 0.0f, 0.0f, 0.0f);
126126
enum one = Vector4(1.0f, 1.0f, 1.0f, 1.0f);
127127

128-
@safe @nogc nothrow:
128+
@safe @nogc nothrow pure:
129129

130-
inout Vector4 opUnary(string op)() if (op == "+" || op == "-") {
130+
Vector4 opUnary(string op)() const if (op == "+" || op == "-") {
131131
return Vector4(
132132
mixin(op, "x"),
133133
mixin(op, "y"),
@@ -136,7 +136,7 @@ struct Vector4
136136
);
137137
}
138138

139-
inout Vector4 opBinary(string op)(inout Vector4 rhs) if (op == "+" || op == "-") {
139+
Vector4 opBinary(string op)(inout Vector4 rhs) const if (op == "+" || op == "-") {
140140
return Vector4(
141141
mixin("x", op, "rhs.x"),
142142
mixin("y", op, "rhs.y"),
@@ -153,7 +153,7 @@ struct Vector4
153153
return this;
154154
}
155155

156-
inout Vector4 opBinary(string op)(inout float rhs) if (op == "+" || op == "-" || op == "*" || op == "/") {
156+
Vector4 opBinary(string op)(inout float rhs) const if (op == "+" || op == "-" || op == "*" || op == "/") {
157157
return Vector4(
158158
mixin("x", op, "rhs"),
159159
mixin("y", op, "rhs"),
@@ -162,7 +162,7 @@ struct Vector4
162162
);
163163
}
164164

165-
inout Vector4 opBinaryRight(string op)(inout float lhs) if (op == "+" || op == "-" || op == "*" || op == "/") {
165+
Vector4 opBinaryRight(string op)(inout float lhs) const if (op == "+" || op == "-" || op == "*" || op == "/") {
166166
return Vector4(
167167
mixin("lhs", op, "x"),
168168
mixin("lhs", op, "y"),
@@ -214,14 +214,14 @@ struct Rectangle
214214
alias w = width;
215215
alias h = height;
216216

217-
@safe @nogc nothrow:
217+
@safe @nogc nothrow pure:
218218

219-
Vector2 origin() { // Rectangle function exclusive to raylib-d
219+
Vector2 origin() const { // Rectangle function exclusive to raylib-d
220220
return Vector2(x, y);
221221
}
222222
alias position = origin;
223223

224-
Vector2 dimensions() {
224+
Vector2 dimensions() const {
225225
return Vector2(width, height);
226226
}
227227

@@ -262,22 +262,22 @@ struct Color
262262
ubyte r;
263263
ubyte g;
264264
ubyte b;
265-
ubyte a = 255;
265+
ubyte a;
266266

267-
@safe @nogc nothrow:
267+
@safe @nogc nothrow pure:
268268

269-
this(ubyte r, ubyte g, ubyte b, ubyte a = 255) {
269+
this(ubyte r, ubyte g, ubyte b, ubyte a = 255) inout {
270270
this.r = r;
271271
this.g = g;
272272
this.b = b;
273273
this.a = a;
274274
}
275275

276-
this(ubyte[4] rgba) {
276+
this(ubyte[4] rgba) inout {
277277
this(rgba[0], rgba[1], rgba[2], rgba[3]);
278278
}
279279

280-
this(ubyte[3] rgb) {
280+
this(ubyte[3] rgb) inout {
281281
this(rgb[0], rgb[1], rgb[2], 255);
282282
}
283283
}

source/raylib/raymathext.d

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module raylib.raymathext;
22

33
import raylib;
44
import core.stdc.math;
5-
import std.traits : FieldNameTuple;
65

76
pragma(inline, true):
87

@@ -15,15 +14,15 @@ struct Bivector2
1514
enum zero = Bivector2(0.0f);
1615
enum one = Bivector2(1.0f);
1716

18-
@safe @nogc nothrow:
17+
@safe @nogc nothrow pure:
1918

20-
inout Bivector2 opUnary(string op)() if (op == "+" || op == "-") {
19+
Bivector2 opUnary(string op)() const if (op == "+" || op == "-") {
2120
return Bivector2(
2221
mixin(op, "xy"),
2322
);
2423
}
2524

26-
inout Bivector2 opBinary(string op)(inout Bivector2 rhs) if (op == "+" || op == "-") {
25+
Bivector2 opBinary(string op)(inout Bivector2 rhs) const if (op == "+" || op == "-") {
2726
return Bivector2(
2827
mixin("xy", op, "rhs.xy"),
2928
);
@@ -34,13 +33,13 @@ struct Bivector2
3433
return this;
3534
}
3635

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 == "/") {
3837
return Bivector2(
3938
mixin("xy", op, "rhs"),
4039
);
4140
}
4241

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 == "/") {
4443
return Bivector2(
4544
mixin("lhs", op, "xy"),
4645
);
@@ -64,17 +63,17 @@ struct Bivector3
6463
enum zero = Bivector3(0.0f, 0.0f, 0.0f);
6564
enum one = Bivector3(1.0f, 1.0f, 1.0f);
6665

67-
@safe @nogc nothrow:
66+
@safe @nogc nothrow pure:
6867

69-
inout Bivector3 opUnary(string op)() if (op == "+" || op == "-") {
68+
Bivector3 opUnary(string op)() const if (op == "+" || op == "-") {
7069
return Bivector3(
7170
mixin(op, "xy"),
7271
mixin(op, "yz"),
7372
mixin(op, "zx"),
7473
);
7574
}
7675

77-
inout Bivector3 opBinary(string op)(inout Bivector3 rhs) if (op == "+" || op == "-") {
76+
Bivector3 opBinary(string op)(inout Bivector3 rhs) const if (op == "+" || op == "-") {
7877
return Bivector3(
7978
mixin("xy", op, "rhs.xy"),
8079
mixin("yz", op, "rhs.yz"),
@@ -89,15 +88,15 @@ struct Bivector3
8988
return this;
9089
}
9190

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 == "/") {
9392
return Bivector3(
9493
mixin("xy", op, "rhs"),
9594
mixin("yz", op, "rhs"),
9695
mixin("zx", op, "rhs"),
9796
);
9897
}
9998

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 == "/") {
101100
return Bivector3(
102101
mixin("lhs", op, "xy"),
103102
mixin("lhs", op, "yz"),
@@ -128,9 +127,9 @@ struct Rotor3
128127
alias j = zx;
129128
alias k = xy;
130129

131-
@safe @nogc nothrow:
130+
@safe @nogc nothrow pure:
132131

133-
@property Bivector3 b()
132+
@property Bivector3 b() const
134133
{
135134
return Bivector3(xy, yz, zx);
136135
}
@@ -143,21 +142,23 @@ struct Rotor3
143142
return _b;
144143
}
145144

146-
this(float _a, Bivector3 _b)
145+
this(float _a, Bivector3 _b) inout
147146
{
148147
a = _a;
149-
b = _b;
148+
xy = _b.xy;
149+
yz = _b.yz;
150+
zx = _b.zx;
150151
}
151152

152-
this(float _a, float _xy, float _yz, float _zx)
153+
this(float _a, float _xy, float _yz, float _zx) inout
153154
{
154155
a = _a;
155156
xy = _xy;
156157
yz = _yz;
157158
zx = _zx;
158159
}
159160

160-
inout Rotor3 opUnary(string op)() if (op == "+" || op == "-") {
161+
Rotor3 opUnary(string op)() const if (op == "+" || op == "-") {
161162
return Rotor3(
162163
mixin(op, "a"),
163164
mixin(op, "xy"),
@@ -167,7 +168,7 @@ struct Rotor3
167168
}
168169

169170
/// 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 == "*") {
171172
alias p = this;
172173
Rotor3 r;
173174
r.a = p.a * q.a - p.i * q.i - p.j * q.j - p.k * q.k;
@@ -177,23 +178,23 @@ struct Rotor3
177178
return r;
178179
}
179180

180-
inout Vector3 opBinary(string op)(inout Vector3 v) if (op == "*") {
181+
Vector3 opBinary(string op)(inout Vector3 v) const if (op == "*") {
181182
Vector3 rv;
182183
rv.x = a * v.x + xy * v.y - zx * v.z;
183184
rv.y = a * v.y + yz * v.z - xy * v.x;
184185
rv.z = a * v.z + zx * v.x - yz * v.y;
185186
return rv;
186187
}
187188

188-
inout Vector3 opBinaryRight(string op)(inout Vector3 v) if (op == "*") {
189+
Vector3 opBinaryRight(string op)(inout Vector3 v) const if (op == "*") {
189190
Vector3 vr;
190191
vr.x = v.x * a - v.y * xy + v.z * zx;
191192
vr.y = v.y * a - v.z * yz + v.x * xy;
192193
vr.z = v.z * a - v.x * zx + v.y * yz;
193194
return vr;
194195
}
195196

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 == "/") {
197198
return Rotor3(
198199
mixin("a", op, "rhs"),
199200
mixin("xy", op, "rhs"),
@@ -202,7 +203,7 @@ struct Rotor3
202203
);
203204
}
204205

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 == "/") {
206207
return Rotor3(
207208
mixin("lhs", op, "a"),
208209
mixin("lhs", op, "xy"),
@@ -247,6 +248,7 @@ unittest
247248
float length(T)(T v)
248249
{
249250
enum fragment = () {
251+
import std.traits : FieldNameTuple;
250252
string result;
251253
foreach(string fn; FieldNameTuple!T)
252254
result ~= fn ~ "*" ~ fn ~ "+";
@@ -268,6 +270,7 @@ float distance(T)(T lhs, T rhs)
268270
float dot(T)(T lhs, T rhs)
269271
{
270272
enum fragment = {
273+
import std.traits : FieldNameTuple;
271274
string result;
272275
foreach(fn; FieldNameTuple!T)
273276
result ~= "lhs." ~ fn ~ "*" ~ "rhs." ~ fn ~ "+";

0 commit comments

Comments
 (0)