From 05bc7577b5019bf28c80b1b021a70e152d0caaf0 Mon Sep 17 00:00:00 2001 From: Orange Date: Tue, 11 Nov 2025 23:34:30 +0300 Subject: [PATCH] Refactors perpendicular vector selection Simplifies logic for finding a non-zero perpendicular vector by iterating through candidate directions. This improves readability and maintainability. --- include/omath/collision/simplex.hpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/include/omath/collision/simplex.hpp b/include/omath/collision/simplex.hpp index 9ff5c4f..c4de3f4 100644 --- a/include/omath/collision/simplex.hpp +++ b/include/omath/collision/simplex.hpp @@ -134,13 +134,10 @@ namespace omath::collision template static constexpr V any_perp(const V& v) { - // try cross with axes until non-zero - V d = v.cross(V{1, 0, 0}); - if (near_zero(d)) - d = v.cross(V{0, 1, 0}); - if (near_zero(d)) - d = v.cross(V{0, 0, 1}); - return d; + for (const auto& dir : {V{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}) + if (const auto d = v.cross(dir); !near_zero(d)) + return d; + std::unreachable(); } constexpr bool handle_line(VectorType& direction)