Fix geom::acos_over_sqrt_1_minus_x2 to allow arguments slightly larger than 1 to prevent NaNs

This commit is contained in:
Nikita Lisitsa 2022-01-12 19:18:24 +03:00
parent efc22a5bd7
commit 7babed1c57

View file

@ -60,7 +60,7 @@ namespace psemek::geom
template <typename T>
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<T>::epsilon())
return T{1};
return std::acos(x) / t;