72 inline float pi<float>()
78 inline float piDouble<float>()
84 inline float piHalf<float>()
90 inline float piQuart<float>()
96 inline float piSquare<float>()
103 inline double pi<double>()
105 return 3.14159265358979323846;
109 inline double piDouble<double>()
111 return 6.28318530717958647692;
115 inline double piHalf<double>()
117 return 1.57079632679489661923;
121 inline double piQuart<double>()
123 return 0.78539816339744830961;
127 inline double piSquare<double>()
129 return 9.86960440108935861883449099987615114;
133 static const float DegToRadF = 0.01745329f;
135 static const float RadToDegF = 57.2957795f;
137 static const double DegToRad = 0.0174532925199432957692;
139 static const double RadToDeg = 57.295779513082320876846364344191;
142 inline float degToRad(
float deg)
144 return deg * DegToRadF;
147 inline double degToRad(
double deg)
149 return deg * DegToRad;
153 inline float radToDeg(
float rad)
155 return rad * RadToDegF;
158 inline double radToDeg(
double rad)
160 return rad * RadToDeg;
169 template <
typename T>
174 assert(theta <= piDouble<T>());
177 T localTheta = theta;
179 if(localTheta > pi<T>())
181 localTheta -= piDouble<T>();
184 const T B = 4 / pi<T>();
185 const T C = -4 / piSquare<T>();
187 const T P =
static_cast<T
>(0.225);
189 T y = B * localTheta + C * localTheta * ::fabs(localTheta);
190 y = P * (y * std::fabs(y) - y) + y;
199 template <
typename T>
204 assert(theta <= piDouble<T>());
207 T sinTheta = theta + piHalf<T>();
209 if(sinTheta > piDouble<T>())
211 sinTheta -= piDouble<T>();
219 template <
typename T>
224 if(y > 0)
return piHalf<T>();
232 if(std::fabs(z) < 1.0)
234 atan = z / (
static_cast<T
>(1.0) +
static_cast<T
>(0.28) * z * z);
238 return y < 0 ? atan - pi<T>()
244 atan = piHalf<T>() - z / (z * z + static_cast<T>(0.28));
246 return atan - pi<T>();
252 inline float toPolar(
float x,
float y)
259 return radToDeg(
fastAtan2(y, x) ) + 360.0f;
262 template <
typename T>
265 return static_cast<T
>(1.0) / std::sqrt(x);
268 inline float invSqrtf(
float x)
270 return 1.0f / std::sqrt(x);
275 inline double hypot(
double x,
double y)
277 #if __cplusplus == 201103L
278 return std::hypot(x, y);
279 #elif defined(_MSC_VER) || defined(_WIN32_WCE) || defined(_WIN32)
282 return ::hypot(x, y);
291 #if __cplusplus >= 201103L
293 return std::lround(x);
295 #elif (_MSC_VER < 1800)
298 tmp += (x - tmp >= 0.5) - (x - tmp <= -0.5);
346 #if __cplusplus >= 201103L
348 return std::lround(x);
350 #elif (_MSC_VER < 1800)
353 tmp += (x - tmp >= 0.5) - (x - tmp <= -0.5);
double hypot(double x, double y)
Return the euclidean distance of the given values.
Definition: Math.h:275
T fastSin(const T &theta)
Fast, but less precise sine calculation.
Definition: Math.h:170
T piHalf()
The constant pi/2.
int_type int32_t
Signed 32-bit integer type.
Definition: Types.h:36
T piDouble()
The constant pi*2.
Pt::int32_t lround(float x)
Rounds to nearest integer value.
Definition: Math.h:289
T fastCos(const T &theta)
Fast, less precise cosine calculation.
Definition: Math.h:200
T fastAtan2(T y, T x)
Fast, but less precise atan2 calculation.
Definition: Math.h:220
T piQuart()
The constant pi/4.
T piSquare()
The constant pi^2.