From 9cc83aafdaf570b73b9671ba3b08ab211e0516fd Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 10 Oct 2018 22:59:57 +0200 Subject: [PATCH] Math/Angle: Add FromDegrees and FromRadians builders --- include/Nazara/Math/Angle.hpp | 2 ++ include/Nazara/Math/Angle.inl | 24 +++++++++++++++++++++++ tests/Engine/Physics2D/RigidBody2D.cpp | 2 +- tests/SDK/NDK/Systems/PhysicsSystem2D.cpp | 6 +++--- tests/SDK/NDK/Systems/RenderSystem.cpp | 2 +- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/include/Nazara/Math/Angle.hpp b/include/Nazara/Math/Angle.hpp index 74e2b884d..31ea6daeb 100644 --- a/include/Nazara/Math/Angle.hpp +++ b/include/Nazara/Math/Angle.hpp @@ -68,6 +68,8 @@ namespace Nz bool operator==(const Angle& other) const; bool operator!=(const Angle& other) const; + static Angle FromDegrees(T ang); + static Angle FromRadians(T ang); static Angle Zero(); T angle; diff --git a/include/Nazara/Math/Angle.inl b/include/Nazara/Math/Angle.inl index 354cab93f..b0c52c5a6 100644 --- a/include/Nazara/Math/Angle.inl +++ b/include/Nazara/Math/Angle.inl @@ -471,6 +471,30 @@ namespace Nz return !NumberEquals(angle, other.angle, Detail::AngleUtils::template GetEpsilon()); } + /*! + * \brief Builds an Angle instance using a degree angle, converting if needed + * \return An angle describing the degree angle as Unit + * + * \param ang Degree angle + */ + template + Angle Angle::FromDegrees(T ang) + { + return Angle(Detail::AngleUtils::FromDegrees(ang)); + } + + /*! + * \brief Builds an Angle instance using a radian angle, converting if needed + * \return An angle describing the radian angle as Unit + * + * \param ang Radian angle + */ + template + Angle Angle::FromRadians(T ang) + { + return Angle(Detail::AngleUtils::FromRadians(ang)); + } + /*! * \brief Returns an angle with an angle of zero * \return Zero angle diff --git a/tests/Engine/Physics2D/RigidBody2D.cpp b/tests/Engine/Physics2D/RigidBody2D.cpp index 421a2b083..749fa6f5c 100644 --- a/tests/Engine/Physics2D/RigidBody2D.cpp +++ b/tests/Engine/Physics2D/RigidBody2D.cpp @@ -166,7 +166,7 @@ SCENARIO("RigidBody2D", "[PHYSICS2D][RIGIDBODY2D]") WHEN("We set an angular velocity") { - Nz::RadianAnglef angularSpeed = Nz::RadianAnglef(Nz::DegreeToRadian(90.f)); + Nz::RadianAnglef angularSpeed = Nz::RadianAnglef::FromDegrees(90.f); body.SetAngularVelocity(angularSpeed); world.Step(1.f); diff --git a/tests/SDK/NDK/Systems/PhysicsSystem2D.cpp b/tests/SDK/NDK/Systems/PhysicsSystem2D.cpp index bb6bf250a..d94797065 100644 --- a/tests/SDK/NDK/Systems/PhysicsSystem2D.cpp +++ b/tests/SDK/NDK/Systems/PhysicsSystem2D.cpp @@ -85,7 +85,7 @@ SCENARIO("PhysicsSystem2D", "[NDK][PHYSICSSYSTEM2D]") WHEN("We make rotate our entity") { - Nz::RadianAnglef angularSpeed = Nz::DegreeToRadian(45.f); + Nz::RadianAnglef angularSpeed = Nz::RadianAnglef::FromDegrees(45.f); physicsComponent2D.SetAngularVelocity(angularSpeed); world.Update(2.f); @@ -93,7 +93,7 @@ SCENARIO("PhysicsSystem2D", "[NDK][PHYSICSSYSTEM2D]") { CHECK(physicsComponent2D.GetAngularVelocity() == angularSpeed); CHECK(physicsComponent2D.GetAABB() == Nz::Rectf(-2.f, 0.f, 2.f, 1.f)); - CHECK(physicsComponent2D.GetRotation() == Nz::RadianAnglef(Nz::DegreeToRadian(90.f))); + CHECK(physicsComponent2D.GetRotation() == Nz::RadianAnglef::FromDegrees(90.f)); CHECK(nodeComponent.GetRotation().ToEulerAngles().roll == Approx(Nz::FromDegrees(90.f))); } } @@ -129,7 +129,7 @@ SCENARIO("PhysicsSystem2D", "[NDK][PHYSICSSYSTEM2D]") WHEN("We make rotate our entity") { - Nz::RadianAnglef angularSpeed(Nz::DegreeToRadian(45.f)); + Nz::RadianAnglef angularSpeed = Nz::RadianAnglef::FromDegrees(45.f); physicsComponent2D.SetAngularVelocity(angularSpeed); world.Update(2.f); diff --git a/tests/SDK/NDK/Systems/RenderSystem.cpp b/tests/SDK/NDK/Systems/RenderSystem.cpp index d68f544ab..329818f74 100644 --- a/tests/SDK/NDK/Systems/RenderSystem.cpp +++ b/tests/SDK/NDK/Systems/RenderSystem.cpp @@ -82,7 +82,7 @@ SCENARIO("RenderSystem", "[NDK][RenderSystem]") WHEN("We set an angular velocity") { - Nz::RadianAnglef angularSpeed(Nz::DegreeToRadian(90.f)); + Nz::RadianAnglef angularSpeed = Nz::RadianAnglef::FromDegrees(90.f); physicsComponent2D.SetAngularVelocity(angularSpeed); world.Update(1.f);