Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions include/omath/vector2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,29 @@ namespace omath
return x + y;
}

[[nodiscard]]
bool operator<(const Vector2& other) const noexcept
{
return length() < other.length();
}
[[nodiscard]]
bool operator>(const Vector2& other) const noexcept
{
return length() > other.length();
}

[[nodiscard]]
bool operator<=(const Vector2& other) const noexcept
{
return length() <= other.length();
}

[[nodiscard]]
bool operator>=(const Vector2& other) const noexcept
{
return length() >= other.length();
}

[[nodiscard]]
constexpr std::tuple<Type, Type> as_tuple() const noexcept
{
Expand Down
24 changes: 24 additions & 0 deletions include/omath/vector3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,30 @@ namespace omath
return {angles::radians_to_degrees(std::asin(delta.z / distance)),
angles::radians_to_degrees(std::atan2(delta.y, delta.x)), 0};
}

[[nodiscard]]
bool operator<(const Vector3& other) const noexcept
{
return length() < other.length();
}

[[nodiscard]]
bool operator>(const Vector3& other) const noexcept
{
return length() > other.length();
}

[[nodiscard]]
bool operator<=(const Vector3& other) const noexcept
{
return length() <= other.length();
}

[[nodiscard]]
bool operator>=(const Vector3& other) const noexcept
{
return length() >= other.length();
}
};
} // namespace omath
// ReSharper disable once CppRedundantNamespaceDefinition
Expand Down
26 changes: 25 additions & 1 deletion include/omath/vector4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace omath
return Vector3<Type>::dot(other) + w * other.w;
}

[[nodiscard]] Vector3<Type> length() const noexcept
[[nodiscard]] Type length() const noexcept
{
return std::sqrt(length_sqr());
}
Expand Down Expand Up @@ -158,6 +158,30 @@ namespace omath
return Vector3<Type>::sum() + w;
}

[[nodiscard]]
bool operator<(const Vector4& other) const noexcept
{
return length() < other.length();
}

[[nodiscard]]
bool operator>(const Vector4& other) const noexcept
{
return length() > other.length();
}

[[nodiscard]]
bool operator<=(const Vector4& other) const noexcept
{
return length() <= other.length();
}

[[nodiscard]]
bool operator>=(const Vector4& other) const noexcept
{
return length() >= other.length();
}

#ifdef OMATH_IMGUI_INTEGRATION
[[nodiscard]]
ImVec4 to_im_vec4() const noexcept
Expand Down
22 changes: 22 additions & 0 deletions tests/general/unit_test_vector2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,28 @@ TEST_F(UnitTestVector2, NegationOperator_ZeroVector)
EXPECT_FLOAT_EQ(result.y, -0.0f);
}

TEST_F(UnitTestVector2, LessOperator)
{
EXPECT_TRUE(v1 < v2);
}

TEST_F(UnitTestVector2, GreaterOperator)
{
EXPECT_TRUE(v2 > v1);
}
TEST_F(UnitTestVector2, LessEqualOperator)
{
EXPECT_TRUE(omath::Vector2<float>{} <= omath::Vector2<float>{});
EXPECT_TRUE(omath::Vector2<float>{} <= omath::Vector2(1.f, 1.f));
}

TEST_F(UnitTestVector2, GreaterEqualOperator)
{
EXPECT_TRUE(omath::Vector2<float>{} >= omath::Vector2<float>{});
EXPECT_TRUE(omath::Vector2(1.f, 1.f) >= omath::Vector2<float>{});
}


// Static assertions (compile-time checks)
static_assert(Vector2(1.0f, 2.0f).length_sqr() == 5.0f, "LengthSqr should be 5");
static_assert(Vector2(1.0f, 2.0f).dot(Vector2(4.0f, 5.0f)) == 14.0f, "Dot product should be 14");
Expand Down
21 changes: 21 additions & 0 deletions tests/general/unit_test_vector3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,27 @@ TEST_F(UnitTestVector3, IsPerpendicular)
EXPECT_FALSE(Vector3(0.0f, 0.0f, 0.0f).is_perpendicular({0.0f, 0.0f, 1.0f}));
}

TEST_F(UnitTestVector3, LessOperator)
{
EXPECT_TRUE(v1 < v2);
}

TEST_F(UnitTestVector3, GreaterOperator)
{
EXPECT_TRUE(v2 > v1);
}
TEST_F(UnitTestVector3, LessEqualOperator)
{
EXPECT_TRUE(omath::Vector3<float>{} <= omath::Vector3<float>{});
EXPECT_TRUE(omath::Vector3<float>{} <= omath::Vector3(1.f, 1.f, 1.f));
}

TEST_F(UnitTestVector3, GreaterEqualOperator)
{
EXPECT_TRUE(omath::Vector3<float>{} >= omath::Vector3<float>{});
EXPECT_TRUE(omath::Vector3(1.f, 1.f, 1.f) >= omath::Vector3<float>{});
}

// Static assertions (compile-time checks)
static_assert(Vector3(1.0f, 2.0f, 3.0f).length_sqr() == 14.0f, "LengthSqr should be 14");
static_assert(Vector3(1.0f, 2.0f, 3.0f).dot(Vector3(4.0f, 5.0f, 6.0f)) == 32.0f, "Dot product should be 32");
Expand Down
20 changes: 20 additions & 0 deletions tests/general/unit_test_vector4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,23 @@ TEST_F(UnitTestVector4, Clamp)
EXPECT_FLOAT_EQ(v3.z, 2.5f);
EXPECT_FLOAT_EQ(v3.w, 4.0f); // w is not clamped in this method
}
TEST_F(UnitTestVector4, LessOperator)
{
EXPECT_TRUE(v1 < v2);
}

TEST_F(UnitTestVector4, GreaterOperator)
{
EXPECT_TRUE(v2 > v1);
}
TEST_F(UnitTestVector4, LessEqualOperator)
{
EXPECT_TRUE(omath::Vector4<float>{} <= omath::Vector4<float>{});
EXPECT_TRUE(omath::Vector4<float>{} <= omath::Vector4(1.f, 1.f, 1.f, 1.f));
}

TEST_F(UnitTestVector4, GreaterEqualOperator)
{
EXPECT_TRUE(omath::Vector4<float>{} >= omath::Vector4<float>{});
EXPECT_TRUE(omath::Vector4(1.f, 1.f, 1.f, 1.f) >= omath::Vector4<float>{});
}
Loading