Added messages to Vector2 function asserts.

Added assert messages to asserts in the Vector2 functions from SFML3 to make it more clear exactly what the comparison is between a value and the Vector2 constructor is achieving.
This commit is contained in:
Erik Bolumburu 2023-06-28 01:25:30 +01:00 committed by Lukas Dürrenberger
parent 27542637aa
commit 867d878c1c

View File

@ -38,7 +38,7 @@ Vector2<T> Vector2<T>::normalized() const
{
static_assert(std::is_floating_point_v<T>, "Vector2::normalized() is only supported for floating point types");
assert(*this != Vector2<T>());
assert(*this != Vector2<T>() && "Vector2::normalized() cannot normalize a zero vector");
return (*this) / length();
}
@ -49,8 +49,8 @@ Angle Vector2<T>::angleTo(const Vector2<T>& rhs) const
{
static_assert(std::is_floating_point_v<T>, "Vector2::angleTo() is only supported for floating point types");
assert(*this != Vector2<T>());
assert(rhs != Vector2<T>());
assert(*this != Vector2<T>() && "Vector2::angleTo() cannot calculate angle from a zero vector");
assert(rhs != Vector2<T>() && "Vector2::angleTo() cannot calculate angle to a zero vector");
return radians(static_cast<float>(std::atan2(cross(rhs), dot(rhs))));
}
@ -61,7 +61,7 @@ Angle Vector2<T>::angle() const
{
static_assert(std::is_floating_point_v<T>, "Vector2::angle() is only supported for floating point types");
assert(*this != Vector2<T>());
assert(*this != Vector2<T>() && "Vector2::angle() cannot calculate angle from a zero vector");
return radians(static_cast<float>(std::atan2(y, x)));
}
@ -87,7 +87,7 @@ Vector2<T> Vector2<T>::projectedOnto(const Vector2<T>& axis) const
{
static_assert(std::is_floating_point_v<T>, "Vector2::projectedOnto() is only supported for floating point types");
assert(axis != Vector2<T>());
assert(axis != Vector2<T>() && "Vector2::projectedOnto() cannot project onto a zero vector");
return dot(axis) / axis.lengthSq() * axis;
}