-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmath_utils.h
More file actions
54 lines (37 loc) · 1014 Bytes
/
math_utils.h
File metadata and controls
54 lines (37 loc) · 1014 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef ICYLIB_MATH_UTILS_H
#define ICYLIB_MATH_UTILS_H
#define ICYLIB_PI 3.142
int icylib_imin(int a, int b);
int icylib_imax(int a, int b);
int icylib_floor(double x);
int icylib_ceil(double x);
unsigned char icylib_is_point_inside_circular_arc(double x, double y, double phi1, double phi2);
#ifdef ICYLIB_IMPLEMENTATION
#include <math.h>
int icylib_imin(int a, int b) {
return a < b ? a : b;
}
int icylib_imax(int a, int b) {
return a > b ? a : b;
}
int icylib_floor(double x) {
return (int)x;
}
int icylib_ceil(double x) {
return x > (int)x ? (int)x + 1 : (int)x;
}
int icylib_round(double x) {
return (int)(x + 0.5);
}
double icylib_wrap_angle(double phi) {
phi = fmod(phi, 2 * ICYLIB_PI);
if (phi < 0) phi += 2 * ICYLIB_PI;
return phi;
}
unsigned char icylib_is_point_inside_circular_arc(double x, double y, double phi1, double phi2) {
double phi = atan2(y, x);
if (phi < 0) phi += 2 * ICYLIB_PI;
return phi >= phi1 && phi <= phi2;
}
#endif
#endif