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>
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});
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)