The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

727 lines
17KB

  1. /*
  2. * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. * Permission is granted to anyone to use this software for any purpose,
  8. * including commercial applications, and to alter it and redistribute it
  9. * freely, subject to the following restrictions:
  10. * 1. The origin of this software must not be misrepresented; you must not
  11. * claim that you wrote the original software. If you use this software
  12. * in a product, an acknowledgment in the product documentation would be
  13. * appreciated but is not required.
  14. * 2. Altered source versions must be plainly marked as such, and must not be
  15. * misrepresented as being the original software.
  16. * 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #ifndef B2_MATH_H
  19. #define B2_MATH_H
  20. #include "b2Settings.h"
  21. /// This function is used to ensure that a floating point number is
  22. /// not a NaN or infinity.
  23. inline bool b2IsValid(float32 x)
  24. {
  25. if (x != x)
  26. {
  27. // NaN.
  28. return false;
  29. }
  30. float32 infinity = std::numeric_limits<float32>::infinity();
  31. return -infinity < x && x < infinity;
  32. }
  33. /// This is a approximate yet fast inverse square-root.
  34. inline float32 b2InvSqrt(float32 x)
  35. {
  36. union
  37. {
  38. float32 x;
  39. juce::int32 i;
  40. } convert;
  41. convert.x = x;
  42. float32 xhalf = 0.5f * x;
  43. convert.i = 0x5f3759df - (convert.i >> 1);
  44. x = convert.x;
  45. x = x * (1.5f - xhalf * x * x);
  46. return x;
  47. }
  48. #define b2Sqrt(x) std::sqrt(x)
  49. #define b2Atan2(y, x) std::atan2(y, x)
  50. /// A 2D column vector.
  51. struct b2Vec2
  52. {
  53. /// Default constructor does nothing (for performance).
  54. b2Vec2() {}
  55. /// Construct using coordinates.
  56. b2Vec2(float32 xCoord, float32 yCoord) : x(xCoord), y(yCoord) {}
  57. /// Set this vector to all zeros.
  58. void SetZero() { x = 0.0f; y = 0.0f; }
  59. /// Set this vector to some specified coordinates.
  60. void Set(float32 x_, float32 y_) { x = x_; y = y_; }
  61. /// Negate this vector.
  62. b2Vec2 operator -() const { b2Vec2 v; v.Set(-x, -y); return v; }
  63. /// Read from and indexed element.
  64. float32 operator () (juce::int32 i) const
  65. {
  66. return (&x)[i];
  67. }
  68. /// Write to an indexed element.
  69. float32& operator () (juce::int32 i)
  70. {
  71. return (&x)[i];
  72. }
  73. /// Add a vector to this vector.
  74. void operator += (const b2Vec2& v)
  75. {
  76. x += v.x; y += v.y;
  77. }
  78. /// Subtract a vector from this vector.
  79. void operator -= (const b2Vec2& v)
  80. {
  81. x -= v.x; y -= v.y;
  82. }
  83. /// Multiply this vector by a scalar.
  84. void operator *= (float32 a)
  85. {
  86. x *= a; y *= a;
  87. }
  88. /// Get the length of this vector (the norm).
  89. float32 Length() const
  90. {
  91. return b2Sqrt(x * x + y * y);
  92. }
  93. /// Get the length squared. For performance, use this instead of
  94. /// b2Vec2::Length (if possible).
  95. float32 LengthSquared() const
  96. {
  97. return x * x + y * y;
  98. }
  99. /// Convert this vector into a unit vector. Returns the length.
  100. float32 Normalize()
  101. {
  102. float32 length = Length();
  103. if (length < b2_epsilon)
  104. {
  105. return 0.0f;
  106. }
  107. float32 invLength = 1.0f / length;
  108. x *= invLength;
  109. y *= invLength;
  110. return length;
  111. }
  112. /// Does this vector contain finite coordinates?
  113. bool IsValid() const
  114. {
  115. return b2IsValid(x) && b2IsValid(y);
  116. }
  117. /// Get the skew vector such that dot(skew_vec, other) == cross(vec, other)
  118. b2Vec2 Skew() const
  119. {
  120. return b2Vec2(-y, x);
  121. }
  122. float32 x, y;
  123. };
  124. /// A 2D column vector with 3 elements.
  125. struct b2Vec3
  126. {
  127. /// Default constructor does nothing (for performance).
  128. b2Vec3() {}
  129. /// Construct using coordinates.
  130. b2Vec3(float32 xCoord, float32 yCoord, float32 zCoord) : x(xCoord), y(yCoord), z(zCoord) {}
  131. /// Set this vector to all zeros.
  132. void SetZero() { x = 0.0f; y = 0.0f; z = 0.0f; }
  133. /// Set this vector to some specified coordinates.
  134. void Set(float32 x_, float32 y_, float32 z_) { x = x_; y = y_; z = z_; }
  135. /// Negate this vector.
  136. b2Vec3 operator -() const { b2Vec3 v; v.Set(-x, -y, -z); return v; }
  137. /// Add a vector to this vector.
  138. void operator += (const b2Vec3& v)
  139. {
  140. x += v.x; y += v.y; z += v.z;
  141. }
  142. /// Subtract a vector from this vector.
  143. void operator -= (const b2Vec3& v)
  144. {
  145. x -= v.x; y -= v.y; z -= v.z;
  146. }
  147. /// Multiply this vector by a scalar.
  148. void operator *= (float32 s)
  149. {
  150. x *= s; y *= s; z *= s;
  151. }
  152. float32 x, y, z;
  153. };
  154. /// A 2-by-2 matrix. Stored in column-major order.
  155. struct b2Mat22
  156. {
  157. /// The default constructor does nothing (for performance).
  158. b2Mat22() {}
  159. /// Construct this matrix using columns.
  160. b2Mat22(const b2Vec2& c1, const b2Vec2& c2)
  161. {
  162. ex = c1;
  163. ey = c2;
  164. }
  165. /// Construct this matrix using scalars.
  166. b2Mat22(float32 a11, float32 a12, float32 a21, float32 a22)
  167. {
  168. ex.x = a11; ex.y = a21;
  169. ey.x = a12; ey.y = a22;
  170. }
  171. /// Initialize this matrix using columns.
  172. void Set(const b2Vec2& c1, const b2Vec2& c2)
  173. {
  174. ex = c1;
  175. ey = c2;
  176. }
  177. /// Set this to the identity matrix.
  178. void SetIdentity()
  179. {
  180. ex.x = 1.0f; ey.x = 0.0f;
  181. ex.y = 0.0f; ey.y = 1.0f;
  182. }
  183. /// Set this matrix to all zeros.
  184. void SetZero()
  185. {
  186. ex.x = 0.0f; ey.x = 0.0f;
  187. ex.y = 0.0f; ey.y = 0.0f;
  188. }
  189. b2Mat22 GetInverse() const
  190. {
  191. float32 a = ex.x, b = ey.x, c = ex.y, d = ey.y;
  192. b2Mat22 B;
  193. float32 det = a * d - b * c;
  194. if (det != 0.0f)
  195. {
  196. det = 1.0f / det;
  197. }
  198. B.ex.x = det * d; B.ey.x = -det * b;
  199. B.ex.y = -det * c; B.ey.y = det * a;
  200. return B;
  201. }
  202. /// Solve A * x = b, where b is a column vector. This is more efficient
  203. /// than computing the inverse in one-shot cases.
  204. b2Vec2 Solve(const b2Vec2& b) const
  205. {
  206. float32 a11 = ex.x, a12 = ey.x, a21 = ex.y, a22 = ey.y;
  207. float32 det = a11 * a22 - a12 * a21;
  208. if (det != 0.0f)
  209. {
  210. det = 1.0f / det;
  211. }
  212. b2Vec2 x;
  213. x.x = det * (a22 * b.x - a12 * b.y);
  214. x.y = det * (a11 * b.y - a21 * b.x);
  215. return x;
  216. }
  217. b2Vec2 ex, ey;
  218. };
  219. /// A 3-by-3 matrix. Stored in column-major order.
  220. struct b2Mat33
  221. {
  222. /// The default constructor does nothing (for performance).
  223. b2Mat33() {}
  224. /// Construct this matrix using columns.
  225. b2Mat33(const b2Vec3& c1, const b2Vec3& c2, const b2Vec3& c3)
  226. {
  227. ex = c1;
  228. ey = c2;
  229. ez = c3;
  230. }
  231. /// Set this matrix to all zeros.
  232. void SetZero()
  233. {
  234. ex.SetZero();
  235. ey.SetZero();
  236. ez.SetZero();
  237. }
  238. /// Solve A * x = b, where b is a column vector. This is more efficient
  239. /// than computing the inverse in one-shot cases.
  240. b2Vec3 Solve33(const b2Vec3& b) const;
  241. /// Solve A * x = b, where b is a column vector. This is more efficient
  242. /// than computing the inverse in one-shot cases. Solve only the upper
  243. /// 2-by-2 matrix equation.
  244. b2Vec2 Solve22(const b2Vec2& b) const;
  245. /// Get the inverse of this matrix as a 2-by-2.
  246. /// Returns the zero matrix if singular.
  247. void GetInverse22(b2Mat33* M) const;
  248. /// Get the symmetric inverse of this matrix as a 3-by-3.
  249. /// Returns the zero matrix if singular.
  250. void GetSymInverse33(b2Mat33* M) const;
  251. b2Vec3 ex, ey, ez;
  252. };
  253. /// Rotation
  254. struct b2Rot
  255. {
  256. b2Rot() {}
  257. /// Initialize from an angle in radians
  258. explicit b2Rot(float32 angle)
  259. {
  260. /// TODO_ERIN optimize
  261. s = sinf(angle);
  262. c = cosf(angle);
  263. }
  264. /// Set using an angle in radians.
  265. void Set(float32 angle)
  266. {
  267. /// TODO_ERIN optimize
  268. s = sinf(angle);
  269. c = cosf(angle);
  270. }
  271. /// Set to the identity rotation
  272. void SetIdentity()
  273. {
  274. s = 0.0f;
  275. c = 1.0f;
  276. }
  277. /// Get the angle in radians
  278. float32 GetAngle() const
  279. {
  280. return b2Atan2(s, c);
  281. }
  282. /// Get the x-axis
  283. b2Vec2 GetXAxis() const
  284. {
  285. return b2Vec2(c, s);
  286. }
  287. /// Get the u-axis
  288. b2Vec2 GetYAxis() const
  289. {
  290. return b2Vec2(-s, c);
  291. }
  292. /// Sine and cosine
  293. float32 s, c;
  294. };
  295. /// A transform contains translation and rotation. It is used to represent
  296. /// the position and orientation of rigid frames.
  297. struct b2Transform
  298. {
  299. /// The default constructor does nothing.
  300. b2Transform() {}
  301. /// Initialize using a position vector and a rotation.
  302. b2Transform(const b2Vec2& position, const b2Rot& rotation) : p(position), q(rotation) {}
  303. /// Set this to the identity transform.
  304. void SetIdentity()
  305. {
  306. p.SetZero();
  307. q.SetIdentity();
  308. }
  309. /// Set this based on the position and angle.
  310. void Set(const b2Vec2& position, float32 angle)
  311. {
  312. p = position;
  313. q.Set(angle);
  314. }
  315. b2Vec2 p;
  316. b2Rot q;
  317. };
  318. /// This describes the motion of a body/shape for TOI computation.
  319. /// Shapes are defined with respect to the body origin, which may
  320. /// no coincide with the center of mass. However, to support dynamics
  321. /// we must interpolate the center of mass position.
  322. struct b2Sweep
  323. {
  324. /// Get the interpolated transform at a specific time.
  325. /// @param beta is a factor in [0,1], where 0 indicates alpha0.
  326. void GetTransform(b2Transform* xfb, float32 beta) const;
  327. /// Advance the sweep forward, yielding a new initial state.
  328. /// @param alpha the new initial time.
  329. void Advance(float32 alpha);
  330. /// Normalize the angles.
  331. void Normalize();
  332. b2Vec2 localCenter; ///< local center of mass position
  333. b2Vec2 c0, c; ///< center world positions
  334. float32 a0, a; ///< world angles
  335. /// Fraction of the current time step in the range [0,1]
  336. /// c0 and a0 are the positions at alpha0.
  337. float32 alpha0;
  338. };
  339. /// Useful constant
  340. extern const b2Vec2 b2Vec2_zero;
  341. /// Perform the dot product on two vectors.
  342. inline float32 b2Dot(const b2Vec2& a, const b2Vec2& b)
  343. {
  344. return a.x * b.x + a.y * b.y;
  345. }
  346. /// Perform the cross product on two vectors. In 2D this produces a scalar.
  347. inline float32 b2Cross(const b2Vec2& a, const b2Vec2& b)
  348. {
  349. return a.x * b.y - a.y * b.x;
  350. }
  351. /// Perform the cross product on a vector and a scalar. In 2D this produces
  352. /// a vector.
  353. inline b2Vec2 b2Cross(const b2Vec2& a, float32 s)
  354. {
  355. return b2Vec2(s * a.y, -s * a.x);
  356. }
  357. /// Perform the cross product on a scalar and a vector. In 2D this produces
  358. /// a vector.
  359. inline b2Vec2 b2Cross(float32 s, const b2Vec2& a)
  360. {
  361. return b2Vec2(-s * a.y, s * a.x);
  362. }
  363. /// Multiply a matrix times a vector. If a rotation matrix is provided,
  364. /// then this transforms the vector from one frame to another.
  365. inline b2Vec2 b2Mul(const b2Mat22& A, const b2Vec2& v)
  366. {
  367. return b2Vec2(A.ex.x * v.x + A.ey.x * v.y, A.ex.y * v.x + A.ey.y * v.y);
  368. }
  369. /// Multiply a matrix transpose times a vector. If a rotation matrix is provided,
  370. /// then this transforms the vector from one frame to another (inverse transform).
  371. inline b2Vec2 b2MulT(const b2Mat22& A, const b2Vec2& v)
  372. {
  373. return b2Vec2(b2Dot(v, A.ex), b2Dot(v, A.ey));
  374. }
  375. /// Add two vectors component-wise.
  376. inline b2Vec2 operator + (const b2Vec2& a, const b2Vec2& b)
  377. {
  378. return b2Vec2(a.x + b.x, a.y + b.y);
  379. }
  380. /// Subtract two vectors component-wise.
  381. inline b2Vec2 operator - (const b2Vec2& a, const b2Vec2& b)
  382. {
  383. return b2Vec2(a.x - b.x, a.y - b.y);
  384. }
  385. inline b2Vec2 operator * (float32 s, const b2Vec2& a)
  386. {
  387. return b2Vec2(s * a.x, s * a.y);
  388. }
  389. inline bool operator == (const b2Vec2& a, const b2Vec2& b)
  390. {
  391. return a.x == b.x && a.y == b.y;
  392. }
  393. inline float32 b2Distance(const b2Vec2& a, const b2Vec2& b)
  394. {
  395. b2Vec2 c = a - b;
  396. return c.Length();
  397. }
  398. inline float32 b2DistanceSquared(const b2Vec2& a, const b2Vec2& b)
  399. {
  400. b2Vec2 c = a - b;
  401. return b2Dot(c, c);
  402. }
  403. inline b2Vec3 operator * (float32 s, const b2Vec3& a)
  404. {
  405. return b2Vec3(s * a.x, s * a.y, s * a.z);
  406. }
  407. /// Add two vectors component-wise.
  408. inline b2Vec3 operator + (const b2Vec3& a, const b2Vec3& b)
  409. {
  410. return b2Vec3(a.x + b.x, a.y + b.y, a.z + b.z);
  411. }
  412. /// Subtract two vectors component-wise.
  413. inline b2Vec3 operator - (const b2Vec3& a, const b2Vec3& b)
  414. {
  415. return b2Vec3(a.x - b.x, a.y - b.y, a.z - b.z);
  416. }
  417. /// Perform the dot product on two vectors.
  418. inline float32 b2Dot(const b2Vec3& a, const b2Vec3& b)
  419. {
  420. return a.x * b.x + a.y * b.y + a.z * b.z;
  421. }
  422. /// Perform the cross product on two vectors.
  423. inline b2Vec3 b2Cross(const b2Vec3& a, const b2Vec3& b)
  424. {
  425. return b2Vec3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
  426. }
  427. inline b2Mat22 operator + (const b2Mat22& A, const b2Mat22& B)
  428. {
  429. return b2Mat22(A.ex + B.ex, A.ey + B.ey);
  430. }
  431. // A * B
  432. inline b2Mat22 b2Mul(const b2Mat22& A, const b2Mat22& B)
  433. {
  434. return b2Mat22(b2Mul(A, B.ex), b2Mul(A, B.ey));
  435. }
  436. // A^T * B
  437. inline b2Mat22 b2MulT(const b2Mat22& A, const b2Mat22& B)
  438. {
  439. b2Vec2 c1(b2Dot(A.ex, B.ex), b2Dot(A.ey, B.ex));
  440. b2Vec2 c2(b2Dot(A.ex, B.ey), b2Dot(A.ey, B.ey));
  441. return b2Mat22(c1, c2);
  442. }
  443. /// Multiply a matrix times a vector.
  444. inline b2Vec3 b2Mul(const b2Mat33& A, const b2Vec3& v)
  445. {
  446. return v.x * A.ex + v.y * A.ey + v.z * A.ez;
  447. }
  448. /// Multiply a matrix times a vector.
  449. inline b2Vec2 b2Mul22(const b2Mat33& A, const b2Vec2& v)
  450. {
  451. return b2Vec2(A.ex.x * v.x + A.ey.x * v.y, A.ex.y * v.x + A.ey.y * v.y);
  452. }
  453. /// Multiply two rotations: q * r
  454. inline b2Rot b2Mul(const b2Rot& q, const b2Rot& r)
  455. {
  456. // [qc -qs] * [rc -rs] = [qc*rc-qs*rs -qc*rs-qs*rc]
  457. // [qs qc] [rs rc] [qs*rc+qc*rs -qs*rs+qc*rc]
  458. // s = qs * rc + qc * rs
  459. // c = qc * rc - qs * rs
  460. b2Rot qr;
  461. qr.s = q.s * r.c + q.c * r.s;
  462. qr.c = q.c * r.c - q.s * r.s;
  463. return qr;
  464. }
  465. /// Transpose multiply two rotations: qT * r
  466. inline b2Rot b2MulT(const b2Rot& q, const b2Rot& r)
  467. {
  468. // [ qc qs] * [rc -rs] = [qc*rc+qs*rs -qc*rs+qs*rc]
  469. // [-qs qc] [rs rc] [-qs*rc+qc*rs qs*rs+qc*rc]
  470. // s = qc * rs - qs * rc
  471. // c = qc * rc + qs * rs
  472. b2Rot qr;
  473. qr.s = q.c * r.s - q.s * r.c;
  474. qr.c = q.c * r.c + q.s * r.s;
  475. return qr;
  476. }
  477. /// Rotate a vector
  478. inline b2Vec2 b2Mul(const b2Rot& q, const b2Vec2& v)
  479. {
  480. return b2Vec2(q.c * v.x - q.s * v.y, q.s * v.x + q.c * v.y);
  481. }
  482. /// Inverse rotate a vector
  483. inline b2Vec2 b2MulT(const b2Rot& q, const b2Vec2& v)
  484. {
  485. return b2Vec2(q.c * v.x + q.s * v.y, -q.s * v.x + q.c * v.y);
  486. }
  487. inline b2Vec2 b2Mul(const b2Transform& T, const b2Vec2& v)
  488. {
  489. float32 x = (T.q.c * v.x - T.q.s * v.y) + T.p.x;
  490. float32 y = (T.q.s * v.x + T.q.c * v.y) + T.p.y;
  491. return b2Vec2(x, y);
  492. }
  493. inline b2Vec2 b2MulT(const b2Transform& T, const b2Vec2& v)
  494. {
  495. float32 px = v.x - T.p.x;
  496. float32 py = v.y - T.p.y;
  497. float32 x = (T.q.c * px + T.q.s * py);
  498. float32 y = (-T.q.s * px + T.q.c * py);
  499. return b2Vec2(x, y);
  500. }
  501. // v2 = A.q.Rot(B.q.Rot(v1) + B.p) + A.p
  502. // = (A.q * B.q).Rot(v1) + A.q.Rot(B.p) + A.p
  503. inline b2Transform b2Mul(const b2Transform& A, const b2Transform& B)
  504. {
  505. b2Transform C;
  506. C.q = b2Mul(A.q, B.q);
  507. C.p = b2Mul(A.q, B.p) + A.p;
  508. return C;
  509. }
  510. // v2 = A.q' * (B.q * v1 + B.p - A.p)
  511. // = A.q' * B.q * v1 + A.q' * (B.p - A.p)
  512. inline b2Transform b2MulT(const b2Transform& A, const b2Transform& B)
  513. {
  514. b2Transform C;
  515. C.q = b2MulT(A.q, B.q);
  516. C.p = b2MulT(A.q, B.p - A.p);
  517. return C;
  518. }
  519. template <typename T>
  520. inline T b2Abs(T a)
  521. {
  522. return a > T(0) ? a : -a;
  523. }
  524. inline b2Vec2 b2Abs(const b2Vec2& a)
  525. {
  526. return b2Vec2(b2Abs(a.x), b2Abs(a.y));
  527. }
  528. inline b2Mat22 b2Abs(const b2Mat22& A)
  529. {
  530. return b2Mat22(b2Abs(A.ex), b2Abs(A.ey));
  531. }
  532. template <typename T>
  533. inline T b2Min(T a, T b)
  534. {
  535. return a < b ? a : b;
  536. }
  537. inline b2Vec2 b2Min(const b2Vec2& a, const b2Vec2& b)
  538. {
  539. return b2Vec2(b2Min(a.x, b.x), b2Min(a.y, b.y));
  540. }
  541. template <typename T>
  542. inline T b2Max(T a, T b)
  543. {
  544. return a > b ? a : b;
  545. }
  546. inline b2Vec2 b2Max(const b2Vec2& a, const b2Vec2& b)
  547. {
  548. return b2Vec2(b2Max(a.x, b.x), b2Max(a.y, b.y));
  549. }
  550. template <typename T>
  551. inline T b2Clamp(T a, T low, T high)
  552. {
  553. return b2Max(low, b2Min(a, high));
  554. }
  555. inline b2Vec2 b2Clamp(const b2Vec2& a, const b2Vec2& low, const b2Vec2& high)
  556. {
  557. return b2Max(low, b2Min(a, high));
  558. }
  559. template<typename T> inline void b2Swap(T& a, T& b)
  560. {
  561. T tmp = a;
  562. a = b;
  563. b = tmp;
  564. }
  565. /// "Next Largest Power of 2
  566. /// Given a binary integer value x, the next largest power of 2 can be computed by a SWAR algorithm
  567. /// that recursively "folds" the upper bits into the lower bits. This process yields a bit vector with
  568. /// the same most significant 1 as x, but all 1's below it. Adding 1 to that value yields the next
  569. /// largest power of 2. For a 32-bit value:"
  570. inline juce::uint32 b2NextPowerOfTwo(juce::uint32 x)
  571. {
  572. x |= (x >> 1);
  573. x |= (x >> 2);
  574. x |= (x >> 4);
  575. x |= (x >> 8);
  576. x |= (x >> 16);
  577. return x + 1;
  578. }
  579. inline bool b2IsPowerOfTwo(juce::uint32 x)
  580. {
  581. bool result = x > 0 && (x & (x - 1)) == 0;
  582. return result;
  583. }
  584. inline void b2Sweep::GetTransform(b2Transform* xf, float32 beta) const
  585. {
  586. xf->p = (1.0f - beta) * c0 + beta * c;
  587. float32 angle = (1.0f - beta) * a0 + beta * a;
  588. xf->q.Set(angle);
  589. // Shift to origin
  590. xf->p -= b2Mul(xf->q, localCenter);
  591. }
  592. inline void b2Sweep::Advance(float32 alpha)
  593. {
  594. b2Assert(alpha0 < 1.0f);
  595. float32 beta = (alpha - alpha0) / (1.0f - alpha0);
  596. c0 = (1.0f - beta) * c0 + beta * c;
  597. a0 = (1.0f - beta) * a0 + beta * a;
  598. alpha0 = alpha;
  599. }
  600. /// Normalize an angle in radians to be between -pi and pi
  601. inline void b2Sweep::Normalize()
  602. {
  603. float32 twoPi = 2.0f * b2_pi;
  604. float32 d = twoPi * floorf(a0 / twoPi);
  605. a0 -= d;
  606. a -= d;
  607. }
  608. #endif