Skip to content

Commit f027136

Browse files
authored
Merge pull request #384 from penggrin12/many-constexpr
Add `constexpr`s wherever possible without a warning
2 parents 2bcebf1 + fb9a69e commit f027136

9 files changed

Lines changed: 47 additions & 47 deletions

File tree

include/BoundingBox.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class BoundingBox : public ::BoundingBox {
1313
/*
1414
* Copy a bounding box from another bounding box.
1515
*/
16-
BoundingBox(const ::BoundingBox& box) : ::BoundingBox{box.min, box.max} {
16+
constexpr BoundingBox(const ::BoundingBox& box) : ::BoundingBox{box.min, box.max} {
1717
// Nothing.
1818
}
1919

@@ -22,8 +22,8 @@ class BoundingBox : public ::BoundingBox {
2222
*/
2323
BoundingBox(const ::Mesh& mesh) { set(::GetMeshBoundingBox(mesh)); }
2424

25-
BoundingBox(::Vector3 minMax = ::Vector3{0.0f, 0.0f, 0.0f}) : ::BoundingBox{minMax, minMax} {}
26-
BoundingBox(::Vector3 min, ::Vector3 max) : ::BoundingBox{min, max} {}
25+
constexpr BoundingBox(::Vector3 minMax = ::Vector3{0.0f, 0.0f, 0.0f}) : ::BoundingBox{minMax, minMax} {}
26+
constexpr BoundingBox(::Vector3 min, ::Vector3 max) : ::BoundingBox{min, max} {}
2727

2828
GETTERSETTER(::Vector3, Min, min)
2929
GETTERSETTER(::Vector3, Max, max)

include/Color.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ namespace raylib {
1313
*/
1414
class Color : public ::Color {
1515
public:
16-
Color(const ::Color& color) : ::Color{color.r, color.g, color.b, color.a} {}
16+
constexpr Color(const ::Color& color) : ::Color{color.r, color.g, color.b, color.a} {}
1717

18-
Color(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha = 255)
18+
constexpr Color(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha = 255)
1919
: ::Color{red, green, blue, alpha} {};
2020

2121
/**
2222
* Black.
2323
*/
24-
Color() : ::Color{0, 0, 0, 255} {};
24+
constexpr Color() : ::Color{0, 0, 0, 255} {};
2525

2626
/**
2727
* Returns a Color from HSV values

include/Matrix.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ namespace raylib {
1515
*/
1616
class Matrix : public ::Matrix {
1717
public:
18-
Matrix(const ::Matrix& mat)
18+
constexpr Matrix(const ::Matrix& mat)
1919
: ::Matrix(mat) {
2020
// Nothing.
2121
}
2222

23-
Matrix(
23+
constexpr Matrix(
2424
float m0 = 0,
2525
float m4 = 0,
2626
float m8 = 0,
@@ -72,14 +72,14 @@ class Matrix : public ::Matrix {
7272
return *this;
7373
}
7474

75-
bool operator==(const ::Matrix& other) {
75+
constexpr bool operator==(const ::Matrix& other) {
7676
return m0 == other.m0 && m1 == other.m1 && m2 == other.m2 && m3 == other.m3 && m4 == other.m4 &&
7777
m5 == other.m5 && m6 == other.m6 && m7 == other.m7 && m8 == other.m8 && m9 == other.m9 &&
7878
m10 == other.m10 && m11 == other.m11 && m12 == other.m12 && m13 == other.m13 && m14 == other.m14 &&
7979
m15 == other.m15;
8080
}
8181

82-
bool operator!=(const ::Matrix& other) { return !(*this == other); }
82+
constexpr bool operator!=(const ::Matrix& other) { return !(*this == other); }
8383

8484
#ifndef RAYLIB_CPP_NO_MATH
8585
/**

include/Ray.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Ray : public ::Ray {
1313
public:
1414
Ray(const ::Ray& ray) { set(ray); }
1515

16-
Ray(::Vector3 position = {0.0f, 0.0f, 0.0f}, ::Vector3 direction = {0.0f, 0.0f, 0.0f})
16+
constexpr Ray(::Vector3 position = {0.0f, 0.0f, 0.0f}, ::Vector3 direction = {0.0f, 0.0f, 0.0f})
1717
: ::Ray{position, direction} {
1818
// Nothing.
1919
}

include/RayCollision.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class RayCollision : public ::RayCollision {
1212
public:
1313
RayCollision(const ::RayCollision& ray) : ::RayCollision(ray) { }
1414

15-
RayCollision(bool hit, float distance, ::Vector3 point, ::Vector3 normal)
15+
constexpr RayCollision(bool hit, float distance, ::Vector3 point, ::Vector3 normal)
1616
: ::RayCollision{hit, distance, point, normal} {
1717
// Nothing.
1818
}

include/Rectangle.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ namespace raylib {
1111
*/
1212
class Rectangle : public ::Rectangle {
1313
public:
14-
Rectangle(const ::Rectangle& rect) : ::Rectangle{rect.x, rect.y, rect.width, rect.height} {}
14+
constexpr Rectangle(const ::Rectangle& rect) : ::Rectangle{rect.x, rect.y, rect.width, rect.height} {}
1515

16-
Rectangle(float x, float y, float width, float height) : ::Rectangle{x, y, width, height} {}
17-
Rectangle(float x, float y, float width) : ::Rectangle{x, y, width, 0} {}
18-
Rectangle(float x, float y) : ::Rectangle{x, y, 0, 0} {}
19-
Rectangle(float x) : ::Rectangle{x, 0, 0, 0} {}
20-
Rectangle() : ::Rectangle{0, 0, 0, 0} {}
16+
constexpr Rectangle(float x, float y, float width, float height) : ::Rectangle{x, y, width, height} {}
17+
constexpr Rectangle(float x, float y, float width) : ::Rectangle{x, y, width, 0} {}
18+
constexpr Rectangle(float x, float y) : ::Rectangle{x, y, 0, 0} {}
19+
constexpr Rectangle(float x) : ::Rectangle{x, 0, 0, 0} {}
20+
constexpr Rectangle() : ::Rectangle{0, 0, 0, 0} {}
2121

22-
Rectangle(::Vector2 position, ::Vector2 size) : ::Rectangle{position.x, position.y, size.x, size.y} {}
23-
Rectangle(::Vector2 size) : ::Rectangle{0, 0, size.x, size.y} {}
24-
Rectangle(::Vector4 rect) : ::Rectangle{rect.x, rect.y, rect.z, rect.w} {}
22+
constexpr Rectangle(::Vector2 position, ::Vector2 size) : ::Rectangle{position.x, position.y, size.x, size.y} {}
23+
constexpr Rectangle(::Vector2 size) : ::Rectangle{0, 0, size.x, size.y} {}
24+
constexpr Rectangle(::Vector4 rect) : ::Rectangle{rect.x, rect.y, rect.z, rect.w} {}
2525

2626
GETTERSETTER(float, X, x)
2727
GETTERSETTER(float, Y, y)
@@ -33,9 +33,9 @@ class Rectangle : public ::Rectangle {
3333
return *this;
3434
}
3535

36-
::Vector4 ToVector4() { return {x, y, width, height}; }
36+
constexpr ::Vector4 ToVector4() const { return {x, y, width, height}; }
3737

38-
explicit operator ::Vector4() const { return {x, y, width, height}; }
38+
constexpr explicit operator ::Vector4() const { return {x, y, width, height}; }
3939

4040
/**
4141
* Draw a color-filled rectangle

include/Vector2.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ namespace raylib {
1717
*/
1818
class Vector2 : public ::Vector2 {
1919
public:
20-
Vector2(const ::Vector2& vec) : ::Vector2{vec.x, vec.y} {}
20+
constexpr Vector2(const ::Vector2& vec) : ::Vector2{vec.x, vec.y} {}
2121

22-
Vector2(float x, float y) : ::Vector2{x, y} {}
23-
Vector2(float x) : ::Vector2{x, 0} {}
24-
Vector2() : ::Vector2{0, 0} {}
22+
constexpr Vector2(float x, float y) : ::Vector2{x, y} {}
23+
constexpr Vector2(float x) : ::Vector2{x, 0} {}
24+
constexpr Vector2() : ::Vector2{0, 0} {}
2525

2626
GETTERSETTER(float, X, x)
2727
GETTERSETTER(float, Y, y)
@@ -37,12 +37,12 @@ class Vector2 : public ::Vector2 {
3737
/**
3838
* Determine whether or not the vectors are equal.
3939
*/
40-
bool operator==(const ::Vector2& other) const { return x == other.x && y == other.y; }
40+
constexpr bool operator==(const ::Vector2& other) const { return x == other.x && y == other.y; }
4141

4242
/**
4343
* Determines if the vectors are not equal.
4444
*/
45-
bool operator!=(const ::Vector2& other) const { return !(*this == other); }
45+
constexpr bool operator!=(const ::Vector2& other) const { return !(*this == other); }
4646

4747
[[nodiscard]] std::string ToString() const { return TextFormat("Vector2(%f, %f)", x, y); }
4848

include/Vector3.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ namespace raylib {
1717
*/
1818
class Vector3 : public ::Vector3 {
1919
public:
20-
Vector3(const ::Vector3& vec) : ::Vector3{vec.x, vec.y, vec.z} {}
20+
constexpr Vector3(const ::Vector3& vec) : ::Vector3{vec.x, vec.y, vec.z} {}
2121

22-
Vector3(float x, float y, float z) : ::Vector3{x, y, z} {}
23-
Vector3(float x, float y) : ::Vector3{x, y, 0} {}
24-
Vector3(float x) : ::Vector3{x, 0, 0} {}
25-
Vector3() : ::Vector3{0, 0, 0} {}
22+
constexpr Vector3(float x, float y, float z) : ::Vector3{x, y, z} {}
23+
constexpr Vector3(float x, float y) : ::Vector3{x, y, 0} {}
24+
constexpr Vector3(float x) : ::Vector3{x, 0, 0} {}
25+
constexpr Vector3() : ::Vector3{0, 0, 0} {}
2626

2727
Vector3(::Color color) { set(ColorToHSV(color)); }
2828

@@ -35,9 +35,9 @@ class Vector3 : public ::Vector3 {
3535
return *this;
3636
}
3737

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

40-
bool operator!=(const ::Vector3& other) const { return !(*this == other); }
40+
constexpr bool operator!=(const ::Vector3& other) const { return !(*this == other); }
4141

4242
[[nodiscard]] std::string ToString() const { return TextFormat("Vector3(%f, %f, %f)", x, y, z); }
4343

include/Vector4.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ namespace raylib {
1818
*/
1919
class Vector4 : public ::Vector4 {
2020
public:
21-
Vector4(const ::Vector4& vec) : ::Vector4{vec.x, vec.y, vec.z, vec.w} {}
21+
constexpr Vector4(const ::Vector4& vec) : ::Vector4{vec.x, vec.y, vec.z, vec.w} {}
2222

23-
Vector4(float x, float y, float z, float w) : ::Vector4{x, y, z, w} {}
24-
Vector4(float x, float y, float z) : ::Vector4{x, y, z, 0} {}
25-
Vector4(float x, float y) : ::Vector4{x, y, 0, 0} {}
26-
Vector4(float x) : ::Vector4{x, 0, 0, 0} {}
27-
Vector4() : ::Vector4{0, 0, 0, 0} {}
28-
Vector4(::Rectangle rectangle) : ::Vector4{rectangle.x, rectangle.y, rectangle.width, rectangle.height} {}
23+
constexpr Vector4(float x, float y, float z, float w) : ::Vector4{x, y, z, w} {}
24+
constexpr Vector4(float x, float y, float z) : ::Vector4{x, y, z, 0} {}
25+
constexpr Vector4(float x, float y) : ::Vector4{x, y, 0, 0} {}
26+
constexpr Vector4(float x) : ::Vector4{x, 0, 0, 0} {}
27+
constexpr Vector4() : ::Vector4{0, 0, 0, 0} {}
28+
constexpr Vector4(::Rectangle rectangle) : ::Vector4{rectangle.x, rectangle.y, rectangle.width, rectangle.height} {}
2929

3030
Vector4(::Color color) { set(ColorNormalize(color)); }
3131

@@ -39,15 +39,15 @@ class Vector4 : public ::Vector4 {
3939
return *this;
4040
}
4141

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

46-
bool operator!=(const ::Vector4& other) const { return !(*this == other); }
46+
constexpr bool operator!=(const ::Vector4& other) const { return !(*this == other); }
4747

48-
[[nodiscard]] ::Rectangle ToRectangle() const { return {x, y, z, w}; }
48+
[[nodiscard]] constexpr ::Rectangle ToRectangle() const { return {x, y, z, w}; }
4949

50-
operator ::Rectangle() const { return {x, y, z, w}; }
50+
constexpr operator ::Rectangle() const { return {x, y, z, w}; }
5151

5252
[[nodiscard]] std::string ToString() const { return TextFormat("Vector4(%f, %f, %f, %f)", x, y, z, w); }
5353

0 commit comments

Comments
 (0)