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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
#include "mons_math/vec2.h"
#include "mons_math/util.h"
#include "mons_math/vec3.h"
#include <math.h>
mons_vec2 mons_vec2_add(mons_vec2 a, mons_vec2 b) {
mons_vec2 result = {
a.x + b.x,
a.y + b.y,
};
return result;
}
void mons_vec2_add_inplace(mons_vec2 *a, mons_vec2 b) {
a->x += b.x;
a->y += b.y;
}
mons_vec2 mons_vec2_sub(mons_vec2 a, mons_vec2 b) {
mons_vec2 result = {
a.x - b.x,
a.y - b.y,
};
return result;
}
void mons_vec2_sub_inplace(mons_vec2 *a, mons_vec2 b) {
a->x -= b.x;
a->y -= b.y;
}
mons_vec2 mons_vec2_mul_f(mons_vec2 a, float b) {
mons_vec2 result = {
a.x * b,
a.y * b,
};
return result;
}
mons_vec2 mons_vec2_mul_i(mons_vec2 a, int b) {
mons_vec2 result = {
a.x * b,
a.y * b,
};
return result;
}
float mons_vec2_dot(mons_vec2 a, mons_vec2 b) {
return (a.x * b.x) + (a.y * b.y);
}
void mons_vec2_mul_f_inplace(mons_vec2 *a, float b) {
a->x *= b;
a->y *= b;
}
void mons_vec2_mul_i_inplace(mons_vec2 *a, int b) {
a->x *= b;
a->y *= b;
}
float mons_vec2_len(mons_vec2 a) { return sqrtf(mons_vec2_len_squared(a)); }
float mons_vec2_len_squared(mons_vec2 a) { return (a.x * a.x) + (a.y * a.y); }
mons_vec3 mons_vec2_extend(mons_vec2 a) {
mons_vec3 result = {
a.x,
a.y,
0.0,
};
return result;
}
int mons_vec2_equal(mons_vec2 a, mons_vec2 b) {
return mons_float_approx_equal(a.x, b.x) &&
mons_float_approx_equal(a.y, b.y);
}
mons_vec2 mons_vec2_div_f(mons_vec2 a, float b) {
return (mons_vec2) {
a.x / b,
a.y / b,
};
}
mons_vec2 mons_vec2_div_i(mons_vec2 a, int b) {
return (mons_vec2) {
a.x / b,
a.y / b,
};
}
void mons_vec2_div_f_inplace(mons_vec2 *a, float b) {
a->x /= b;
a->y /= b;
}
void mons_vec2_div_i_inplace(mons_vec2 *a, int b) {
a->x /= b;
a->y /= b;
}
mons_vec2 mons_vec2_negate(mons_vec2 a) {
return mons_vec2_mul_i(a, -1);
}
void mons_vec2_negate_inplace(mons_vec2 *a) {
mons_vec2_mul_i_inplace(a, -1);
}
mons_vec2 mons_vec2_normalize(mons_vec2 a) {
float len = mons_vec2_len(a);
return mons_vec2_div_f(a, len);
}
void mons_vec2_normalize_inplace(mons_vec2 *a) {
float len = mons_vec2_len(*a);
mons_vec2_div_f_inplace(a, len);
}
|