#ifndef _VECTOR_H #define _VECTOR_H #include struct vector { double x; double y; }; /* * res = a - b */ static inline void vector_sub(const struct vector *a, const struct vector *b, struct vector *res) { res->x = a->x - b->x; res->y = a->y - b->y; } /* * res = a + b */ static inline void vector_add(const struct vector *a, const struct vector *b, struct vector *res) { res->x = a->x + b->x; res->y = a->y + b->y; } static inline double vector_abs(const struct vector *a) { return sqrt(a->x * a->x + a->y * a->y); } static inline void vector_scale(const struct vector *a, const double b, struct vector *res) { res->x = a->x * b; res->y = a->y * b; } static inline void vector_div(const struct vector *a, const double b, struct vector *res) { res->x = a->x / b; res->y = a->y / b; } #endif