#ifndef HANDMADE_MATH_H #define HANDMADE_MATH_H /* TODO: Make these static. */ struct v2 { float x, y; float e[2]; }; struct v2 v2(float x, float y) { struct v2 result; result.x = x; result.y = y; return result; } struct v2 v2_multiply(float a, struct v2 b) { struct v2 result; result.x = a * b.x; result.y = a * b.y; return result; } struct v2 v2_unary(struct v2 a) { struct v2 result; result.x = -a.x; result.y = -a.y; return result; } struct v2 v2_add(struct v2 a, struct v2 b) { struct v2 result; result.x = a.x + b.x; result.y = a.y + b.y; return result; } struct v2 v2_subtract(struct v2 a, struct v2 b) { struct v2 result; result.x = a.x - b.x; result.y = a.y - b.y; return result; } float square(float a) { float result; result = a * a; return result; } float inner_product(struct v2 a, struct v2 b) { float result = a.x*b.x + a.y*b.y; return result; } float length_sq(struct v2 a) { float result = inner_product(a, a); return result; } #endif