From 7babed1c5774ff066835512e4e95daddef11dfd5 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Wed, 12 Jan 2022 19:18:24 +0300 Subject: [PATCH] Fix geom::acos_over_sqrt_1_minus_x2 to allow arguments slightly larger than 1 to prevent NaNs --- libs/geom/include/psemek/geom/math.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/geom/include/psemek/geom/math.hpp b/libs/geom/include/psemek/geom/math.hpp index 81586461..71b559b1 100644 --- a/libs/geom/include/psemek/geom/math.hpp +++ b/libs/geom/include/psemek/geom/math.hpp @@ -60,7 +60,7 @@ namespace psemek::geom template T acos_over_sqrt_1_minus_x2(T const & x) { - auto t = std::sqrt(T{1} - x * x); + auto t = std::sqrt(std::max(T{0}, T{1} - x * x)); if (t < std::numeric_limits::epsilon()) return T{1}; return std::acos(x) / t;