Math/Angle: Add FromDegrees and FromRadians builders

This commit is contained in:
Lynix 2018-10-10 22:59:57 +02:00
parent 56922001ba
commit 9cc83aafda
5 changed files with 31 additions and 5 deletions

View File

@ -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;

View File

@ -471,6 +471,30 @@ namespace Nz
return !NumberEquals(angle, other.angle, Detail::AngleUtils<Unit>::template GetEpsilon<T>());
}
/*!
* \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<AngleUnit Unit, typename T>
Angle<Unit, T> Angle<Unit, T>::FromDegrees(T ang)
{
return Angle(Detail::AngleUtils<Unit>::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<AngleUnit Unit, typename T>
Angle<Unit, T> Angle<Unit, T>::FromRadians(T ang)
{
return Angle(Detail::AngleUtils<Unit>::FromRadians(ang));
}
/*!
* \brief Returns an angle with an angle of zero
* \return Zero angle

View File

@ -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);

View File

@ -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);

View File

@ -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);