#include #include #include "types.h" vec2 dp_vec2_new(float x, float y) { vec2 new; assert(isfinite(x)); assert(isfinite(y)); new.x = x; new.y = y; return new; } vec2 dp_vec2_add(vec2 a, vec2 b) { vec2 new; new.x = a.x + b.x; new.y = a.y + b.y; return new; } vec2 dp_vec2_sub(vec2 a, vec2 b) { vec2 new; new.x = a.x - b.x; new.y = a.y - b.y; return new; } vec2 dp_vec2_mul(vec2 vec, float scalar) { vec2 new; new.x = vec.x * scalar; new.y = vec.y * scalar; return new; } vec2 dp_vec2_dot(vec2 a, vec2 b) { vec2 dot; dot.x = a.x * b.x; dot.y = a.y * b.y; return dot; } float dp_vec2_length(vec2 v) { return sqrtf(powf(v.x, 2.f) + powf(v.y, 2.f)); } vec2 dp_vec2_normal(vec2 v) { float a; a = 1.f / dp_vec2_length(v); return dp_vec2_mul(v, a); }