From 8b66098f3d3d5bd49d16abdf39970320bce96c91 Mon Sep 17 00:00:00 2001 From: thejinchao Date: Wed, 2 Jul 2025 22:32:11 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=AE=9A=E4=B9=892=E7=BB=B4?= =?UTF-8?q?=E5=90=91=E9=87=8F=E7=9A=84=E5=A4=A7=E5=B0=8F=E6=AF=94=E8=BE=83?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E7=AC=A6=EF=BC=8C=E6=9A=82=E6=97=B6=E5=8E=BB?= =?UTF-8?q?=E6=8E=893=E7=BB=B4=E5=92=8C4=E7=BA=AC=E5=90=91=E9=87=8F?= =?UTF-8?q?=E7=9A=84=E6=AF=94=E8=BE=83=E6=93=8D=E4=BD=9C=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/core/include/math/dvc_vector2.h | 20 +++++++------ source/core/include/math/dvc_vector3.h | 8 ------ source/core/include/math/dvc_vector4.h | 8 ------ test/unit/dvt_unit_vector2.cpp | 40 +++++++++++++++++++------- test/unit/dvt_unit_vector3.cpp | 10 ------- test/unit/dvt_unit_vector4.cpp | 10 ------- 6 files changed, 42 insertions(+), 54 deletions(-) diff --git a/source/core/include/math/dvc_vector2.h b/source/core/include/math/dvc_vector2.h index 87a91d2..7dc037c 100644 --- a/source/core/include/math/dvc_vector2.h +++ b/source/core/include/math/dvc_vector2.h @@ -59,6 +59,18 @@ public: return (x != rkVector.x || y != rkVector.y); } + inline bool operator > (const TVector2& rkVector) const { + if (y > rkVector.y) return true; + else if (y < rkVector.y) return false; + else return x > rkVector.x; + } + + inline bool operator < (const TVector2& rkVector) const { + if (y < rkVector.y) return true; + else if (y > rkVector.y) return false; + else return x < rkVector.x; + } + public: // Arithmetic operations inline TVector2 operator + (const TVector2& rkVector) const { @@ -172,14 +184,6 @@ public: return *this; } - inline bool operator < (const TVector2& rhs) const { - return (x < rhs.x && y < rhs.y); - } - - inline bool operator > (const TVector2& rhs) const { - return (x > rhs.x && y > rhs.y); - } - public: inline T length(void) const { return MathUtil::sqrt(x * x + y * y); diff --git a/source/core/include/math/dvc_vector3.h b/source/core/include/math/dvc_vector3.h index 673ce18..08be26a 100644 --- a/source/core/include/math/dvc_vector3.h +++ b/source/core/include/math/dvc_vector3.h @@ -194,14 +194,6 @@ public: return *this; } - inline bool operator < (const TVector3& rhs) const { - return (x < rhs.x && y < rhs.y && z < rhs.z); - } - - inline bool operator > (const TVector3& rhs) const { - return (x > rhs.x && y > rhs.y && z > rhs.z); - } - public: inline T length(void) const { return MathUtil::sqrt(x * x + y * y + z * z); diff --git a/source/core/include/math/dvc_vector4.h b/source/core/include/math/dvc_vector4.h index 7d43828..02f3c76 100644 --- a/source/core/include/math/dvc_vector4.h +++ b/source/core/include/math/dvc_vector4.h @@ -210,14 +210,6 @@ public: return *this; } - inline bool operator < (const TVector4& rhs) const { - return (x < rhs.x && y < rhs.y && z < rhs.z && w < rhs.w); - } - - inline bool operator > (const TVector4& rhs) const { - return (x > rhs.x && y > rhs.y && z > rhs.z && w > rhs.w); - } - public: inline T dotProduct(const TVector4& vec) const { diff --git a/test/unit/dvt_unit_vector2.cpp b/test/unit/dvt_unit_vector2.cpp index 65f8610..84b7518 100644 --- a/test/unit/dvt_unit_vector2.cpp +++ b/test/unit/dvt_unit_vector2.cpp @@ -75,6 +75,36 @@ TEST(Math_Vector2, Basic) EXPECT_TRUE(v1 != v2); } + { + fVector2 v1(TWO_RANDOM_FLOAT), v2(v1); + + EXPECT_FALSE(v2 > v1); + EXPECT_FALSE(v1 > v2); + EXPECT_FALSE(v2 < v1); + EXPECT_FALSE(v1 < v2); + + v2.y += 1.f; + EXPECT_GT(v2, v1); + EXPECT_LT(v1, v2); + + v2 = v1; + v2.x += 1.f; + EXPECT_GT(v2, v1); + EXPECT_LT(v1, v2); + + v2 = v1; + v2.x += 1.f; + v2.y += 1.f; + EXPECT_GT(v2, v1); + EXPECT_LT(v1, v2); + + v2 = v1; + v2.x += 1.f; + v2.y -= 1.f; + EXPECT_LT(v2, v1); + EXPECT_GT(v1, v2); + } + { float a = 0.f; while (a == 0.f) { a = _randomFloat(); } @@ -190,16 +220,6 @@ TEST(Math_Vector2, Basic) v3 /= a; EXPECT_TRUE(v3 == v1 / a); } - - { - fVector2 v1(TWO_RANDOM_FLOAT), v2(v1); - - v2 += 1.f; - EXPECT_TRUE(v2 > v1); - - v2 -= 2.f; - EXPECT_TRUE(v2 < v1); - } } //------------------------------------------------------------------------------------- diff --git a/test/unit/dvt_unit_vector3.cpp b/test/unit/dvt_unit_vector3.cpp index ae0dee8..a680f6c 100644 --- a/test/unit/dvt_unit_vector3.cpp +++ b/test/unit/dvt_unit_vector3.cpp @@ -238,16 +238,6 @@ TEST(Math_Vector3, Basic) v3 /= a; EXPECT_TRUE(v3 == v1 / a); } - - { - fVector3 v1(THREE_RANDOM_FLOAT), v2(v1); - - v2 += 1.f; - EXPECT_TRUE(v2 > v1); - - v2 -= 2.f; - EXPECT_TRUE(v2 < v1); - } } //------------------------------------------------------------------------------------- diff --git a/test/unit/dvt_unit_vector4.cpp b/test/unit/dvt_unit_vector4.cpp index 48a41bc..db39094 100644 --- a/test/unit/dvt_unit_vector4.cpp +++ b/test/unit/dvt_unit_vector4.cpp @@ -234,16 +234,6 @@ TEST(Math_Vector4, Basic) v3 /= a; EXPECT_TRUE(v3 == v1 / a); } - - { - fVector4 v1(FOUR_RANDOM_FLOAT), v2(v1); - - v2 += 1.f; - EXPECT_TRUE(v2 > v1); - - v2 -= 2.f; - EXPECT_TRUE(v2 < v1); - } }