]> git.bts.cx Git - benzene.git/blob - src/bz/math/math.h
Fixed Aseprite rendering system
[benzene.git] / src / bz / math / math.h
1 #ifndef BZ_MATH_MATH_H
2 #define BZ_MATH_MATH_H
3
4 #include <bz/types/common.h>
5
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9
10 #define bzAbs(a) ((a) < 0.0f ? -(a) : (a))
11
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))))
15
16 #define bzMMin(a, b) (bzAbs(a) < bzAbs(b) ? (a) : (b))
17 #define bzMMax(a, b) (bzAbs(a) > bzAbs(b) ? (a) : (b))
18
19 #define bzClamp(a, b, v) (bzMin(bzMax(v, bzMin((a), (b))), bzMax((a), (b))))
20
21 #define bzSgn(v) (bzAbs(v) < 0.001f ? 0.0f : ((v) >= 0.0f ? 1.0f : -1.0f))
22
23 #define bzLerp(a, b, t) ((a) * (1 - (t)) + (b) * (t))
24 #define bzUnlerp(a, b, v) (((v) - (a)) / ((b) - (a)))
25
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)))
29
30 extern float bzSine(float a);
31 extern float bzCosine(float a);
32
33 extern float bzInverseSine(float a);
34 extern float bzInverseCosine(float a);
35
36 extern float bzSqrt(float a);
37
38 extern float bzAtan2(float x, float y); // To match PICO-8
39 extern float bzAngleDelta(float from, float to);
40
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);
44
45 #ifdef __cplusplus
46 }
47 #endif
48
49 #endif