From ebfdd0b70e8749efbcf361597125b5959bd62eff Mon Sep 17 00:00:00 2001 From: Orange Date: Sun, 9 Nov 2025 14:40:22 +0300 Subject: [PATCH] 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. --- include/omath/collision/simplex.hpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/include/omath/collision/simplex.hpp b/include/omath/collision/simplex.hpp index 46d7e1e..703afb4 100644 --- a/include/omath/collision/simplex.hpp +++ b/include/omath/collision/simplex.hpp @@ -55,10 +55,11 @@ namespace omath::collision bool handle_line(Simplex& points, Vector3& direction) { - Vector3 a = points[0]; - const Vector3 b = points[1]; + const Vector3& a = points[0]; + const Vector3& b = points[1]; - Vector3 ab = b - a; + const Vector3 ab = b - a; + // ReSharper disable once CppTooWideScopeInitStatement const Vector3 ao = -a; if (ab.point_to_same_direction(ao)) @@ -74,15 +75,15 @@ namespace omath::collision bool handle_triangle(Simplex& points, Vector3& direction) { - Vector3 a = points[0]; - Vector3 b = points[1]; - Vector3 c = points[2]; + const Vector3& a = points[0]; + const Vector3& b = points[1]; + const Vector3& c = points[2]; - Vector3 ab = b - a; - Vector3 ac = c - a; - Vector3 ao = -a; + const Vector3 ab = b - a; + const Vector3 ac = c - a; + const Vector3 ao = -a; - Vector3 abc = ab.cross(ac); + const Vector3 abc = ab.cross(ac); 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)) return handle_line(points = {a, b}, direction); - if (abc.point_to_same_direction(ao)) { direction = abc; @@ -138,7 +138,6 @@ namespace omath::collision if (adb.point_to_same_direction(ao)) return handle_triangle(simplex = {a, d, b}, direction); - return true; }