1
0
Fork 0
tsgames/build/assets/lib/vec2.c

44 lines
696 B
C

#include "vec2.h"
#include <math.h>
vec2 vec2_add(vec2 a, vec2 b) {
return (vec2){
.x = a.x + b.x,
.y = a.y + b.y,
};
}
vec2 vec2_sub(vec2 a, vec2 b) {
return (vec2){
.x = a.x - b.x,
.y = a.y - b.y,
};
}
float vec2_dot(vec2 a, vec2 b) {
return a.x * b.x + a.y * b.y;
}
vec2 vec2_mul(vec2 x, float f) {
return (vec2){
.x = x.x * f,
.y = x.y * f,
};
}
vec2 vec2_div(vec2 x, float f) {
return (vec2){
.x = x.x / f,
.y = x.y / f,
};
}
float vec2_mag(vec2 x) {
return sqrtf(x.x * x.x + x.y * x.y);
}
vec2 vec2_normalize(vec2 x) {
float len = vec2_mag(x);
return vec2_div(x, len);
}