From 867d878c1c82fc0a1669a4b85c5f3b0ff7b2f364 Mon Sep 17 00:00:00 2001 From: Erik Bolumburu <108585396+erikbolumburu11@users.noreply.github.com> Date: Wed, 28 Jun 2023 01:25:30 +0100 Subject: [PATCH] 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. --- src/SFML/System/Vector2.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/SFML/System/Vector2.cpp b/src/SFML/System/Vector2.cpp index 397ea8ae..b78f0681 100644 --- a/src/SFML/System/Vector2.cpp +++ b/src/SFML/System/Vector2.cpp @@ -38,7 +38,7 @@ Vector2 Vector2::normalized() const { static_assert(std::is_floating_point_v, "Vector2::normalized() is only supported for floating point types"); - assert(*this != Vector2()); + assert(*this != Vector2() && "Vector2::normalized() cannot normalize a zero vector"); return (*this) / length(); } @@ -49,8 +49,8 @@ Angle Vector2::angleTo(const Vector2& rhs) const { static_assert(std::is_floating_point_v, "Vector2::angleTo() is only supported for floating point types"); - assert(*this != Vector2()); - assert(rhs != Vector2()); + assert(*this != Vector2() && "Vector2::angleTo() cannot calculate angle from a zero vector"); + assert(rhs != Vector2() && "Vector2::angleTo() cannot calculate angle to a zero vector"); return radians(static_cast(std::atan2(cross(rhs), dot(rhs)))); } @@ -61,7 +61,7 @@ Angle Vector2::angle() const { static_assert(std::is_floating_point_v, "Vector2::angle() is only supported for floating point types"); - assert(*this != Vector2()); + assert(*this != Vector2() && "Vector2::angle() cannot calculate angle from a zero vector"); return radians(static_cast(std::atan2(y, x))); } @@ -87,7 +87,7 @@ Vector2 Vector2::projectedOnto(const Vector2& axis) const { static_assert(std::is_floating_point_v, "Vector2::projectedOnto() is only supported for floating point types"); - assert(axis != Vector2()); + assert(axis != Vector2() && "Vector2::projectedOnto() cannot project onto a zero vector"); return dot(axis) / axis.lengthSq() * axis; }