diff --git a/src/base/color.h b/src/base/color.h index 0cde12f..44cdd88 100644 --- a/src/base/color.h +++ b/src/base/color.h @@ -35,12 +35,9 @@ class CColor { static_cast(clamp(0, _a, 1) * 255)); } - constexpr bool operator==(const CColor& c) const { - return r == c.r && g == c.g && b == c.b && a == c.a; - } - constexpr bool operator!=(const CColor& c) const { - return r != c.r || g != c.g || b != c.b || a != c.a; - } + constexpr friend bool operator==(const CColor& lhs, + const CColor& rhs) = default; + [[nodiscard]] constexpr uint32_t argb() const { return (a << 24) | (r << 16) | (g << 8) | b; } diff --git a/src/base/matrix.h b/src/base/matrix.h index 6c762e2..a6f9521 100644 --- a/src/base/matrix.h +++ b/src/base/matrix.h @@ -43,8 +43,8 @@ class CMatrix4x4 { constexpr CMatrix4x4 operator*(const float f) const; constexpr CMatrix4x4 operator/(const float f) const; constexpr friend CMatrix4x4 operator*(const float f, const CMatrix4x4& mat); - constexpr bool operator==(const CMatrix4x4& mat) const { return m == mat.m; } - constexpr bool operator!=(const CMatrix4x4& mat) const { return m != mat.m; } + constexpr friend bool operator==(const CMatrix4x4& lhs, + const CMatrix4x4& rhs) = default; constexpr void Transpose(); [[nodiscard]] constexpr CMatrix4x4 Transposed() const; diff --git a/src/base/rectangle.h b/src/base/rectangle.h index 67da97a..5bd2ed5 100644 --- a/src/base/rectangle.h +++ b/src/base/rectangle.h @@ -61,12 +61,9 @@ class CRect { Move(-p); return *this; } - constexpr bool operator==(const CRect& r) const { - return x1 == r.x1 && y1 == r.y1 && x2 == r.x2 && y2 == r.y2; - } - constexpr bool operator!=(const CRect& r) const { - return x1 != r.x1 || y1 != r.y1 || x2 != r.x2 || y2 != r.y2; - } + constexpr friend bool operator==(const CRect& lhs, + const CRect& rhs) = default; + constexpr CRect operator|(const CRect& r) const { if (!Intersects(r)) return CRect(1, 1, -1, -1); return GetIntersection(r); diff --git a/src/base/vector.h b/src/base/vector.h index 718cfea..9be509c 100644 --- a/src/base/vector.h +++ b/src/base/vector.h @@ -54,12 +54,9 @@ class CVector2 { const float fi = 1 / f; return CVector2(x * fi, y * fi); } - constexpr bool operator==(const CVector2& v) const { - return x == v.x && y == v.y; - } - constexpr bool operator!=(const CVector2& v) const { - return x != v.x || y != v.y; - } + constexpr friend bool operator==(const CVector2& lhs, + const CVector2& rhs) = default; + // dot product constexpr float operator*(const CVector2& v) const { return x * v.x + y * v.y; @@ -135,12 +132,9 @@ class CVector2I { constexpr CVector2I operator/(const int32_t f) const { return CVector2I(x / f, y / f); } - constexpr bool operator==(const CVector2I& v) const { - return x == v.x && y == v.y; - } - constexpr bool operator!=(const CVector2I& v) const { - return x != v.x || y != v.y; - } + constexpr friend bool operator==(const CVector2I& lhs, + const CVector2I& rhs) = default; + // dot product constexpr int32_t operator*(const CVector2I& v) const { return x * v.x + y * v.y; @@ -216,12 +210,9 @@ class CVector3 { const float fi = 1 / f; return CVector3(x * fi, y * fi, z * fi); } - constexpr bool operator==(const CVector3& v) { - return x == v.x && y == v.y && z == v.z; - } - constexpr bool operator!=(const CVector3& v) const { - return x != v.x || y != v.y || z != v.z; - } + constexpr friend bool operator==(const CVector3& lhs, + const CVector3& rhs) = default; + // dot product constexpr float operator*(const CVector3& v) const { return x * v.x + y * v.y + z * v.z; @@ -307,12 +298,9 @@ class CVector4 { const float fi = 1 / f; return CVector4(x * fi, y * fi, z * fi, w * fi); } - constexpr bool operator==(const CVector4& v) const { - return x == v.x && y == v.y && z == v.z && w == v.w; - } - constexpr bool operator!=(const CVector4& v) const { - return x != v.x || y != v.y || z != v.z || w != v.w; - } + constexpr friend bool operator==(const CVector4& lhs, + const CVector4& rhs) = default; + // dot product constexpr float operator*(const CVector4& v) const { return x * v.x + y * v.y + z * v.z + w * v.w;