]> git.lizzy.rs Git - nothing.git/blob - src/point.c
Make player color customizable (#76)
[nothing.git] / src / point.c
1 #include <math.h>
2 #include "./point.h"
3
4 vec_t vec(float x, float y)
5 {
6     vec_t result = {
7         .x = x,
8         .y = y
9     };
10     return result;
11 }
12
13 vec_t vec_sum(vec_t v1, vec_t v2)
14 {
15     vec_t result = {
16         .x = v1.x + v2.x,
17         .y = v1.y + v2.y
18     };
19     return result;
20 }
21
22 vec_t vec_neg(vec_t v)
23 {
24     vec_t result = {
25         .x = -v.x,
26         .y = -v.y
27     };
28
29     return result;
30 }
31
32 float vec_length(vec_t v)
33 {
34     return sqrtf(v.x * v.x + v.y * v.y);
35 }
36
37 void vec_add(vec_t *v1, vec_t v2)
38 {
39     v1->x += v2.x;
40     v1->y += v2.y;
41 }
42
43 vec_t vec_scala_mult(vec_t v, float scalar)
44 {
45     vec_t result = {
46         .x = v.x * scalar,
47         .y = v.y * scalar
48     };
49     return result;
50 }
51
52 vec_t vec_entry_mult(vec_t v1, vec_t v2)
53 {
54     vec_t result = {
55         .x = v1.x * v2.x,
56         .y = v1.y * v2.y
57     };
58
59     return result;
60 }
61
62 vec_t vec_entry_div(vec_t v1, vec_t v2)
63 {
64     vec_t result = {
65         .x = v1.x / v2.x,
66         .y = v1.y / v2.y
67     };
68
69     return result;
70 }