Refactors perpendicular vector selection

Simplifies logic for finding a non-zero perpendicular vector by iterating through candidate directions. This improves readability and maintainability.
This commit is contained in:
2025-11-11 23:34:30 +03:00
parent 9efabd8fb2
commit 05bc7577b5

View File

@@ -134,13 +134,10 @@ namespace omath::collision
template<class V> template<class V>
static constexpr V any_perp(const V& v) static constexpr V any_perp(const V& v)
{ {
// try cross with axes until non-zero for (const auto& dir : {V{1, 0, 0}, {0, 1, 0}, {0, 0, 1}})
V d = v.cross(V{1, 0, 0}); if (const auto d = v.cross(dir); !near_zero(d))
if (near_zero(d)) return d;
d = v.cross(V{0, 1, 0}); std::unreachable();
if (near_zero(d))
d = v.cross(V{0, 0, 1});
return d;
} }
constexpr bool handle_line(VectorType& direction) constexpr bool handle_line(VectorType& direction)