Refactors GJK tetrahedron handling

Updates the `handle_tetrahedron` function to use const references for simplex points, improving efficiency and readability.

Corrects a potential bug where the `simplex` variable wasn't being correctly updated when recursively calling `handle_triangle`.

Also, const-qualifies `point_to_same_direction` for better safety.
This commit is contained in:
2025-11-09 14:15:32 +03:00
parent 31cc1116ae
commit 1e540862a0
3 changed files with 17 additions and 17 deletions

View File

@@ -113,30 +113,30 @@ namespace omath::collision
return false; return false;
} }
bool handle_tetrahedron(Simplex& points, Vector3<float>& direction) bool handle_tetrahedron(Simplex& simplex, Vector3<float>& direction)
{ {
Vector3<float> a = points[0]; const auto& a = simplex[0];
Vector3<float> b = points[1]; const auto& b = simplex[1];
Vector3<float> c = points[2]; const auto& c = simplex[2];
Vector3<float> d = points[3]; const auto& d = simplex[3];
Vector3<float> ab = b - a; const Vector3<float> ab = b - a;
Vector3<float> ac = c - a; const Vector3<float> ac = c - a;
Vector3<float> ad = d - a; const Vector3<float> ad = d - a;
Vector3<float> ao = -a; const Vector3<float> ao = -a;
Vector3<float> abc = ab.cross(ac); const Vector3<float> abc = ab.cross(ac);
Vector3<float> acd = ac.cross(ad); const Vector3<float> acd = ac.cross(ad);
Vector3<float> adb = ad.cross(ab); const Vector3<float> adb = ad.cross(ab);
if (abc.point_to_same_direction(ao)) if (abc.point_to_same_direction(ao))
return handle_triangle(points = {a, b, c}, direction); return handle_triangle(simplex = {a, b, c}, direction);
if (acd.point_to_same_direction(ao)) if (acd.point_to_same_direction(ao))
return handle_triangle(points = {a, c, d}, direction); return handle_triangle(simplex = {a, c, d}, direction);
if (adb.point_to_same_direction(ao)) if (adb.point_to_same_direction(ao))
return handle_triangle(points = {a, d, b}, direction); return handle_triangle(simplex = {a, d, b}, direction);
return true; return true;

View File

@@ -217,7 +217,7 @@ namespace omath
} }
[[nodiscard]] [[nodiscard]]
bool point_to_same_direction(const Vector3& other) bool point_to_same_direction(const Vector3& other) const
{ {
return dot(other) > static_cast<Type>(0); return dot(other) > static_cast<Type>(0);
} }

View File

@@ -9,7 +9,7 @@
namespace omath namespace omath
{ {
struct Hsv struct Hsv final
{ {
float hue{}; float hue{};
float saturation{}; float saturation{};