speed up code by 10 times replacing hypot with sqrt

This commit is contained in:
LDprg 2022-09-06 09:25:23 +02:00 committed by Vittorio Romeo
parent 45986c6400
commit 0584448a06
2 changed files with 3 additions and 3 deletions

View File

@ -106,8 +106,8 @@ template <typename T>
T Vector2<T>::length() const
{
static_assert(std::is_floating_point_v<T>, "Vector2::length() is only supported for floating point types");
return std::hypot(x, y);
return std::sqrt(x*x + y*y);
}
} // namespace sf

View File

@ -48,7 +48,7 @@ T Vector3<T>::length() const
{
static_assert(std::is_floating_point_v<T>, "Vector3::length() is only supported for floating point types");
return std::hypot(x, y, z);
return std::sqrt(x*x + y*y + z*z);
}
} // namespace sf