palpic2png.c: improve, make usable with ppic binary files
[rofl0r-openDOW.git] / vec2f.h
blob25b5f03f328ef4001e8559442fa617f91f492078
1 #ifndef VEC2F_H
2 #define VEC2F_H
4 #include <math.h>
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);
31 #endif