2018-10-06 20:39:40 -07:00
|
|
|
#pragma once
|
2015-08-25 15:04:15 -07:00
|
|
|
|
2017-09-16 20:04:23 -07:00
|
|
|
#include <cmath>
|
2015-08-25 15:04:15 -07:00
|
|
|
|
2019-09-01 00:38:45 -07:00
|
|
|
#include "zeus/Math.hpp"
|
|
|
|
|
2018-12-07 17:16:50 -08:00
|
|
|
namespace zeus {
|
2015-08-25 15:04:15 -07:00
|
|
|
/**
|
2016-09-01 12:38:16 -07:00
|
|
|
* @brief The CRelAngle class represents relative angle in radians
|
2015-08-25 15:04:15 -07:00
|
|
|
*/
|
2019-01-29 00:27:23 -08:00
|
|
|
class CRelAngle {
|
2018-12-07 17:16:50 -08:00
|
|
|
float angle = 0.f;
|
|
|
|
|
2019-01-29 00:27:23 -08:00
|
|
|
public:
|
2020-02-29 01:33:29 -08:00
|
|
|
[[nodiscard]] static float MakeRelativeAngle(float angle) noexcept {
|
2018-12-15 22:31:17 -08:00
|
|
|
float ret = angle - std::trunc(angle / (2.f * M_PIF)) * (2.f * M_PIF);
|
|
|
|
if (ret < 0.f)
|
|
|
|
ret += 2.f * M_PIF;
|
|
|
|
return ret;
|
2018-12-07 17:16:50 -08:00
|
|
|
}
|
|
|
|
|
2019-09-03 13:32:48 -07:00
|
|
|
constexpr CRelAngle() noexcept = default;
|
2018-12-07 17:16:50 -08:00
|
|
|
|
2019-09-03 13:32:48 -07:00
|
|
|
constexpr CRelAngle(float angle) noexcept : angle(angle) {}
|
2018-12-07 17:16:50 -08:00
|
|
|
|
2019-09-03 13:32:48 -07:00
|
|
|
constexpr CRelAngle(const CRelAngle&) noexcept = default;
|
|
|
|
|
|
|
|
constexpr CRelAngle& operator=(float ang) noexcept {
|
2018-12-16 19:51:14 -08:00
|
|
|
angle = ang;
|
2018-12-07 17:16:50 -08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-09-03 13:32:48 -07:00
|
|
|
constexpr CRelAngle& operator=(const CRelAngle& ang) noexcept = default;
|
2018-12-07 17:16:50 -08:00
|
|
|
|
2020-02-29 01:33:29 -08:00
|
|
|
[[nodiscard]] constexpr float asDegrees() const noexcept { return radToDeg(angle); }
|
2018-12-07 17:16:50 -08:00
|
|
|
|
2020-02-29 01:33:29 -08:00
|
|
|
[[nodiscard]] constexpr float asRadians() const noexcept { return angle; }
|
2018-12-07 17:16:50 -08:00
|
|
|
|
2020-02-29 01:33:29 -08:00
|
|
|
[[nodiscard]] float arcCosine() const noexcept { return std::acos(angle); }
|
2018-12-07 17:16:50 -08:00
|
|
|
|
2020-02-29 01:33:29 -08:00
|
|
|
[[nodiscard]] static constexpr CRelAngle FromDegrees(float angle) noexcept {
|
2018-12-07 17:16:50 -08:00
|
|
|
CRelAngle ret;
|
2018-12-16 19:51:14 -08:00
|
|
|
ret.angle = degToRad(angle);
|
2018-12-07 17:16:50 -08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-09-03 13:32:48 -07:00
|
|
|
constexpr operator float() const noexcept { return angle; }
|
2018-12-07 17:16:50 -08:00
|
|
|
|
2020-02-29 01:33:29 -08:00
|
|
|
[[nodiscard]] static constexpr CRelAngle FromRadians(float angle) noexcept { return CRelAngle(angle); }
|
2018-12-07 17:16:50 -08:00
|
|
|
|
2020-02-29 01:33:29 -08:00
|
|
|
[[nodiscard]] constexpr bool operator<(const CRelAngle& other) const noexcept { return angle < other.angle; }
|
2018-12-07 17:16:50 -08:00
|
|
|
|
2019-09-03 13:32:48 -07:00
|
|
|
constexpr CRelAngle& operator+=(const CRelAngle& other) noexcept {
|
|
|
|
angle += other.angle;
|
2018-12-07 17:16:50 -08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-09-03 13:32:48 -07:00
|
|
|
constexpr CRelAngle& operator+=(float r) noexcept {
|
|
|
|
angle += r;
|
2018-12-07 17:16:50 -08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-09-03 13:32:48 -07:00
|
|
|
constexpr CRelAngle& operator-=(const CRelAngle& other) noexcept {
|
|
|
|
angle -= other.angle;
|
2018-12-07 17:16:50 -08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-09-03 13:32:48 -07:00
|
|
|
constexpr CRelAngle& operator-=(float r) noexcept {
|
|
|
|
angle -= r;
|
2018-12-07 17:16:50 -08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-09-03 13:32:48 -07:00
|
|
|
constexpr CRelAngle& operator*=(const CRelAngle& other) noexcept {
|
|
|
|
angle *= other.angle;
|
2018-12-07 17:16:50 -08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-09-03 13:32:48 -07:00
|
|
|
constexpr CRelAngle& operator*=(float r) noexcept {
|
|
|
|
angle *= r;
|
2018-12-07 17:16:50 -08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-09-03 13:32:48 -07:00
|
|
|
constexpr CRelAngle& operator/=(const CRelAngle& other) noexcept {
|
|
|
|
angle /= other.angle;
|
2018-12-07 17:16:50 -08:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2019-09-03 13:32:48 -07:00
|
|
|
constexpr CRelAngle& operator/=(float r) noexcept {
|
|
|
|
angle /= r;
|
2018-12-07 17:16:50 -08:00
|
|
|
return *this;
|
|
|
|
}
|
2018-12-16 19:51:14 -08:00
|
|
|
|
2019-09-03 13:32:48 -07:00
|
|
|
void makeRel() noexcept { angle = MakeRelativeAngle(angle); }
|
2018-12-16 19:51:14 -08:00
|
|
|
|
2020-02-29 01:33:29 -08:00
|
|
|
[[nodiscard]] CRelAngle asRel() const noexcept { return CRelAngle(MakeRelativeAngle(angle)); }
|
2015-08-25 15:04:15 -07:00
|
|
|
};
|
2018-12-07 21:23:50 -08:00
|
|
|
} // namespace zeus
|