12#define B2_MIN(A, B) ((A) < (B) ? (A) : (B))
15#define B2_MAX(A, B) ((A) > (B) ? (A) : (B))
18#define B2_ABS(A) ((A) > 0.0f ? (A) : -(A))
21#define B2_CLAMP(A, B, C) B2_MIN(B2_MAX(A, B), C)
23static const b2Vec2 b2Vec2_zero = {0.0f, 0.0f};
24static const b2Rot b2Rot_identity = {0.0f, 1.0f};
25static const b2Transform b2Transform_identity = {{0.0f, 0.0f}, {0.0f, 1.0f}};
26static const b2Mat22 b2Mat22_zero = {{0.0f, 0.0f}, {0.0f, 0.0f}};
31 return a.
x * b.
x + a.y * b.y;
37 return a.
x * b.y - a.y * b.
x;
127 c.
x = B2_MIN(a.
x, b.
x);
128 c.y = B2_MIN(a.y, b.y);
136 c.
x = B2_MAX(a.
x, b.
x);
137 c.y = B2_MAX(a.y, b.y);
145 c.
x = B2_CLAMP(v.
x, a.
x, b.
x);
146 c.y = B2_CLAMP(v.y, a.y, b.y);
151static inline float b2Length(
b2Vec2 v)
153 return sqrtf(v.
x * v.
x + v.y * v.y);
157static inline float b2LengthSquared(
b2Vec2 v)
159 return v.
x * v.
x + v.y * v.y;
164 float dx = b.
x - a.
x;
165 float dy = b.y - a.y;
166 return sqrtf(dx * dx + dy * dy);
170static inline float b2DistanceSquared(
b2Vec2 a,
b2Vec2 b)
173 return c.
x * c.
x + c.y * c.y;
177static inline b2Rot b2MakeRot(
float angle)
179 b2Rot q = {sinf(angle), cosf(angle)};
184static inline float b2Rot_GetAngle(
b2Rot q)
186 return atan2f(q.
s, q.c);
211 qr.
s = q.
s * r.c + q.c * r.
s;
212 qr.c = q.c * r.c - q.
s * r.
s;
224 qr.
s = q.c * r.
s - q.
s * r.c;
225 qr.c = q.c * r.c + q.
s * r.
s;
244 float x = (xf.q.c * p.
x - xf.q.
s * p.y) + xf.p.
x;
245 float y = (xf.q.s * p.x + xf.q.c * p.y) + xf.p.y;
253 float vx = p.
x - xf.p.
x;
254 float vy = p.y - xf.p.y;
263 C.q = b2MulRot(A.q, B.q);
264 C.p = b2Add(b2RotateVector(A.q, B.p), A.p);
273 C.q = b2InvMulRot(A.q, B.q);
274 C.p = b2InvRotateVector(A.q, b2Sub(B.p, A.p));
282 A.
cx.
x * v.
x + A.cy.
x * v.y,
283 A.
cx.y * v.
x + A.cy.y * v.y,
291 float a = A.
cx.
x, b = A.cy.
x, c = A.
cx.y, d = A.cy.y;
292 float det = a * d - b * c;
309 s = s && a.lowerBound.
x <= b.lowerBound.
x;
310 s = s && a.lowerBound.y <= b.lowerBound.y;
311 s = s && b.upperBound.
x <= a.upperBound.
x;
312 s = s && b.upperBound.y <= a.upperBound.y;
316BOX2D_API
bool b2IsValid(
float a);
317BOX2D_API
bool b2IsValidVec2(
b2Vec2 v);
325BOX2D_API
b2Vec2 b2GetLengthAndNormalize(
float* length,
b2Vec2 v);
types used by the Box2D API
float s
Sine and cosine.
Definition types.h:56
float x
coordinates
Definition types.h:49
#define B2_LITERAL(T)
Used for C literals like (b2Vec2){1.0f, 2.0f} where C++ requires b2Vec2{1.0f, 2.0f}.
Definition types.h:29
b2Vec2 cx
columns
Definition types.h:70
Axis-aligned bounding box.
Definition types.h:75
A 2-by-2 Matrix.
Definition types.h:68
2D rotation
Definition types.h:54