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
8namespace bs
9{
10 class Degree;
11
12 /** @addtogroup Math
13 * @{
14 */
15
16 /**
17 * Wrapper class which indicates a given angle value is in radians.
18 *
19 * @note
20 * Radian values are interchangeable with Degree values, and conversions will be done automatically between them.
21 */
22 class BS_UTILITY_EXPORT Radian
23 {
24 public:
25 constexpr Radian() = default;
26 constexpr Radian(const Radian&) = default;
27 constexpr Radian& operator= (const Radian&) = default;
28
29 constexpr explicit Radian(float r) : mRad(r) {}
30 constexpr Radian& operator= (const float& f) { mRad = f; return *this; }
31
32 Radian(const Degree& d);
33 Radian& operator= (const Degree& d);
34
35 /** Returns the value of the angle in degrees. */
36 float valueDegrees() const;
37
38 /** Returns the value of the angle in radians. */
39 constexpr float valueRadians() const { return mRad; }
40
41 /** Wraps the angle in [0, 2 * PI) range. */
42 Radian wrap();
43
44 const Radian& operator+ () const { return *this; }
45 Radian operator+ (const Radian& r) const { return Radian (mRad + r.mRad); }
46 Radian operator+ (const Degree& d) const;
47 Radian& operator+= (const Radian& r) { mRad += r.mRad; return *this; }
48 Radian& operator+= (const Degree& d);
49 Radian operator- () const { return Radian(-mRad); }
50 Radian operator- (const Radian& r) const { return Radian (mRad - r.mRad); }
51 Radian operator- (const Degree& d) const;
52 Radian& operator-= (const Radian& r) { mRad -= r.mRad; return *this; }
53 Radian& operator-= (const Degree& d);
54 Radian operator* (float f) const { return Radian (mRad * f); }
55 Radian operator* (const Radian& f) const { return Radian (mRad * f.mRad); }
56 Radian& operator*= (float f) { mRad *= f; return *this; }
57 Radian operator/ (float f) const { return Radian (mRad / f); }
58 Radian& operator/= (float f) { mRad /= f; return *this; }
59
60 friend Radian operator* (float lhs, const Radian& rhs) { return Radian(lhs * rhs.mRad); }
61 friend Radian operator/ (float lhs, const Radian& rhs) { return Radian(lhs / rhs.mRad); }
62 friend Radian operator+ (Radian& lhs, float rhs) { return Radian(lhs.mRad + rhs); }
63 friend Radian operator+ (float lhs, const Radian& rhs) { return Radian(lhs + rhs.mRad); }
64 friend Radian operator- (const Radian& lhs, float rhs) { return Radian(lhs.mRad - rhs); }
65 friend Radian operator- (const float lhs, const Radian& rhs) { return Radian(lhs - rhs.mRad); }
66
67 bool operator< (const Radian& r) const { return mRad < r.mRad; }
68 bool operator<= (const Radian& r) const { return mRad <= r.mRad; }
69 bool operator== (const Radian& r) const { return mRad == r.mRad; }
70 bool operator!= (const Radian& r) const { return mRad != r.mRad; }
71 bool operator>= (const Radian& r) const { return mRad >= r.mRad; }
72 bool operator> (const Radian& r) const { return mRad > r.mRad; }
73
74 private:
75 float mRad = 0.0f;
76 };
77
78 /** @} */
79
80 /** @cond SPECIALIZATIONS */
81 BS_ALLOW_MEMCPY_SERIALIZATION(Radian);
82 /** @endcond */
83}
84