Refactors triangle calculations for generic vectors

Updates the `Triangle` class to use a generic `Vector` type instead of `Vector3`, enhancing flexibility and reusability.

Changes include updating relevant function return types to use `Vector::ContainedType` and adapting length and distance calculations accordingly.

This refactoring supports the ongoing work on the EPA algorithm (feature/epa_algorithm) by providing a more adaptable foundation for geometric calculations.
This commit is contained in:
2025-11-13 15:29:10 +03:00
parent c515dc89a9
commit 6d3b543648
4 changed files with 13 additions and 10 deletions

View File

@@ -26,12 +26,12 @@ namespace omath
{
}
Vector3<float> m_vertex1;
Vector3<float> m_vertex2;
Vector3<float> m_vertex3;
Vector m_vertex1;
Vector m_vertex2;
Vector m_vertex3;
[[nodiscard]]
constexpr Vector3<float> calculate_normal() const
constexpr Vector calculate_normal() const
{
const auto b = side_b_vector();
const auto a = side_a_vector();
@@ -40,25 +40,25 @@ namespace omath
}
[[nodiscard]]
float side_a_length() const
Vector::ContainedType side_a_length() const
{
return m_vertex1.distance_to(m_vertex2);
}
[[nodiscard]]
float side_b_length() const
Vector::ContainedType side_b_length() const
{
return m_vertex3.distance_to(m_vertex2);
}
[[nodiscard]]
constexpr Vector3<float> side_a_vector() const
constexpr Vector side_a_vector() const
{
return m_vertex1 - m_vertex2;
}
[[nodiscard]]
constexpr float hypot() const
constexpr Vector::ContainedType hypot() const
{
return m_vertex1.distance_to(m_vertex3);
}
@@ -72,12 +72,12 @@ namespace omath
return std::abs(side_a * side_a + side_b * side_b - hypot_value * hypot_value) <= 0.0001f;
}
[[nodiscard]]
constexpr Vector3<float> side_b_vector() const
constexpr Vector side_b_vector() const
{
return m_vertex3 - m_vertex2;
}
[[nodiscard]]
constexpr Vector3<float> mid_point() const
constexpr Vector mid_point() const
{
return (m_vertex1 + m_vertex2 + m_vertex3) / 3;
}

View File

@@ -19,6 +19,7 @@ namespace omath
class Vector2
{
public:
using ContainedType = Type;
Type x = static_cast<Type>(0);
Type y = static_cast<Type>(0);

View File

@@ -23,6 +23,7 @@ namespace omath
class Vector3 : public Vector2<Type>
{
public:
using ContainedType = Type;
Type z = static_cast<Type>(0);
constexpr Vector3(const Type& x, const Type& y, const Type& z) noexcept: Vector2<Type>(x, y), z(z)
{

View File

@@ -13,6 +13,7 @@ namespace omath
class Vector4 : public Vector3<Type>
{
public:
using ContainedType = Type;
Type w;
constexpr Vector4(const Type& x, const Type& y, const Type& z, const Type& w): Vector3<Type>(x, y, z), w(w)