6 typedef struct { float x
, y
; } vec2f
;
8 #define VEC(a, b) (vec2f) { .x = a, .y = b }
10 static inline vec2f
velocity(const vec2f
* from
, const vec2f
* to
) {
11 return VEC(to
->x
- from
->x
, to
->y
- from
->y
);
14 static inline float veclength(const vec2f
*v
) {
15 return sqrtf((v
->x
* v
->x
) + (v
->y
* v
->y
));
18 static inline float vecdist(const vec2f
* a
, const vec2f
* b
) {
19 vec2f vel
= velocity(a
, b
);
20 return veclength(&vel
);
23 static inline vec2f
vecadd(const vec2f
* a
, const vec2f
* b
) {
24 return VEC(a
->x
+ b
->x
, a
->y
+ b
->y
);
27 static inline vec2f
vecsub(const vec2f
* a
, const vec2f
* b
) {
28 return VEC(a
->x
- b
->x
, a
->y
- b
->y
);