Skip to content

Commit 1e8b821

Browse files
authored
Merge pull request #248 from dbrats/vector_constness
Fix const correctness for Vector2, Vector3, and Vector4
2 parents 4fba82c + 9e8b448 commit 1e8b821

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

include/Vector2.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ class Vector2 : public ::Vector2 {
3535
/**
3636
* Determine whether or not the vectors are equal.
3737
*/
38-
bool operator==(const ::Vector2& other) {
38+
bool operator==(const ::Vector2& other) const {
3939
return x == other.x
4040
&& y == other.y;
4141
}
4242

4343
/**
4444
* Determines if the vectors are not equal.
4545
*/
46-
bool operator!=(const ::Vector2& other) {
46+
bool operator!=(const ::Vector2& other) const {
4747
return !(*this == other);
4848
}
4949

@@ -211,7 +211,7 @@ class Vector2 : public ::Vector2 {
211211
/**
212212
* Transforms a Vector2 by a given Matrix
213213
*/
214-
inline Vector2 Transform(::Matrix mat) {
214+
inline Vector2 Transform(::Matrix mat) const {
215215
return ::Vector2Transform(*this, mat);
216216
}
217217

@@ -246,28 +246,28 @@ class Vector2 : public ::Vector2 {
246246
/**
247247
* Invert the given vector
248248
*/
249-
inline Vector2 Invert() {
249+
inline Vector2 Invert() const {
250250
return ::Vector2Invert(*this);
251251
}
252252

253253
/**
254254
* Clamp the components of the vector between
255255
*/
256-
inline Vector2 Clamp(::Vector2 min, ::Vector2 max) {
256+
inline Vector2 Clamp(::Vector2 min, ::Vector2 max) const {
257257
return ::Vector2Clamp(*this, min, max);
258258
}
259259

260260
/**
261261
* // Clamp the magnitude of the vector between two min and max values
262262
*/
263-
inline Vector2 Clamp(float min, float max) {
263+
inline Vector2 Clamp(float min, float max) const {
264264
return ::Vector2ClampValue(*this, min, max);
265265
}
266266

267267
/**
268268
* Check whether two given vectors are almost equal
269269
*/
270-
inline int Equals(::Vector2 q) {
270+
inline int Equals(::Vector2 q) const {
271271
return ::Vector2Equals(*this, q);
272272
}
273273

@@ -302,7 +302,7 @@ class Vector2 : public ::Vector2 {
302302
/**
303303
* Calculate square distance between two vectors
304304
*/
305-
inline float DistanceSqr(::Vector2 v2) {
305+
inline float DistanceSqr(::Vector2 v2) const {
306306
return ::Vector2DistanceSqr(*this, v2);
307307
}
308308

@@ -418,7 +418,7 @@ class Vector2 : public ::Vector2 {
418418
/**
419419
* Check if point belongs to line created between two points [p1] and [p2] with defined margin in pixels [threshold]
420420
*/
421-
inline bool CheckCollisionPointLine(::Vector2 p1, ::Vector2 p2, int threshold = 1) {
421+
inline bool CheckCollisionPointLine(::Vector2 p1, ::Vector2 p2, int threshold = 1) const {
422422
return ::CheckCollisionPointLine(*this, p1, p2, threshold);
423423
}
424424

include/Vector3.hpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,28 @@ class Vector3 : public ::Vector3 {
3535
return *this;
3636
}
3737

38-
bool operator==(const ::Vector3& other) {
38+
bool operator==(const ::Vector3& other) const {
3939
return x == other.x
4040
&& y == other.y
4141
&& z == other.z;
4242
}
4343

44-
bool operator!=(const ::Vector3& other) {
44+
bool operator!=(const ::Vector3& other) const {
4545
return !(*this == other);
4646
}
4747

4848
#ifndef RAYLIB_CPP_NO_MATH
4949
/**
5050
* Add two vectors
5151
*/
52-
inline Vector3 Add(const ::Vector3& vector3) {
52+
inline Vector3 Add(const ::Vector3& vector3) const {
5353
return Vector3Add(*this, vector3);
5454
}
5555

5656
/**
5757
* Add two vectors
5858
*/
59-
inline Vector3 operator+(const ::Vector3& vector3) {
59+
inline Vector3 operator+(const ::Vector3& vector3) const {
6060
return Vector3Add(*this, vector3);
6161
}
6262

@@ -69,14 +69,14 @@ class Vector3 : public ::Vector3 {
6969
/**
7070
* Subtract two vectors.
7171
*/
72-
inline Vector3 Subtract(const ::Vector3& vector3) {
72+
inline Vector3 Subtract(const ::Vector3& vector3) const {
7373
return Vector3Subtract(*this, vector3);
7474
}
7575

7676
/**
7777
* Subtract two vectors.
7878
*/
79-
inline Vector3 operator-(const ::Vector3& vector3) {
79+
inline Vector3 operator-(const ::Vector3& vector3) const {
8080
return Vector3Subtract(*this, vector3);
8181
}
8282

@@ -89,14 +89,14 @@ class Vector3 : public ::Vector3 {
8989
/**
9090
* Negate provided vector (invert direction)
9191
*/
92-
inline Vector3 Negate() {
92+
inline Vector3 Negate() const {
9393
return Vector3Negate(*this);
9494
}
9595

9696
/**
9797
* Negate provided vector (invert direction)
9898
*/
99-
inline Vector3 operator-() {
99+
inline Vector3 operator-() const {
100100
return Vector3Negate(*this);
101101
}
102102

@@ -207,7 +207,7 @@ class Vector3 : public ::Vector3 {
207207
return Vector3Normalize(*this);
208208
}
209209

210-
inline float DotProduct(const ::Vector3& vector3) {
210+
inline float DotProduct(const ::Vector3& vector3) const {
211211
return Vector3DotProduct(*this, vector3);
212212
}
213213

@@ -235,23 +235,23 @@ class Vector3 : public ::Vector3 {
235235
return Vector3Transform(*this, matrix);
236236
}
237237

238-
inline Vector3 RotateByQuaternion(const ::Quaternion& quaternion) {
238+
inline Vector3 RotateByQuaternion(const ::Quaternion& quaternion) const {
239239
return Vector3RotateByQuaternion(*this, quaternion);
240240
}
241241

242242
inline Vector3 Reflect(const ::Vector3& normal) const {
243243
return Vector3Reflect(*this, normal);
244244
}
245245

246-
inline Vector3 Min(const ::Vector3& vector3) {
246+
inline Vector3 Min(const ::Vector3& vector3) const {
247247
return Vector3Min(*this, vector3);
248248
}
249249

250-
inline Vector3 Max(const ::Vector3& vector3) {
250+
inline Vector3 Max(const ::Vector3& vector3) const {
251251
return Vector3Max(*this, vector3);
252252
}
253253

254-
inline Vector3 Barycenter(const ::Vector3& a, const ::Vector3& b, const ::Vector3& c) {
254+
inline Vector3 Barycenter(const ::Vector3& a, const ::Vector3& b, const ::Vector3& c) const {
255255
return Vector3Barycenter(*this, a, b, c);
256256
}
257257

@@ -325,7 +325,7 @@ class Vector3 : public ::Vector3 {
325325
/**
326326
* Detect collision between two spheres
327327
*/
328-
inline bool CheckCollision(float radius1, const ::Vector3& center2, float radius2) {
328+
inline bool CheckCollision(float radius1, const ::Vector3& center2, float radius2) const {
329329
return CheckCollisionSpheres(*this, radius1, center2, radius2);
330330
}
331331

include/Vector4.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ class Vector4 : public ::Vector4 {
3939
return *this;
4040
}
4141

42-
bool operator==(const ::Vector4& other) {
42+
bool operator==(const ::Vector4& other) const {
4343
return x == other.x
4444
&& y == other.y
4545
&& z == other.z
4646
&& w == other.w;
4747
}
4848

49-
bool operator!=(const ::Vector4& other) {
49+
bool operator!=(const ::Vector4& other) const {
5050
return !(*this == other);
5151
}
5252

53-
inline ::Rectangle ToRectangle() {
53+
inline ::Rectangle ToRectangle() const {
5454
return {x, y, z, w};
5555
}
5656

@@ -95,22 +95,22 @@ class Vector4 : public ::Vector4 {
9595
return QuaternionInvert(*this);
9696
}
9797

98-
inline void ToAxisAngle(::Vector3 *outAxis, float *outAngle) {
98+
inline void ToAxisAngle(::Vector3 *outAxis, float *outAngle) const {
9999
QuaternionToAxisAngle(*this, outAxis, outAngle);
100100
}
101101

102102
/**
103103
* Get the rotation angle and axis for a given quaternion
104104
*/
105-
std::pair<Vector3, float> ToAxisAngle() {
105+
std::pair<Vector3, float> ToAxisAngle() const {
106106
Vector3 outAxis;
107107
float outAngle;
108108
QuaternionToAxisAngle(*this, &outAxis, &outAngle);
109109

110110
return std::pair<Vector3, float>(outAxis, outAngle);
111111
}
112112

113-
inline Vector4 Transform(const ::Matrix& matrix) {
113+
inline Vector4 Transform(const ::Matrix& matrix) const {
114114
return ::QuaternionTransform(*this, matrix);
115115
}
116116

@@ -138,7 +138,7 @@ class Vector4 : public ::Vector4 {
138138
return ::QuaternionFromEuler(vector3.x, vector3.y, vector3.z);
139139
}
140140

141-
inline Vector3 ToEuler() {
141+
inline Vector3 ToEuler() const {
142142
return ::QuaternionToEuler(*this);
143143
}
144144
#endif
@@ -147,7 +147,7 @@ class Vector4 : public ::Vector4 {
147147
return ::ColorFromNormalized(*this);
148148
}
149149

150-
operator Color() {
150+
operator Color() const {
151151
return ColorFromNormalized();
152152
}
153153

0 commit comments

Comments
 (0)