重新定义2维向量的大小比较操作符,暂时去掉3维和4纬向量的比较操作符

This commit is contained in:
2025-07-02 22:32:11 +08:00
parent 2520e9589f
commit 8b66098f3d
6 changed files with 42 additions and 54 deletions
+12 -8
View File
@@ -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);
-8
View File
@@ -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);
-8
View File
@@ -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 {
+30 -10
View File
@@ -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);
}
}
//-------------------------------------------------------------------------------------
-10
View File
@@ -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);
}
}
//-------------------------------------------------------------------------------------
-10
View File
@@ -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);
}
}