From e4087165b9ce1c1e7b2ab60483fcc50b9ab0683d Mon Sep 17 00:00:00 2001 From: Orange Date: Sun, 17 May 2026 09:38:19 +0300 Subject: [PATCH] added safety check --- include/omath/linear_algebra/mat.hpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/omath/linear_algebra/mat.hpp b/include/omath/linear_algebra/mat.hpp index 30461f8..141390b 100644 --- a/include/omath/linear_algebra/mat.hpp +++ b/include/omath/linear_algebra/mat.hpp @@ -628,10 +628,16 @@ namespace omath return static_cast(std::sqrt(x * x + y * y + z * z)); }; + const auto scale_x = column_length(mat.at(0, 0), mat.at(1, 0), mat.at(2, 0)); + const auto scale_y = column_length(mat.at(0, 1), mat.at(1, 1), mat.at(2, 1)); + const auto scale_z = column_length(mat.at(0, 2), mat.at(1, 2), mat.at(2, 2)); + + constexpr auto epsilon = std::numeric_limits::epsilon(); + return { - column_length(mat.at(0, 0), mat.at(1, 0), mat.at(2, 0)), - column_length(mat.at(0, 1), mat.at(1, 1), mat.at(2, 1)), - column_length(mat.at(0, 2), mat.at(1, 2), mat.at(2, 2)), + std::abs(scale_x) < epsilon ? Type{1} : scale_x, + std::abs(scale_y) < epsilon ? Type{1} : scale_y, + std::abs(scale_z) < epsilon ? Type{1} : scale_z, }; }