From 1d4025467678c1cc5fb3ef40fb0a3c0da4e7836d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 20 Feb 2013 20:59:10 +0100 Subject: [PATCH] Math: use Rad for Vector::angle(). --- src/Math/Test/VectorTest.cpp | 14 ++++++++------ src/Math/Vector.h | 9 +++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Math/Test/VectorTest.cpp b/src/Math/Test/VectorTest.cpp index 9035fdaeb..8772c487b 100644 --- a/src/Math/Test/VectorTest.cpp +++ b/src/Math/Test/VectorTest.cpp @@ -63,6 +63,7 @@ class VectorTest: public Corrade::TestSuite::Tester { void configuration(); }; +typedef Math::Rad Rad; typedef Vector<3, float> Vector3; typedef Vector<4, float> Vector4; typedef Vector<4, std::int32_t> Vector4i; @@ -305,17 +306,18 @@ void VectorTest::projectedOntoNormalized() { void VectorTest::angle() { std::ostringstream o; Error::setOutput(&o); - CORRADE_COMPARE(Vector3::angle(Vector3(2.0f, 3.0f, 4.0f).normalized(), {1.0f, -2.0f, 3.0f}), - std::numeric_limits::quiet_NaN()); + auto angle = Vector3::angle(Vector3(2.0f, 3.0f, 4.0f).normalized(), {1.0f, -2.0f, 3.0f}); + CORRADE_VERIFY(angle != angle); CORRADE_COMPARE(o.str(), "Math::Vector::angle(): vectors must be normalized\n"); o.str(""); - CORRADE_COMPARE(Vector3::angle({2.0f, 3.0f, 4.0f}, Vector3(1.0f, -2.0f, 3.0f).normalized()), - std::numeric_limits::quiet_NaN()); + angle = Vector3::angle({2.0f, 3.0f, 4.0f}, Vector3(1.0f, -2.0f, 3.0f).normalized()); + CORRADE_VERIFY(angle != angle); CORRADE_COMPARE(o.str(), "Math::Vector::angle(): vectors must be normalized\n"); - CORRADE_COMPARE(Vector3::angle(Vector3(2.0f, 3.0f, 4.0f).normalized(), Vector3(1.0f, -2.0f, 3.0f).normalized()), - rad(1.162514f)); + CORRADE_COMPARE(Vector3::angle(Vector3(2.0f, 3.0f, 4.0f).normalized(), + Vector3(1.0f, -2.0f, 3.0f).normalized()), + Rad(1.162514f)); } void VectorTest::debug() { diff --git a/src/Math/Vector.h b/src/Math/Vector.h index 843061517..d8debb235 100644 --- a/src/Math/Vector.h +++ b/src/Math/Vector.h @@ -25,6 +25,7 @@ #include #include +#include "Math/Angle.h" #include "Math/BoolVector.h" #include "Math/MathTypeTraits.h" @@ -78,16 +79,16 @@ template class Vector { } /** - * @brief Angle between normalized vectors (in radians) + * @brief Angle between normalized vectors * * Expects that both vectors are normalized. @f[ * \theta = acos \left( \frac{\boldsymbol a \cdot \boldsymbol b}{|\boldsymbol a| \cdot |\boldsymbol b|} \right) = acos (\boldsymbol a \cdot \boldsymbol b) * @f] */ - inline static T angle(const Vector& normalizedA, const Vector& normalizedB) { + inline static Rad angle(const Vector& normalizedA, const Vector& normalizedB) { CORRADE_ASSERT(MathTypeTraits::equals(normalizedA.dot(), T(1)) && MathTypeTraits::equals(normalizedB.dot(), T(1)), - "Math::Vector::angle(): vectors must be normalized", std::numeric_limits::quiet_NaN()); - return std::acos(dot(normalizedA, normalizedB)); + "Math::Vector::angle(): vectors must be normalized", Rad(std::numeric_limits::quiet_NaN())); + return Rad(std::acos(dot(normalizedA, normalizedB))); } /**