diff --git a/libs/geom/include/psemek/geom/vector.hpp b/libs/geom/include/psemek/geom/vector.hpp index ddbaca50..40b2b404 100644 --- a/libs/geom/include/psemek/geom/vector.hpp +++ b/libs/geom/include/psemek/geom/vector.hpp @@ -220,9 +220,11 @@ namespace psemek::geom template T linf_norm(vector const & v) { - T r = std::abs(v[0]); + using std::abs; + using std::max; + T r = abs(v[0]); for (std::size_t i = 1; i < N; ++i) - r = std::max(r, std::abs(v[i])); + r = max(r, abs(v[i])); return r; } @@ -230,8 +232,9 @@ namespace psemek::geom T length(vector const & v) { T const m = linf_norm(v); - if (m == 0) return m; - return m * std::sqrt(length_sqr(v / m)); + if (m == T(0)) return m; + using std::sqrt; + return m * sqrt(length_sqr(v / m)); } template @@ -289,9 +292,11 @@ namespace psemek::geom { std::size_t i = 0, j = 1; + using std::abs; + for (std::size_t k = 1; k < N; ++k) { - if (std::abs(v[k]) > std::abs(v[i])) + if (abs(v[k]) > abs(v[i])) { j = i; i = k; @@ -314,32 +319,41 @@ namespace psemek::geom template vector direction(T angle) { - return {std::cos(angle), std::sin(angle)}; + using std::sin; + using std::cos; + return {cos(angle), sin(angle)}; } template T angle(vector const & v) { - return std::atan2(v[1], v[0]); + using std::atan2; + return atan2(v[1], v[0]); } template T angle(vector const & v0, vector const & v1) { - return std::atan2(det(v0, v1), dot(v0, v1)); + using std::atan2; + return atan2(det(v0, v1), dot(v0, v1)); } template T angle(vector const & v0, vector const & v1) { - return std::acos(std::min(T{1}, std::max(T{-1}, dot(v0, v1)))); + using std::acos; + using std::min; + using std::max; + return acos(min(T{1}, max(T{-1}, dot(v0, v1)))); } template vector rotate(vector const & v, T angle) { - auto const c = std::cos(angle); - auto const s = std::sin(angle); + using std::sin; + using std::cos; + auto const c = cos(angle); + auto const s = sin(angle); return {v[0] * c - v[1] * s, v[0] * s + v[1] * c}; } @@ -369,19 +383,19 @@ namespace psemek::geom template vector pointwise_log(vector const & v) { - return pointwise([](T const & a){ return std::log(a); }, v); + return pointwise([](T const & a){ using std::log; return log(a); }, v); } template vector pointwise_exp(vector const & v) { - return pointwise([](T const & a){ return std::exp(a); }, v); + return pointwise([](T const & a){ using std::exp; return exp(a); }, v); } template vector pointwise_pow(vector const & v0, vector const & v1) { - return pointwise([](T const & a, T const & b){ return std::pow(a, b); }, v0, v1); + return pointwise([](T const & a, T const & b){ using std::pow; return pow(a, b); }, v0, v1); } template @@ -393,23 +407,27 @@ namespace psemek::geom template vector slerp(vector const & v0, vector const & v1, T const & t) { + using std::pow; + using std::abs; + using std::sin; + // threshold is chosen so that for abs(x) < threshold the second term in // sin(x) Taylor series is less than the minimum value representable by T - static auto const threshold = std::pow(6 * std::numeric_limits::min(), T{1}/T{3}); + static auto const threshold = pow(T{6} * std::numeric_limits::min(), T{1}/T{3}); auto const omega = angle(normalized(v0), normalized(v1)); // NB: the case of omega ~ pi is ambiguous and isn't handled in any special way - if (std::abs(omega) < threshold) + if (abs(omega) < threshold) { // prevent division by zero return normalized(lerp(v0, v1, t)); } else { - auto const s = std::sin(omega); - return v0 * std::sin((1 - t) * omega) / s + v1 * std::sin(t * omega) / s; + auto const s = sin(omega); + return v0 * sin((1 - t) * omega) / s + v1 * sin(t * omega) / s; } } @@ -439,8 +457,9 @@ namespace psemek::geom template bool isfinite(vector const & v) { + using std::isfinite; for (std::size_t i = 0; i < N; ++i) - if (!std::isfinite(v[i])) + if (!isfinite(v[i])) return false; return true; }