Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
orange-cpp committed Nov 9, 2025
commit 1e540862a0e5fdf4c72e9369d1d31e299aa3c421
32 changes: 16 additions & 16 deletions include/omath/collision/simplex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,30 +113,30 @@ namespace omath::collision
return false;
}

bool handle_tetrahedron(Simplex& points, Vector3<float>& direction)
bool handle_tetrahedron(Simplex& simplex, Vector3<float>& direction)
{
Vector3<float> a = points[0];
Vector3<float> b = points[1];
Vector3<float> c = points[2];
Vector3<float> d = points[3];

Vector3<float> ab = b - a;
Vector3<float> ac = c - a;
Vector3<float> ad = d - a;
Vector3<float> ao = -a;
const auto& a = simplex[0];
const auto& b = simplex[1];
const auto& c = simplex[2];
const auto& d = simplex[3];

const Vector3<float> ab = b - a;
const Vector3<float> ac = c - a;
const Vector3<float> ad = d - a;
const Vector3<float> ao = -a;

Vector3<float> abc = ab.cross(ac);
Vector3<float> acd = ac.cross(ad);
Vector3<float> adb = ad.cross(ab);
const Vector3<float> abc = ab.cross(ac);
const Vector3<float> acd = ac.cross(ad);
const Vector3<float> adb = ad.cross(ab);

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))
return handle_triangle(points = {a, c, d}, direction);
return handle_triangle(simplex = {a, c, d}, direction);

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;
Expand Down
2 changes: 1 addition & 1 deletion include/omath/linear_algebra/vector3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ namespace omath
}

[[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);
}
Expand Down
2 changes: 1 addition & 1 deletion include/omath/utility/color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace omath
{
struct Hsv
struct Hsv final
{
float hue{};
float saturation{};
Expand Down