Skip to content

Commit 51fd49e

Browse files
committed
Make raylib not introduce the operators
1 parent 0c7c3a6 commit 51fd49e

File tree

7 files changed

+185
-4
lines changed

7 files changed

+185
-4
lines changed

examples/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if (NOT raylib_FOUND)
1515
FetchContent_Declare(
1616
raylib
1717
GIT_REPOSITORY https://github.com/raysan5/raylib.git
18-
GIT_TAG d8feef5
18+
GIT_TAG 5e6cdf3
1919
GIT_SHALLOW 1
2020
)
2121
FetchContent_GetProperties(raylib)

include/Vector2.hpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,36 +54,127 @@ class Vector2 : public ::Vector2 {
5454
*/
5555
Vector2 Add(const ::Vector2& vector2) const { return Vector2Add(*this, vector2); }
5656

57+
/**
58+
* Add two vectors (v1 + v2)
59+
*/
60+
Vector2 operator+(const ::Vector2& vector2) const { return Vector2Add(*this, vector2); }
61+
62+
/**
63+
* Add two vectors (v1 + v2)
64+
*/
65+
Vector2& operator+=(const ::Vector2& vector2) {
66+
set(Vector2Add(*this, vector2));
67+
68+
return *this;
69+
}
70+
5771
/**
5872
* Subtract two vectors (v1 - v2)
5973
*/
6074
Vector2 Subtract(const ::Vector2& vector2) const { return Vector2Subtract(*this, vector2); }
6175

76+
/**
77+
* Subtract two vectors (v1 - v2)
78+
*/
79+
Vector2 operator-(const ::Vector2& vector2) const { return Vector2Subtract(*this, vector2); }
80+
81+
/**
82+
* Subtract two vectors (v1 - v2)
83+
*/
84+
Vector2& operator-=(const ::Vector2& vector2) {
85+
set(Vector2Subtract(*this, vector2));
86+
87+
return *this;
88+
}
89+
6290
/**
6391
* Negate vector
6492
*/
6593
Vector2 Negate() const { return Vector2Negate(*this); }
6694

95+
/**
96+
* Negate vector
97+
*/
98+
Vector2 operator-() const { return Vector2Negate(*this); }
99+
67100
/**
68101
* Multiply vector by vector
69102
*/
70103
Vector2 Multiply(const ::Vector2& vector2) const { return Vector2Multiply(*this, vector2); }
71104

105+
/**
106+
* Multiply vector by vector
107+
*/
108+
Vector2 operator*(const ::Vector2& vector2) const { return Vector2Multiply(*this, vector2); }
109+
110+
/**
111+
* Multiply vector by vector
112+
*/
113+
Vector2& operator*=(const ::Vector2& vector2) {
114+
set(Vector2Multiply(*this, vector2));
115+
116+
return *this;
117+
}
118+
72119
/**
73120
* Scale vector (multiply by value)
74121
*/
75122
Vector2 Scale(const float scale) const { return Vector2Scale(*this, scale); }
76123

124+
/**
125+
* Scale vector (multiply by value)
126+
*/
127+
Vector2 operator*(const float scale) const { return Vector2Scale(*this, scale); }
128+
129+
/**
130+
* Scale vector (multiply by value)
131+
*/
132+
Vector2& operator*=(const float scale) {
133+
set(Vector2Scale(*this, scale));
134+
135+
return *this;
136+
}
137+
77138
/**
78139
* Divide vector by vector
79140
*/
80141
Vector2 Divide(const ::Vector2& vector2) const { return Vector2Divide(*this, vector2); }
81142

143+
144+
/**
145+
* Divide vector by vector
146+
*/
147+
Vector2 operator/(const ::Vector2& vector2) const { return Vector2Divide(*this, vector2); }
148+
149+
/**
150+
* Divide vector by vector
151+
*/
152+
Vector2& operator/=(const ::Vector2& vector2) {
153+
set(Vector2Divide(*this, vector2));
154+
155+
return *this;
156+
}
157+
82158
/**
83159
* Divide vector by value
84160
*/
85161
Vector2 Divide(const float div) const { return ::Vector2{x / div, y / div}; }
86162

163+
/**
164+
* Divide vector by value
165+
*/
166+
Vector2 operator/(const float div) const { return Divide(div); }
167+
168+
/**
169+
* Divide vector by value
170+
*/
171+
Vector2& operator/=(const float div) {
172+
this->x /= div;
173+
this->y /= div;
174+
175+
return *this;
176+
}
177+
87178
/**
88179
* Normalize provided vector
89180
*/

include/Vector3.hpp

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,36 +49,123 @@ class Vector3 : public ::Vector3 {
4949
*/
5050
Vector3 Add(const ::Vector3& vector3) const { return Vector3Add(*this, vector3); }
5151

52+
/**
53+
* Add two vectors
54+
*/
55+
Vector3 operator+(const ::Vector3& vector3) const { return Vector3Add(*this, vector3); }
56+
57+
Vector3& operator+=(const ::Vector3& vector3) {
58+
set(Vector3Add(*this, vector3));
59+
60+
return *this;
61+
}
62+
5263
/**
5364
* Subtract two vectors.
5465
*/
5566
Vector3 Subtract(const ::Vector3& vector3) const { return Vector3Subtract(*this, vector3); }
5667

68+
/**
69+
* Subtract two vectors.
70+
*/
71+
Vector3 operator-(const ::Vector3& vector3) const { return Vector3Subtract(*this, vector3); }
72+
73+
Vector3& operator-=(const ::Vector3& vector3) {
74+
set(Vector3Subtract(*this, vector3));
75+
76+
return *this;
77+
}
78+
5779
/**
5880
* Negate provided vector (invert direction)
5981
*/
6082
Vector3 Negate() const { return Vector3Negate(*this); }
6183

84+
/**
85+
* Negate provided vector (invert direction)
86+
*/
87+
Vector3 operator-() const { return Vector3Negate(*this); }
88+
6289
/**
6390
* Multiply vector by vector
6491
*/
6592
Vector3 Multiply(const ::Vector3& vector3) const { return Vector3Multiply(*this, vector3); }
6693

94+
/**
95+
* Multiply vector by vector
96+
*/
97+
Vector3 operator*(const ::Vector3& vector3) const { return Vector3Multiply(*this, vector3); }
98+
99+
/**
100+
* Multiply vector by vector
101+
*/
102+
Vector3& operator*=(const ::Vector3& vector3) {
103+
set(Vector3Multiply(*this, vector3));
104+
105+
return *this;
106+
}
107+
67108
/**
68109
* Multiply vector by scalar
69110
*/
70111
Vector3 Scale(const float scaler) const { return Vector3Scale(*this, scaler); }
71112

113+
/**
114+
* Multiply vector by scalar
115+
*/
116+
Vector3 operator*(const float scaler) const { return Vector3Scale(*this, scaler); }
117+
118+
/**
119+
* Multiply vector by scalar
120+
*/
121+
Vector3& operator*=(const float scaler) {
122+
set(Vector3Scale(*this, scaler));
123+
124+
return *this;
125+
}
126+
72127
/**
73128
* Divide vector by vector
74129
*/
75130
Vector3 Divide(const ::Vector3& vector3) const { return Vector3Divide(*this, vector3); }
76131

132+
/**
133+
* Divide vector by vector
134+
*/
135+
Vector3 operator/(const ::Vector3& vector3) const { return Vector3Divide(*this, vector3); }
136+
137+
/**
138+
* Divide vector by vector
139+
*/
140+
Vector3& operator/=(const ::Vector3& vector3) {
141+
x /= vector3.x;
142+
y /= vector3.y;
143+
z /= vector3.z;
144+
145+
return *this;
146+
}
147+
77148
/**
78149
* Divide a vector by a value.
79150
*/
80151
Vector3 Divide(const float div) const { return ::Vector3{x / div, y / div, z / div}; }
81152

153+
/**
154+
* Divide a vector by a value.
155+
*/
156+
Vector3 operator/(const float div) const { return Divide(div); }
157+
158+
/**
159+
* Divide a vector by a value.
160+
*/
161+
Vector3& operator/=(const float div) {
162+
x /= div;
163+
y /= div;
164+
z /= div;
165+
166+
return *this;
167+
}
168+
82169
/**
83170
* Calculate vector length
84171
*/

include/Vector4.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class Vector4 : public ::Vector4 {
5656
#ifndef RAYLIB_CPP_NO_MATH
5757
Vector4 Multiply(const ::Vector4& vector4) const { return QuaternionMultiply(*this, vector4); }
5858

59+
Vector4 operator*(const ::Vector4& vector4) const { return QuaternionMultiply(*this, vector4); }
60+
5961
Vector4 Lerp(const ::Vector4& vector4, float amount) const { return QuaternionLerp(*this, vector4, amount); }
6062

6163
Vector4 Nlerp(const ::Vector4& vector4, float amount) const { return QuaternionNlerp(*this, vector4, amount); }

include/raymath.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ extern "C" {
1515
#pragma GCC diagnostic push // These throw a warnings on visual studio, need to check if __GNUC__ is defined to use it.
1616
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
1717
#endif
18+
#define RAYMATH_DISABLE_CPP_OPERATORS
1819
#include "raymath.h" // NOLINT
1920
#ifdef __GNUC__
2021
#pragma GCC diagnostic pop

projects/CMake/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if (NOT raylib_FOUND)
88
FetchContent_Declare(
99
raylib
1010
GIT_REPOSITORY https://github.com/raysan5/raylib.git
11-
GIT_TAG d8feef5
11+
GIT_TAG 5e6cdf3
1212
GIT_SHALLOW 1
1313
)
1414
FetchContent_MakeAvailable(raylib)

tests/raylib_cpp_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int main(int argc, char* argv[]) {
6060
{
6161
// Loading
6262
raylib::Image image(path + "/resources/feynman.png");
63-
Assert(image.IsReady());
63+
Assert(image.IsValid());
6464

6565
// Chaining
6666
image.Crop(100, 100).Resize(50, 50);
@@ -108,7 +108,7 @@ int main(int argc, char* argv[]) {
108108
// Wave
109109
{
110110
raylib::Wave wave(path + "/resources/weird.wav");
111-
Assert(wave.IsReady(), "Expected wave to be loaded correctly");
111+
Assert(wave.IsValid(), "Expected wave to be loaded correctly");
112112
}
113113

114114
// RaylibException

0 commit comments

Comments
 (0)