From 96e4e1c9d66818987bcd62e4f986aad23a1f6610 Mon Sep 17 00:00:00 2001 From: Orange Date: Sun, 16 Feb 2025 10:06:04 +0300 Subject: [PATCH] added new method added concept for mat type --- include/omath/Mat.hpp | 7 +++++++ include/omath/Vector3.hpp | 11 ++++++++++- tests/general/UnitTestVector3.cpp | 6 ++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/include/omath/Mat.hpp b/include/omath/Mat.hpp index 382d900..3a23fbc 100644 --- a/include/omath/Mat.hpp +++ b/include/omath/Mat.hpp @@ -22,6 +22,13 @@ namespace omath COLUMN_MAJOR }; + + template + concept MatTemplateEqual = + (M1::rows == M2::rows) && (M1::columns == M2::columns) && + std::is_same_v && + (M1::store_type == M2::store_type); + template requires std::is_arithmetic_v class Mat final diff --git a/include/omath/Vector3.hpp b/include/omath/Vector3.hpp index 7d3ff50..88dce1c 100644 --- a/include/omath/Vector3.hpp +++ b/include/omath/Vector3.hpp @@ -9,6 +9,7 @@ #include "omath/Vector2.hpp" #include "omath/Angle.hpp" #include +#include namespace omath @@ -228,6 +229,14 @@ namespace omath return Angle::FromRadians(std::acos(Dot(other) / bottom)); } + [[nodiscard]] bool IsPerpendicular(const Vector3& other) const + { + if (const auto angle = AngleBetween(other)) + return angle->AsDegrees() == 90.f; + + return false; + } + [[nodiscard]] constexpr float Sum2D() const { return Vector2::Sum(); @@ -235,7 +244,7 @@ namespace omath [[nodiscard]] Vector3 ViewAngleTo(const Vector3& other) const; - [[nodiscard]] std::tuple AsTuple() const + [[nodiscard]] constexpr std::tuple AsTuple() const { return std::make_tuple(x, y, z); } diff --git a/tests/general/UnitTestVector3.cpp b/tests/general/UnitTestVector3.cpp index 14002d3..d7560a6 100644 --- a/tests/general/UnitTestVector3.cpp +++ b/tests/general/UnitTestVector3.cpp @@ -395,6 +395,12 @@ TEST_F(UnitTestVector3, AngleBeatween) EXPECT_FALSE(Vector3(0.0f, 0.0f, 0.0f).AngleBetween({0.0f, 0.0f, 1.0f}).has_value()); } +TEST_F(UnitTestVector3, IsPerpendicular) +{ + EXPECT_EQ(Vector3(0.0f, 0.0f, 1.0f).IsPerpendicular({1, 0 ,0}), true); + EXPECT_EQ(Vector3(0.0f, 0.0f, 1.0f).IsPerpendicular({0.0f, 0.0f, 1.0f}), false); + EXPECT_FALSE(Vector3(0.0f, 0.0f, 0.0f).IsPerpendicular({0.0f, 0.0f, 1.0f})); +} // Static assertions (compile-time checks) static_assert(Vector3(1.0f, 2.0f, 3.0f).LengthSqr() == 14.0f, "LengthSqr should be 14");