From: Mikko Rasa Date: Fri, 16 Sep 2016 22:38:05 +0000 (+0300) Subject: Use numeric literals in place of M_PI X-Git-Url: http://git.tdb.fi/?p=libs%2Fmath.git;a=commitdiff_plain;h=540bea4f0254725c003c73f7340c1d48ac0c86f5 Use numeric literals in place of M_PI Recent Windows headers require _USE_MATH_DEFINES to be #defined in order to #define M_PI, but we can't guarantee that someone else won't #include before us. --- diff --git a/source/geometry/angle.h b/source/geometry/angle.h index 207a5a2..2d178d2 100644 --- a/source/geometry/angle.h +++ b/source/geometry/angle.h @@ -27,15 +27,15 @@ public: 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 inline Angle Angle::from_degrees(T d) { - return Angle(d*M_PI/180); + return Angle(d/57.2957795130823208768); } template @@ -69,7 +69,7 @@ inline Angle Angle::from_radians(T r) template inline Angle Angle::from_turns(T t) { - return Angle(t*2*M_PI); + return Angle(t*6.28318530717958647692); } template @@ -155,10 +155,11 @@ inline T operator/(const Angle &a1, const Angle &a2) template inline Angle &Angle::wrap_with_base(const Angle &b) { + const float two_pi = 6.28318530717958647692; 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; }