26 inline bool b2IsValid(float32 x)
 
   28     int32 ix = *
reinterpret_cast<int32*
>(&x);
 
   29     return (ix & 0x7f800000) != 0x7f800000;
 
   33 inline float32 b2InvSqrt(float32 x)
 
   42     float32 xhalf = 0.5f * x;
 
   43     convert.i = 0x5f3759df - (convert.i >> 1);
 
   45     x = x * (1.5f - xhalf * x * x);
 
   49 #define b2Sqrt(x)   sqrtf(x) 
   50 #define b2Atan2(y, x)   atan2f(y, x) 
   59     b2Vec2(float32 x, float32 y) : x(x), y(y) {}
 
   65     void Set(float32 x_, float32 y_) { x = x_; y = y_; }
 
  103         return b2Sqrt(x * x + y * y);
 
  110         return x * x + y * y;
 
  116         float32 length = 
Length();
 
  117         if (length < b2_epsilon)
 
  121         float32 invLength = 1.0f / length;
 
  131         return b2IsValid(x) && b2IsValid(y);
 
  150     b2Vec3(float32 x, float32 y, float32 z) : x(x), y(y), z(z) {}
 
  153     void SetZero() { x = 0.0f; y = 0.0f; z = 0.0f; }
 
  156     void Set(float32 x_, float32 y_, float32 z_) { x = x_; y = y_; z = z_; }
 
  164         x += v.x; y += v.y; z += v.z;
 
  170         x -= v.x; y -= v.y; z -= v.z;
 
  176         x *= s; y *= s; z *= s;
 
  196     b2Mat22(float32 a11, float32 a12, float32 a21, float32 a22)
 
  198         ex.x = a11; ex.y = a21;
 
  199         ey.x = a12; ey.y = a22;
 
  212         ex.x = 1.0f; ey.x = 0.0f;
 
  213         ex.y = 0.0f; ey.y = 1.0f;
 
  219         ex.x = 0.0f; ey.x = 0.0f;
 
  220         ex.y = 0.0f; ey.y = 0.0f;
 
  225         float32 a = ex.x, b = ey.x, c = ex.y, d = ey.y;
 
  227         float32 det = a * d - b * c;
 
  232         B.ex.x =  det * d;  B.ey.x = -det * b;
 
  233         B.ex.y = -det * c;  B.ey.y =  det * a;
 
  241         float32 a11 = ex.x, a12 = ey.x, a21 = ex.y, a22 = ey.y;
 
  242         float32 det = a11 * a22 - a12 * a21;
 
  248         x.x = det * (a22 * b.x - a12 * b.y);
 
  249         x.y = det * (a11 * b.y - a21 * b.x);
 
  329         return b2Atan2(
s, c);
 
  403 extern const b2Vec2 b2Vec2_zero;
 
  408     return a.x * b.x + a.y * b.y;
 
  412 inline float32 b2Cross(
const b2Vec2& a, 
const b2Vec2& b)
 
  414     return a.x * b.y - a.y * b.x;
 
  421     return b2Vec2(s * a.y, -s * a.x);
 
  428     return b2Vec2(-s * a.y, s * a.x);
 
  435     return b2Vec2(A.ex.x * v.x + A.ey.x * v.y, A.ex.y * v.x + A.ey.y * v.y);
 
  442     return b2Vec2(b2Dot(v, A.ex), b2Dot(v, A.ey));
 
  448     return b2Vec2(a.x + b.x, a.y + b.y);
 
  454     return b2Vec2(a.x - b.x, a.y - b.y);
 
  459     return b2Vec2(s * a.x, s * a.y);
 
  462 inline bool operator == (
const b2Vec2& a, 
const b2Vec2& b)
 
  464     return a.x == b.x && a.y == b.y;
 
  467 inline float32 b2Distance(
const b2Vec2& a, 
const b2Vec2& b)
 
  473 inline float32 b2DistanceSquared(
const b2Vec2& a, 
const b2Vec2& b)
 
  481     return b2Vec3(s * a.x, s * a.y, s * a.z);
 
  487     return b2Vec3(a.x + b.x, a.y + b.y, a.z + b.z);
 
  493     return b2Vec3(a.x - b.x, a.y - b.y, a.z - b.z);
 
  499     return a.x * b.x + a.y * b.y + a.z * b.z;
 
  505     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);
 
  510     return b2Mat22(A.ex + B.ex, A.ey + B.ey);
 
  516     return b2Mat22(b2Mul(A, B.ex), b2Mul(A, B.ey));
 
  522     b2Vec2 c1(b2Dot(A.ex, B.ex), b2Dot(A.ey, B.ex));
 
  523     b2Vec2 c2(b2Dot(A.ex, B.ey), b2Dot(A.ey, B.ey));
 
  530     return v.x * A.ex + v.y * A.ey + v.z * A.ez;
 
  536     return b2Vec2(A.ex.x * v.x + A.ey.x * v.y, A.ex.y * v.x + A.ey.y * v.y);
 
  547     qr.
s = q.
s * r.c + q.c * r.
s;
 
  548     qr.c = q.c * r.c - q.
s * r.
s;
 
  560     qr.
s = q.c * r.
s - q.
s * r.c;
 
  561     qr.c = q.c * r.c + q.
s * r.
s;
 
  568     return b2Vec2(q.c * v.x - q.
s * v.y, q.
s * v.x + q.c * v.y);
 
  574     return b2Vec2(q.c * v.x + q.
s * v.y, -q.
s * v.x + q.c * v.y);
 
  579     float32 x = (T.q.c * v.x - T.q.
s * v.y) + T.p.x;
 
  580     float32 y = (T.q.
s * v.x + T.q.c * v.y) + T.p.y;
 
  587     float32 px = v.x - T.p.x;
 
  588     float32 py = v.y - T.p.y;
 
  589     float32 x = (T.q.c * px + T.q.
s * py);
 
  590     float32 y = (-T.q.
s * px + T.q.c * py);
 
  600     C.q = b2Mul(A.q, B.q);
 
  601     C.p = b2Mul(A.q, B.p) + A.p;
 
  610     C.q = b2MulT(A.q, B.q);
 
  611     C.p = b2MulT(A.q, B.p - A.p);
 
  615 template <
typename T>
 
  618     return a > T(0) ? a : -a;
 
  623     return b2Vec2(b2Abs(a.x), b2Abs(a.y));
 
  628     return b2Mat22(b2Abs(A.ex), b2Abs(A.ey));
 
  631 template <
typename T>
 
  632 inline T b2Min(T a, T b)
 
  634     return a < b ? a : b;
 
  639     return b2Vec2(b2Min(a.x, b.x), b2Min(a.y, b.y));
 
  642 template <
typename T>
 
  643 inline T b2Max(T a, T b)
 
  645     return a > b ? a : b;
 
  650     return b2Vec2(b2Max(a.x, b.x), b2Max(a.y, b.y));
 
  653 template <
typename T>
 
  654 inline T b2Clamp(T a, T low, T high)
 
  656     return b2Max(low, b2Min(a, high));
 
  661     return b2Max(low, b2Min(a, high));
 
  664 template<
typename T> 
inline void b2Swap(T& a, T& b)
 
  676 inline uint32 b2NextPowerOfTwo(uint32 x)
 
  686 inline bool b2IsPowerOfTwo(uint32 x)
 
  688     bool result = x > 0 && (x & (x - 1)) == 0;
 
  694     xf->p = (1.0f - beta) * c0 + beta * 
c;
 
  695     float32 angle = (1.0f - beta) * a0 + beta * 
a;
 
  706     c0 += beta * (
c - c0);
 
  707     a0 += beta * (
a - a0);
 
  714     float32 twoPi = 2.0f * b2_pi;
 
  715     float32 d =  twoPi * floorf(a0 / twoPi);