Refactors simplex handling in GJK algorithm

Updates simplex handling to use references for vertex access, avoiding unnecessary copies. This improves performance and clarity within the GJK algorithm.
This commit is contained in:
2025-11-09 14:40:22 +03:00
parent e7b82f441c
commit ebfdd0b70e

View File

@@ -55,10 +55,11 @@ namespace omath::collision
bool handle_line(Simplex& points, Vector3<float>& direction) bool handle_line(Simplex& points, Vector3<float>& direction)
{ {
Vector3<float> a = points[0]; const Vector3<float>& a = points[0];
const Vector3<float> b = points[1]; const Vector3<float>& b = points[1];
Vector3<float> ab = b - a; const Vector3<float> ab = b - a;
// ReSharper disable once CppTooWideScopeInitStatement
const Vector3<float> ao = -a; const Vector3<float> ao = -a;
if (ab.point_to_same_direction(ao)) if (ab.point_to_same_direction(ao))
@@ -74,15 +75,15 @@ namespace omath::collision
bool handle_triangle(Simplex& points, Vector3<float>& direction) bool handle_triangle(Simplex& points, Vector3<float>& direction)
{ {
Vector3<float> a = points[0]; const Vector3<float>& a = points[0];
Vector3<float> b = points[1]; const Vector3<float>& b = points[1];
Vector3<float> c = points[2]; const Vector3<float>& c = points[2];
Vector3<float> ab = b - a; const Vector3<float> ab = b - a;
Vector3<float> ac = c - a; const Vector3<float> ac = c - a;
Vector3<float> ao = -a; const Vector3<float> ao = -a;
Vector3<float> abc = ab.cross(ac); const Vector3<float> abc = ab.cross(ac);
if (abc.cross(ac).point_to_same_direction(ao)) if (abc.cross(ac).point_to_same_direction(ao))
{ {
@@ -99,7 +100,6 @@ namespace omath::collision
if (ab.cross(abc).point_to_same_direction(ao)) if (ab.cross(abc).point_to_same_direction(ao))
return handle_line(points = {a, b}, direction); return handle_line(points = {a, b}, direction);
if (abc.point_to_same_direction(ao)) if (abc.point_to_same_direction(ao))
{ {
direction = abc; direction = abc;
@@ -138,7 +138,6 @@ namespace omath::collision
if (adb.point_to_same_direction(ao)) if (adb.point_to_same_direction(ao))
return handle_triangle(simplex = {a, d, b}, direction); return handle_triangle(simplex = {a, d, b}, direction);
return true; return true;
} }