| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
|---|---|
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #pragma once |
| 4 | |
| 5 | #include "Prerequisites/BsPlatformDefines.h" |
| 6 | #include "Prerequisites/BsRTTIPrerequisites.h" |
| 7 | |
| 8 | namespace bs |
| 9 | { |
| 10 | class Radian; |
| 11 | /** @addtogroup Math |
| 12 | * @{ |
| 13 | */ |
| 14 | |
| 15 | /** |
| 16 | * Wrapper class which indicates a given angle value is in degrees. |
| 17 | * |
| 18 | * @note |
| 19 | * Degree values are interchangeable with Radian values, and conversions will be done automatically between them. |
| 20 | */ |
| 21 | class BS_UTILITY_EXPORT Degree |
| 22 | { |
| 23 | public: |
| 24 | constexpr Degree() = default; |
| 25 | constexpr Degree(const Degree& d) = default; |
| 26 | constexpr Degree&operator= (const Degree& d) = default; |
| 27 | |
| 28 | constexpr explicit Degree(float d) : mDeg(d) {} |
| 29 | constexpr Degree& operator= (const float& f) { mDeg = f; return *this; } |
| 30 | |
| 31 | Degree(const Radian& r); |
| 32 | Degree& operator= (const Radian& r); |
| 33 | |
| 34 | /** Returns the value of the angle in degrees. */ |
| 35 | constexpr float valueDegrees() const { return mDeg; } |
| 36 | |
| 37 | /** Returns the value of the angle in radians. */ |
| 38 | float valueRadians() const; |
| 39 | |
| 40 | /** Wraps the angle in [0, 360) range */ |
| 41 | Degree wrap(); |
| 42 | |
| 43 | const Degree& operator+ () const { return *this; } |
| 44 | Degree operator+ (const Degree& d) const { return Degree (mDeg + d.mDeg); } |
| 45 | Degree operator+ (const Radian& r) const; |
| 46 | Degree& operator+= (const Degree& d) { mDeg += d.mDeg; return *this; } |
| 47 | Degree& operator+= (const Radian& r); |
| 48 | Degree operator- () const { return Degree(-mDeg); } |
| 49 | Degree operator- (const Degree& d) const { return Degree (mDeg - d.mDeg); } |
| 50 | Degree operator- (const Radian& r) const; |
| 51 | Degree& operator-= (const Degree& d) { mDeg -= d.mDeg; return *this; } |
| 52 | Degree& operator-= (const Radian& r); |
| 53 | Degree operator* (float f) const { return Degree (mDeg * f); } |
| 54 | Degree operator* (const Degree& f) const { return Degree (mDeg * f.mDeg); } |
| 55 | Degree& operator*= (float f) { mDeg *= f; return *this; } |
| 56 | Degree operator/ (float f) const { return Degree (mDeg / f); } |
| 57 | Degree& operator/= (float f) { mDeg /= f; return *this; } |
| 58 | |
| 59 | friend Degree operator* (float lhs, const Degree& rhs) { return Degree(lhs * rhs.mDeg); } |
| 60 | friend Degree operator/ (float lhs, const Degree& rhs) { return Degree(lhs / rhs.mDeg); } |
| 61 | friend Degree operator+ (Degree& lhs, float rhs) { return Degree(lhs.mDeg + rhs); } |
| 62 | friend Degree operator+ (float lhs, const Degree& rhs) { return Degree(lhs + rhs.mDeg); } |
| 63 | friend Degree operator- (const Degree& lhs, float rhs) { return Degree(lhs.mDeg - rhs); } |
| 64 | friend Degree operator- (const float lhs, const Degree& rhs) { return Degree(lhs - rhs.mDeg); } |
| 65 | |
| 66 | bool operator< (const Degree& d) const { return mDeg < d.mDeg; } |
| 67 | bool operator<= (const Degree& d) const { return mDeg <= d.mDeg; } |
| 68 | bool operator== (const Degree& d) const { return mDeg == d.mDeg; } |
| 69 | bool operator!= (const Degree& d) const { return mDeg != d.mDeg; } |
| 70 | bool operator>= (const Degree& d) const { return mDeg >= d.mDeg; } |
| 71 | bool operator> (const Degree& d) const { return mDeg > d.mDeg; } |
| 72 | |
| 73 | private: |
| 74 | float mDeg = 0.0f; |
| 75 | }; |
| 76 | |
| 77 | /** @} */ |
| 78 | |
| 79 | /** @cond SPECIALIZATIONS */ |
| 80 | BS_ALLOW_MEMCPY_SERIALIZATION(Degree); |
| 81 | /** @endcond */ |
| 82 | } |
| 83 |