]> git.tdb.fi Git - libs/math.git/blobdiff - source/geometry/angle.h
Use numeric literals in place of M_PI
[libs/math.git] / source / geometry / angle.h
index fbf6d061af0b9aef10b2f0cbb8b58e8b84ed8ac4..2d178d2235128f6e88a62d37fc00dfd8f0d09988 100644 (file)
@@ -20,22 +20,22 @@ private:
 public:
        Angle(): value(0) { }
        template<typename U>
-       Angle(const Angle<U> &other): value(other.value) { }
+       Angle(const Angle<U> &other): value(other.radians()) { }
 
        static Angle from_degrees(T);
        static Angle from_radians(T);
        static Angle from_turns(T);
 
        static Angle zero() { return from_radians(0); }
-       static Angle right() { return from_radians(M_PI/2); }
+       static Angle right() { return from_turns(0.25); }
        static Angle quarter_turn() { return right(); }
-       static Angle straight() { return from_radians(M_PI); }
+       static Angle straight() { return from_turns(0.5); }
        static Angle half_turn() { return straight(); }
-       static Angle full_turn() { return from_radians(2*M_PI); }
+       static Angle full_turn() { return from_turns(1); }
 
-       T degrees() const { return value*180/M_PI; }
+       T degrees() const { return value*57.2957795130823208768; }
        T radians() const { return value; }
-       T turns() const { return value/(2*M_PI); }
+       T turns() const { return value/6.28318530717958647692; }
 
        Angle &operator+=(const Angle &);
        Angle &operator-=(const Angle &);
@@ -57,7 +57,7 @@ public:
 template<typename T>
 inline Angle<T> Angle<T>::from_degrees(T d)
 {
-       return Angle<T>(d*M_PI/180);
+       return Angle<T>(d/57.2957795130823208768);
 }
 
 template<typename T>
@@ -69,7 +69,7 @@ inline Angle<T> Angle<T>::from_radians(T r)
 template<typename T>
 inline Angle<T> Angle<T>::from_turns(T t)
 {
-       return Angle<T>(t*2*M_PI);
+       return Angle<T>(t*6.28318530717958647692);
 }
 
 template<typename T>
@@ -155,10 +155,11 @@ inline T operator/(const Angle<T> &a1, const Angle<T> &a2)
 template<typename T>
 inline Angle<T> &Angle<T>::wrap_with_base(const Angle<T> &b)
 {
+       const float two_pi = 6.28318530717958647692;
        while(value<b.value)
-               value += 2*M_PI;
-       while(value>=b.value+2*M_PI)
-               value -= 2*M_PI;
+               value += two_pi;
+       while(value>=b.value+two_pi)
+               value -= two_pi;
        return *this;
 }