]>
git.bts.cx Git - benzene.git/blob - src/bz/math/math.h
4 #include <bz/types/common.h>
10 #define bzAbs(a) ((a) < 0.0f ? -(a) : (a))
12 #define bzMin(a, b) ((a) < (b) ? (a) : (b))
13 #define bzMax(a, b) ((a) > (b) ? (a) : (b))
14 #define bzMid(a, b, c) (bzMin(bzMin(bzMax((a), (b)), bzMax((b), (c))), bzMax((a), (c))))
16 #define bzMMin(a, b) (bzAbs(a) < bzAbs(b) ? (a) : (b))
17 #define bzMMax(a, b) (bzAbs(a) > bzAbs(b) ? (a) : (b))
19 #define bzClamp(a, b, v) (bzMin(bzMax(v, bzMin((a), (b))), bzMax((a), (b))))
21 #define bzSgn(v) (bzAbs(v) < 0.001f ? 0.0f : ((v) >= 0.0f ? 1.0f : -1.0f))
23 #define bzLerp(a, b, t) ((a) * (1 - (t)) + (b) * (t))
24 #define bzUnlerp(a, b, v) (((v) - (a)) / ((b) - (a)))
26 #define bzFloor(v) ((float)((int)(v)))
27 #define bzRound(v) (bzFloor(v + bzSgn(v) * 0.5f))
28 #define bzCeil(v) (bzFloor(v) + (bzFloor(v) < (v)))
30 extern float bzSine(float a
);
31 extern float bzCosine(float a
);
33 extern float bzInverseSine(float a
);
34 extern float bzInverseCosine(float a
);
36 extern float bzSqrt(float a
);
38 extern float bzAtan2(float x
, float y
); // To match PICO-8
39 extern float bzAngleDelta(float from
, float to
);
41 extern float bzDistance(float x1
, float y1
, float x2
, float y2
);
42 extern float bzDistanceSquared(float x1
, float y1
, float x2
, float y2
);
43 extern bool bzDistanceCheck(float x1
, float y1
, float x2
, float y2
, float distance
);