Math/Angle: Rework ToDegrees/ToRadians
- Rename To[Degrees|Radians] to To[Degrees|Radians]Angle - Add To[Degrees|Radians] methods which returns an angle value
This commit is contained in:
parent
9cc83aafda
commit
7613f50a6e
|
|
@ -47,10 +47,12 @@ namespace Nz
|
||||||
Angle& Set(const Angle& ang);
|
Angle& Set(const Angle& ang);
|
||||||
template<typename U> Angle& Set(const Angle<Unit, U>& ang);
|
template<typename U> Angle& Set(const Angle<Unit, U>& ang);
|
||||||
|
|
||||||
Angle<AngleUnit::Degree, T> ToDegrees() const;
|
T ToDegrees() const;
|
||||||
|
Angle<AngleUnit::Degree, T> ToDegreeAngle() const;
|
||||||
EulerAngles<T> ToEulerAngles() const;
|
EulerAngles<T> ToEulerAngles() const;
|
||||||
Quaternion<T> ToQuaternion() const;
|
Quaternion<T> ToQuaternion() const;
|
||||||
Angle<AngleUnit::Radian, T> ToRadians() const;
|
T ToRadians() const;
|
||||||
|
Angle<AngleUnit::Radian, T> ToRadianAngle() const;
|
||||||
String ToString() const;
|
String ToString() const;
|
||||||
|
|
||||||
Angle& operator=(const Angle&) = default;
|
Angle& operator=(const Angle&) = default;
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ namespace Nz
|
||||||
template<AngleUnit Unit, typename T>
|
template<AngleUnit Unit, typename T>
|
||||||
T Angle<Unit, T>::GetCos() const
|
T Angle<Unit, T>::GetCos() const
|
||||||
{
|
{
|
||||||
return std::cos(ToRadians().angle);
|
return std::cos(ToRadianAngle().angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
@ -176,7 +176,7 @@ namespace Nz
|
||||||
template<AngleUnit Unit, typename T>
|
template<AngleUnit Unit, typename T>
|
||||||
T Angle<Unit, T>::GetSin() const
|
T Angle<Unit, T>::GetSin() const
|
||||||
{
|
{
|
||||||
return std::sin(ToRadians().angle);
|
return std::sin(ToRadianAngle().angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
@ -191,7 +191,7 @@ namespace Nz
|
||||||
std::pair<T, T> Angle<Unit, T>::GetSinCos() const
|
std::pair<T, T> Angle<Unit, T>::GetSinCos() const
|
||||||
{
|
{
|
||||||
T sin, cos;
|
T sin, cos;
|
||||||
Detail::SinCos<T>(ToRadians().angle, &sin, &cos);
|
Detail::SinCos<T>(ToRadianAngle().angle, &sin, &cos);
|
||||||
|
|
||||||
return std::make_pair(sin, cos);
|
return std::make_pair(sin, cos);
|
||||||
}
|
}
|
||||||
|
|
@ -205,7 +205,7 @@ namespace Nz
|
||||||
template<AngleUnit Unit, typename T>
|
template<AngleUnit Unit, typename T>
|
||||||
T Angle<Unit, T>::GetTan() const
|
T Angle<Unit, T>::GetTan() const
|
||||||
{
|
{
|
||||||
return std::tan(ToRadians().angle);
|
return std::tan(ToRadianAngle().angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
@ -289,14 +289,24 @@ namespace Nz
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Returns the degree angle that is equivalent to this one
|
||||||
|
* \return Equivalent degree angle value
|
||||||
|
*/
|
||||||
|
template<AngleUnit Unit, typename T>
|
||||||
|
T Angle<Unit, T>::ToDegrees() const
|
||||||
|
{
|
||||||
|
return Detail::AngleUtils<Unit>::ToDegrees(angle);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Returns the degree angle that is equivalent to this one
|
* \brief Returns the degree angle that is equivalent to this one
|
||||||
* \return Equivalent degree angle
|
* \return Equivalent degree angle
|
||||||
*/
|
*/
|
||||||
template<AngleUnit Unit, typename T>
|
template<AngleUnit Unit, typename T>
|
||||||
Angle<AngleUnit::Degree, T> Angle<Unit, T>::ToDegrees() const
|
Angle<AngleUnit::Degree, T> Angle<Unit, T>::ToDegreeAngle() const
|
||||||
{
|
{
|
||||||
return DegreeAngle<T>(Detail::AngleUtils<Unit>::ToDegrees(angle));
|
return DegreeAngle<T>(ToDegrees());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
@ -308,7 +318,7 @@ namespace Nz
|
||||||
template<AngleUnit Unit, typename T>
|
template<AngleUnit Unit, typename T>
|
||||||
EulerAngles<T> Angle<Unit, T>::ToEulerAngles() const
|
EulerAngles<T> Angle<Unit, T>::ToEulerAngles() const
|
||||||
{
|
{
|
||||||
return EulerAngles<T>(0, 0, ToDegrees().angle);
|
return EulerAngles<T>(0, 0, ToDegreeAngle().angle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
@ -327,14 +337,24 @@ namespace Nz
|
||||||
return Quaternion<T>(sincos.second, 0, 0, sincos.first);
|
return Quaternion<T>(sincos.second, 0, 0, sincos.first);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Returns the radian angle that is equivalent to this angle
|
||||||
|
* \return Equivalent radian angle value
|
||||||
|
*/
|
||||||
|
template<AngleUnit Unit, typename T>
|
||||||
|
T Angle<Unit, T>::ToRadians() const
|
||||||
|
{
|
||||||
|
return Detail::AngleUtils<Unit>::ToRadians(angle);
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Returns the radian angle that is equivalent to this angle
|
* \brief Returns the radian angle that is equivalent to this angle
|
||||||
* \return Equivalent radian angle
|
* \return Equivalent radian angle
|
||||||
*/
|
*/
|
||||||
template<AngleUnit Unit, typename T>
|
template<AngleUnit Unit, typename T>
|
||||||
Angle<AngleUnit::Radian, T> Angle<Unit, T>::ToRadians() const
|
Angle<AngleUnit::Radian, T> Angle<Unit, T>::ToRadianAngle() const
|
||||||
{
|
{
|
||||||
return RadianAngle<T>(Detail::AngleUtils<Unit>::ToRadians(angle));
|
return RadianAngle<T>(ToRadians());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ SCENARIO("Angle", "[MATH][ANGLE]")
|
||||||
|
|
||||||
WHEN("We convert it to degrees")
|
WHEN("We convert it to degrees")
|
||||||
{
|
{
|
||||||
Nz::DegreeAnglef copyAngle = angle.ToDegrees();
|
Nz::DegreeAnglef copyAngle = angle.ToDegreeAngle();
|
||||||
|
|
||||||
THEN("It should compare to itself")
|
THEN("It should compare to itself")
|
||||||
{
|
{
|
||||||
|
|
@ -28,7 +28,7 @@ SCENARIO("Angle", "[MATH][ANGLE]")
|
||||||
Nz::RadianAnglef expectedResult(float(M_PI_2));
|
Nz::RadianAnglef expectedResult(float(M_PI_2));
|
||||||
|
|
||||||
CHECK(radAngle == expectedResult);
|
CHECK(radAngle == expectedResult);
|
||||||
CHECK(angle.ToRadians() == expectedResult);
|
CHECK(angle.ToRadianAngle() == expectedResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,7 +110,7 @@ SCENARIO("Angle", "[MATH][ANGLE]")
|
||||||
|
|
||||||
WHEN("We convert it to radians")
|
WHEN("We convert it to radians")
|
||||||
{
|
{
|
||||||
Nz::RadianAnglef copyAngle = angle.ToRadians();
|
Nz::RadianAnglef copyAngle = angle.ToRadianAngle();
|
||||||
|
|
||||||
THEN("It should compare to itself")
|
THEN("It should compare to itself")
|
||||||
{
|
{
|
||||||
|
|
@ -127,7 +127,7 @@ SCENARIO("Angle", "[MATH][ANGLE]")
|
||||||
Nz::DegreeAnglef expectedResult(-180.f);
|
Nz::DegreeAnglef expectedResult(-180.f);
|
||||||
|
|
||||||
CHECK(degAngle == expectedResult);
|
CHECK(degAngle == expectedResult);
|
||||||
CHECK(angle.ToDegrees() == expectedResult);
|
CHECK(angle.ToDegreeAngle() == expectedResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue