mMathFn.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _MMATHFN_H_
  23. #define _MMATHFN_H_
  24. #ifndef _PLATFORM_H_
  25. #include "platform/platform.h"
  26. #endif
  27. #ifndef _MCONSTANTS_H_
  28. #include "math/mConstants.h"
  29. #endif
  30. #include <math.h>
  31. // Remove a couple of annoying macros, if they are present (In VC 6, they are.)
  32. #ifdef min
  33. #undef min
  34. #endif
  35. #ifdef max
  36. #undef max
  37. #endif
  38. class MatrixF;
  39. class PlaneF;
  40. extern void MathConsoleInit();
  41. //--------------------------------------
  42. // Installable Library Prototypes
  43. extern S32 (*m_mulDivS32)(S32 a, S32 b, S32 c);
  44. extern U32 (*m_mulDivU32)(S32 a, S32 b, U32 c);
  45. extern F32 (*m_catmullrom)(F32 t, F32 p0, F32 p1, F32 p2, F32 p3);
  46. extern void (*m_point2F_normalize)(F32 *p);
  47. extern void (*m_point2F_normalize_f)(F32 *p, F32 len);
  48. extern void (*m_point2D_normalize)(F64 *p);
  49. extern void (*m_point2D_normalize_f)(F64 *p, F64 len);
  50. extern void (*m_point3F_normalize)(F32 *p);
  51. extern void (*m_point3F_normalize_f)(F32 *p, F32 len);
  52. extern void (*m_point3F_interpolate)(const F32 *from, const F32 *to, F32 factor, F32 *result);
  53. extern void (*m_point3D_normalize)(F64 *p);
  54. extern void (*m_point3D_normalize_f)(F64 *p, F64 len);
  55. extern void (*m_point3D_interpolate)(const F64 *from, const F64 *to, F64 factor, F64 *result);
  56. extern void (*m_point3F_bulk_dot)(const F32* refVector,
  57. const F32* dotPoints,
  58. const U32 numPoints,
  59. const U32 pointStride,
  60. F32* output);
  61. extern void (*m_point3F_bulk_dot_indexed)(const F32* refVector,
  62. const F32* dotPoints,
  63. const U32 numPoints,
  64. const U32 pointStride,
  65. const U32* pointIndices,
  66. F32* output);
  67. extern void (*m_quatF_set_matF)( F32 x, F32 y, F32 z, F32 w, F32* m );
  68. extern void (*m_matF_set_euler)(const F32 *e, F32 *result);
  69. extern void (*m_matF_set_euler_point)(const F32 *e, const F32 *p, F32 *result);
  70. extern void (*m_matF_identity)(F32 *m);
  71. extern void (*m_matF_inverse)(F32 *m);
  72. extern void (*m_matF_affineInverse)(F32 *m);
  73. extern void (*m_matF_transpose)(F32 *m);
  74. extern void (*m_matF_scale)(F32 *m,const F32* p);
  75. extern void (*m_matF_normalize)(F32 *m);
  76. extern F32 (*m_matF_determinant)(const F32 *m);
  77. extern void (*m_matF_x_matF)(const F32 *a, const F32 *b, F32 *mresult);
  78. // extern void (*m_matF_x_point3F)(const F32 *m, const F32 *p, F32 *presult);
  79. // extern void (*m_matF_x_vectorF)(const F32 *m, const F32 *v, F32 *vresult);
  80. extern void (*m_matF_x_point4F)(const F32 *m, const F32 *p, F32 *presult);
  81. extern void (*m_matF_x_scale_x_planeF)(const F32 *m, const F32* s, const F32 *p, F32 *presult);
  82. extern void (*m_matF_x_box3F)(const F32 *m, F32 *min, F32 *max);
  83. // Note that x must point to at least 4 values for quartics, and 3 for cubics
  84. extern U32 (*mSolveQuadratic)(F32 a, F32 b, F32 c, F32* x);
  85. extern U32 (*mSolveCubic)(F32 a, F32 b, F32 c, F32 d, F32* x);
  86. extern U32 (*mSolveQuartic)(F32 a, F32 b, F32 c, F32 d, F32 e, F32* x);
  87. extern S32 mRandI(S32 i1, S32 i2); // random # from i1 to i2 inclusive
  88. extern F32 mRandF(F32 f1, F32 f2); // random # from f1 to f2 inclusive
  89. inline void m_matF_x_point3F(const F32 *m, const F32 *p, F32 *presult)
  90. {
  91. AssertFatal(p != presult, "Error, aliasing matrix mul pointers not allowed here!");
  92. #if defined(TORQUE_SUPPORTS_GCC_INLINE_X86_ASM)
  93. // inline assembly version because gcc's math optimization isn't as good
  94. // JMQ: the profiler shows that with g++ 2.96, the difference
  95. // between the asm and optimized c versions is minimal.
  96. int u0, u1, u2;
  97. __asm__ __volatile__ (
  98. "flds 0x8(%%eax)\n"
  99. "fmuls 0x8(%%ecx)\n"
  100. "flds 0x4(%%eax)\n"
  101. "fmuls 0x4(%%ecx)\n"
  102. "faddp %%st,%%st(1)\n"
  103. "flds (%%eax)\n"
  104. "fmuls (%%ecx)\n"
  105. "faddp %%st,%%st(1)\n"
  106. "fadds 0xc(%%eax)\n"
  107. "fstps (%%edx)\n"
  108. "flds 0x18(%%eax)\n"
  109. "fmuls 0x8(%%ecx)\n"
  110. "flds 0x10(%%eax)\n"
  111. "fmuls (%%ecx)\n"
  112. "faddp %%st,%%st(1)\n"
  113. "flds 0x14(%%eax)\n"
  114. "fmuls 0x4(%%ecx)\n"
  115. "faddp %%st,%%st(1)\n"
  116. "fadds 0x1c(%%eax)\n"
  117. "fstps 0x4(%%edx)\n"
  118. "flds 0x28(%%eax)\n"
  119. "fmuls 0x8(%%ecx)\n"
  120. "flds 0x20(%%eax)\n"
  121. "fmuls (%%ecx)\n"
  122. "faddp %%st,%%st(1)\n"
  123. "flds 0x24(%%eax)\n"
  124. "fmuls 0x4(%%ecx)\n"
  125. "faddp %%st,%%st(1)\n"
  126. "fadds 0x2c(%%eax)\n"
  127. "fstps 0x8(%%edx)\n"
  128. : "=&a" (u0), "=&c" (u1), "=&d" (u2)
  129. : "0" (m), "1" (p), "2" (presult)
  130. : "memory" );
  131. #else
  132. presult[0] = m[0]*p[0] + m[1]*p[1] + m[2]*p[2] + m[3];
  133. presult[1] = m[4]*p[0] + m[5]*p[1] + m[6]*p[2] + m[7];
  134. presult[2] = m[8]*p[0] + m[9]*p[1] + m[10]*p[2] + m[11];
  135. #endif
  136. }
  137. //--------------------------------------
  138. inline void m_matF_x_vectorF(const F32 *m, const F32 *v, F32 *vresult)
  139. {
  140. AssertFatal(v != vresult, "Error, aliasing matrix mul pointers not allowed here!");
  141. #if defined(TORQUE_SUPPORTS_GCC_INLINE_X86_ASM)
  142. // inline assembly version because gcc's math optimization isn't as good
  143. // JMQ: the profiler shows that with g++ 2.96, the difference
  144. // between the asm and optimized c versions is minimal.
  145. int u0, u1, u2;
  146. __asm__ __volatile__ (
  147. "flds 0x8(%%ecx)\n"
  148. "fmuls 0x8(%%eax)\n"
  149. "flds 0x4(%%ecx)\n"
  150. "fmuls 0x4(%%eax)\n"
  151. "faddp %%st,%%st(1)\n"
  152. "flds (%%ecx)\n"
  153. "fmuls (%%eax)\n"
  154. "faddp %%st,%%st(1)\n"
  155. "fstps (%%edx)\n"
  156. "flds 0x18(%%ecx)\n"
  157. "fmuls 0x8(%%eax)\n"
  158. "flds 0x10(%%ecx)\n"
  159. "fmuls (%%eax)\n"
  160. "faddp %%st,%%st(1)\n"
  161. "flds 0x14(%%ecx)\n"
  162. "fmuls 0x4(%%eax)\n"
  163. "faddp %%st,%%st(1)\n"
  164. "fstps 0x4(%%edx)\n"
  165. "flds 0x28(%%ecx)\n"
  166. "fmuls 0x8(%%eax)\n"
  167. "flds 0x20(%%ecx)\n"
  168. "fmuls (%%eax)\n"
  169. "faddp %%st,%%st(1)\n"
  170. "flds 0x24(%%ecx)\n"
  171. "fmuls 0x4(%%eax)\n"
  172. "faddp %%st,%%st(1)\n"
  173. "fstps 0x8(%%edx)\n"
  174. : "=&c" (u0), "=&a" (u1), "=&d" (u2)
  175. : "0" (m), "1" (v), "2" (vresult)
  176. : "memory" );
  177. #else
  178. vresult[0] = m[0]*v[0] + m[1]*v[1] + m[2]*v[2];
  179. vresult[1] = m[4]*v[0] + m[5]*v[1] + m[6]*v[2];
  180. vresult[2] = m[8]*v[0] + m[9]*v[1] + m[10]*v[2];
  181. #endif
  182. }
  183. U32 getNextPow2(U32 io_num);
  184. U32 getBinLog2(U32 io_num);
  185. /// Determines if the given U32 is some 2^n
  186. /// @returns true if in_num is a power of two, otherwise false
  187. inline bool isPow2(const U32 in_num)
  188. {
  189. return (in_num == getNextPow2(in_num));
  190. }
  191. /// Returns the lesser of the two parameters: a & b.
  192. inline U32 getMin(U32 a, U32 b)
  193. {
  194. return a>b ? b : a;
  195. }
  196. /// Returns the lesser of the two parameters: a & b.
  197. inline U16 getMin(U16 a, U16 b)
  198. {
  199. return a>b ? b : a;
  200. }
  201. /// Returns the lesser of the two parameters: a & b.
  202. inline U8 getMin(U8 a, U8 b)
  203. {
  204. return a>b ? b : a;
  205. }
  206. /// Returns the lesser of the two parameters: a & b.
  207. inline S32 getMin(S32 a, S32 b)
  208. {
  209. return a>b ? b : a;
  210. }
  211. /// Returns the lesser of the two parameters: a & b.
  212. inline S16 getMin(S16 a, S16 b)
  213. {
  214. return a>b ? b : a;
  215. }
  216. /// Returns the lesser of the two parameters: a & b.
  217. inline S8 getMin(S8 a, S8 b)
  218. {
  219. return a>b ? b : a;
  220. }
  221. /// Returns the lesser of the two parameters: a & b.
  222. inline float getMin(float a, float b)
  223. {
  224. return a>b ? b : a;
  225. }
  226. /// Returns the lesser of the two parameters: a & b.
  227. inline double getMin(double a, double b)
  228. {
  229. return a>b ? b : a;
  230. }
  231. /// Returns the greater of the two parameters: a & b.
  232. inline U32 getMax(U32 a, U32 b)
  233. {
  234. return a>b ? a : b;
  235. }
  236. /// Returns the greater of the two parameters: a & b.
  237. inline U16 getMax(U16 a, U16 b)
  238. {
  239. return a>b ? a : b;
  240. }
  241. /// Returns the greater of the two parameters: a & b.
  242. inline U8 getMax(U8 a, U8 b)
  243. {
  244. return a>b ? a : b;
  245. }
  246. /// Returns the greater of the two parameters: a & b.
  247. inline S32 getMax(S32 a, S32 b)
  248. {
  249. return a>b ? a : b;
  250. }
  251. /// Returns the greater of the two parameters: a & b.
  252. inline S16 getMax(S16 a, S16 b)
  253. {
  254. return a>b ? a : b;
  255. }
  256. /// Returns the greater of the two parameters: a & b.
  257. inline S8 getMax(S8 a, S8 b)
  258. {
  259. return a>b ? a : b;
  260. }
  261. /// Returns the greater of the two parameters: a & b.
  262. inline float getMax(float a, float b)
  263. {
  264. return a>b ? a : b;
  265. }
  266. /// Returns the greater of the two parameters: a & b.
  267. inline double getMax(double a, double b)
  268. {
  269. return a>b ? a : b;
  270. }
  271. inline F32 mFloor(const F32 val)
  272. {
  273. return (F32) floor(val);
  274. }
  275. inline F32 mCeil(const F32 val)
  276. {
  277. return (F32) ceil(val);
  278. }
  279. inline F32 mFabs(const F32 val)
  280. {
  281. return (F32) fabs(val);
  282. }
  283. inline F32 mFmod(const F32 val, const F32 mod)
  284. {
  285. return (F32) fmod(val, mod);
  286. }
  287. inline S32 mAbs(const S32 val)
  288. {
  289. // Kinda lame, and disallows intrinsic inlining by the compiler. Maybe fix?
  290. // DMM
  291. if (val < 0)
  292. return -val;
  293. return val;
  294. }
  295. inline S32 mClamp(S32 val, S32 low, S32 high)
  296. {
  297. return getMax(getMin(val, high), low);
  298. }
  299. inline F32 mClampF(F32 val, F32 low, F32 high)
  300. {
  301. return (F32) getMax(getMin(val, high), low);
  302. }
  303. inline S32 mMulDiv(S32 a, S32 b, S32 c)
  304. {
  305. return m_mulDivS32(a, b, c);
  306. }
  307. inline U32 mMulDiv(S32 a, S32 b, U32 c)
  308. {
  309. return m_mulDivU32(a, b, c);
  310. }
  311. inline F32 mSin(const F32 angle)
  312. {
  313. return (F32) sin(angle);
  314. }
  315. inline F32 mCos(const F32 angle)
  316. {
  317. return (F32) cos(angle);
  318. }
  319. inline F32 mTan(const F32 angle)
  320. {
  321. return (F32) tan(angle);
  322. }
  323. inline F32 mAsin(const F32 val)
  324. {
  325. return (F32) asin(val);
  326. }
  327. inline F32 mAcos(const F32 val)
  328. {
  329. return (F32) acos(val);
  330. }
  331. inline F32 mAtan(const F32 x, const F32 y)
  332. {
  333. return (F32) atan2(x, y);
  334. }
  335. inline void mSinCos(const F32 angle, F32 &s, F32 &c)
  336. {
  337. s = mSin(angle);
  338. c = mCos(angle);
  339. }
  340. inline F32 mTanh(const F32 angle)
  341. {
  342. return (F32) tanh(angle);
  343. }
  344. inline F32 mSqrt(const F32 val)
  345. {
  346. return (F32) sqrt(val);
  347. }
  348. inline F32 mPow(const F32 x, const F32 y)
  349. {
  350. return (F32) pow(x, y);
  351. }
  352. inline F32 mLog(const F32 val)
  353. {
  354. return (F32) log(val);
  355. }
  356. inline F64 mSin(const F64 angle)
  357. {
  358. return (F64) sin(angle);
  359. }
  360. inline F64 mCos(const F64 angle)
  361. {
  362. return (F64) cos(angle);
  363. }
  364. inline F64 mTan(const F64 angle)
  365. {
  366. return (F64) tan(angle);
  367. }
  368. inline F64 mAsin(const F64 val)
  369. {
  370. return (F64) asin(val);
  371. }
  372. inline F64 mAcos(const F64 val)
  373. {
  374. return (F64) acos(val);
  375. }
  376. inline F64 mAtan(const F64 x, const F64 y)
  377. {
  378. return (F64) atan2(x, y);
  379. }
  380. inline void mSinCos(const F64 angle, F64 &sin, F64 &cos)
  381. {
  382. sin = mSin(angle);
  383. cos = mCos(angle);
  384. }
  385. inline F64 mTanh(const F64 angle)
  386. {
  387. return (F64) tanh(angle);
  388. }
  389. inline F64 mPow(const F64 x, const F64 y)
  390. {
  391. return (F64) pow(x, y);
  392. }
  393. inline F64 mLog(const F64 val)
  394. {
  395. return (F64) log(val);
  396. }
  397. inline F32 mCatmullrom(F32 t, F32 p0, F32 p1, F32 p2, F32 p3)
  398. {
  399. return m_catmullrom(t, p0, p1, p2, p3);
  400. }
  401. inline F64 mFabsD(const F64 val)
  402. {
  403. return (F64) fabs(val);
  404. }
  405. inline F64 mFmodD(const F64 val, const F64 mod)
  406. {
  407. return (F64) fmod(val, mod);
  408. }
  409. inline F64 mSqrtD(const F64 val)
  410. {
  411. return (F64) sqrt(val);
  412. }
  413. inline F64 mFloorD(const F64 val)
  414. {
  415. return (F64) floor(val);
  416. }
  417. inline F64 mCeilD(const F64 val)
  418. {
  419. return (F64) ceil(val);
  420. }
  421. inline bool isEqual(F32 a, F32 b)
  422. {
  423. return mFabs(a - b) < __EQUAL_CONST_F;
  424. }
  425. inline bool isZero(F32 a)
  426. {
  427. return mFabs(a) < __EQUAL_CONST_F;
  428. }
  429. //--------------------------------------
  430. #ifndef _MPOINT_H_
  431. #include "math/mPoint.h"
  432. #endif
  433. inline F32 mDot(const Point2F &p1, const Point2F &p2)
  434. {
  435. return (p1.x*p2.x + p1.y*p2.y);
  436. }
  437. inline F32 mDot(const Point3F &p1, const Point3F &p2)
  438. {
  439. return (p1.x*p2.x + p1.y*p2.y + p1.z*p2.z);
  440. }
  441. inline void mCross(const Point3F &a, const Point3F &b, Point3F *res)
  442. {
  443. res->x = (a.y * b.z) - (a.z * b.y);
  444. res->y = (a.z * b.x) - (a.x * b.z);
  445. res->z = (a.x * b.y) - (a.y * b.x);
  446. }
  447. inline F64 mDot(const Point3D &p1, const Point3D &p2)
  448. {
  449. return (p1.x*p2.x + p1.y*p2.y + p1.z*p2.z);
  450. }
  451. inline void mCross(const Point3D &a, const Point3D &b, Point3D *res)
  452. {
  453. res->x = (a.y * b.z) - (a.z * b.y);
  454. res->y = (a.z * b.x) - (a.x * b.z);
  455. res->z = (a.x * b.y) - (a.y * b.x);
  456. }
  457. inline Point3F mCross(const Point3F &a, const Point3F &b)
  458. {
  459. Point3F ret;
  460. mCross(a,b,&ret);
  461. return ret;
  462. }
  463. inline void mCross(const F32* a, const F32* b, F32 *res)
  464. {
  465. res[0] = (a[1] * b[2]) - (a[2] * b[1]);
  466. res[1] = (a[2] * b[0]) - (a[0] * b[2]);
  467. res[2] = (a[0] * b[1]) - (a[1] * b[0]);
  468. }
  469. inline void mCross(const F64* a, const F64* b, F64* res)
  470. {
  471. res[0] = (a[1] * b[2]) - (a[2] * b[1]);
  472. res[1] = (a[2] * b[0]) - (a[0] * b[2]);
  473. res[2] = (a[0] * b[1]) - (a[1] * b[0]);
  474. }
  475. void mTransformPlane(const MatrixF& mat, const Point3F& scale, const PlaneF& plane, PlaneF* result);
  476. //--------------------------------------
  477. inline F32 mDegToRad(F32 d)
  478. {
  479. return F32((d * M_PI) / F32(180));
  480. }
  481. inline F32 mRadToDeg(F32 r)
  482. {
  483. return F32((r * 180.0) / M_PI);
  484. }
  485. inline F64 mDegToRad(F64 d)
  486. {
  487. return (d * M_PI) / F64(180);
  488. }
  489. inline F64 mRadToDeg(F64 r)
  490. {
  491. return (r * 180.0) / M_PI;
  492. }
  493. /// Get an angle flipping the Y (along the X axis).
  494. inline F32 mGetFlippedXAngle( const F32 radians )
  495. {
  496. return mAtan(-mSin(radians), mCos(radians));
  497. }
  498. /// Get an angle flipping the Y (along the X axis).
  499. inline F32 mGetFlippedYAngle( const F32 radians )
  500. {
  501. return mAtan(mSin(radians), -mCos(radians));
  502. }
  503. /// Precision Rounding.
  504. inline F32 mRound(const F32& value, const F32 epsilon = 0.5f) { return value > 0.0f ? mFloor(value + epsilon) : mCeil(value - epsilon); }
  505. /// Is NAN?
  506. inline F32 mIsNAN(const F32& value) { return (value != value); }
  507. /// Tolerate Is Zero?
  508. inline bool mIsZero(const F32& value) { return mFabs(value) < FLT_EPSILON; }
  509. /// Tolerate Not Zero?
  510. inline bool mNotZero(const F32& value) { return !mIsZero(value); }
  511. /// Tolerate Less-Than?
  512. inline bool mLessThan(const F32& a, const F32& b) { return a < b; }
  513. /// Tolerate Greater-Than?
  514. inline bool mGreaterThan(const F32& a, const F32& b) { return a > b; }
  515. /// Safe Less Than Zero?
  516. inline bool mLessThanZero(const F32& value) { return mLessThan(value, 0.0f); }
  517. /// Safe Greater Than Zero?
  518. inline bool mGreaterThanZero(const F32& value) { return mGreaterThan(value, 0.0f); }
  519. /// Safe Is Equal?
  520. inline bool mIsEqual(const F32& a, const F32& b) { return mIsZero(mFabs(a-b)); }
  521. /// Safe Not Equal?
  522. inline bool mNotEqual(const F32& a, const F32& b) { return !mIsEqual(a,b); }
  523. /// Tolerate Is Equal within Range?
  524. inline bool mIsEqualRange(const F32& a, const F32& b, const F32 epsilon = FLT_EPSILON) { return mFabs(a-b) <= epsilon; }
  525. /// Tolerate Is One?
  526. inline bool mIsOne(const F32& value) { return mIsEqual(value, 1.0f); }
  527. /// Tolerate Less-Than or Equal?
  528. inline bool mLessThanOrEqual(const F32& a, const F32& b) { return ( (a < b) || (!(a>b) && mIsEqual(a,b)) ); }
  529. /// Tolerate Greater-Than or Equal?
  530. inline bool mGreaterThanOrEqual(const F32&a, const F32& b) { return ( (a > b) || (!(a < b) && mIsEqual(a,b)) ); }
  531. /// Get Min/Max.
  532. inline void mGetMinMax(const F32& a, const F32& b, F32& min, F32& max) { if ( mGreaterThan(a,b) ) { max = a; min = b; } else { max = b; min = a; } }
  533. /// Swap.
  534. inline void mSwap(F32& a, F32& b) { F32 temp = b; b = a; a = temp; }
  535. #endif //_MMATHFN_H_