aboutsummaryrefslogtreecommitdiff
path: root/include/math/vec2.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/math/vec2.h')
-rw-r--r--include/math/vec2.h20
1 files changed, 6 insertions, 14 deletions
diff --git a/include/math/vec2.h b/include/math/vec2.h
index dc51c17..5a74705 100644
--- a/include/math/vec2.h
+++ b/include/math/vec2.h
@@ -52,19 +52,13 @@ static inline vec2 vec2_div(vec2 a, vec2 b) {
52} 52}
53 53
54/// Scale a vector by a scalar value. 54/// Scale a vector by a scalar value.
55static inline vec2 vec2_scale(vec2 v, R s) { 55static inline vec2 vec2_scale(vec2 v, R s) { return (vec2){v.x * s, v.y * s}; }
56 return (vec2){v.x * s, v.y * s};
57}
58 56
59/// Compare two vectors for equality. 57/// Compare two vectors for equality.
60static inline bool vec2_eq(vec2 a, vec2 b) { 58static inline bool vec2_eq(vec2 a, vec2 b) { return a.x == b.x && a.y == b.y; }
61 return a.x == b.x && a.y == b.y;
62}
63 59
64/// Return the absolute value of the vector. 60/// Return the absolute value of the vector.
65static inline vec2 vec2_abs(vec2 v) { 61static inline vec2 vec2_abs(vec2 v) { return (vec2){rabs(v.x), rabs(v.y)}; }
66 return (vec2){rabs(v.x), rabs(v.y)};
67}
68 62
69/// Compare two vectors for inequality. 63/// Compare two vectors for inequality.
70static inline bool vec2_ne(vec2 a, vec2 b) { return !(vec2_eq(a, b)); } 64static inline bool vec2_ne(vec2 a, vec2 b) { return !(vec2_eq(a, b)); }
@@ -92,9 +86,7 @@ static inline vec2 vec2_normalize(vec2 v) {
92} 86}
93 87
94/// Return the dot product of two vectors. 88/// Return the dot product of two vectors.
95static inline R vec2_dot(vec2 a, vec2 b) { 89static inline R vec2_dot(vec2 a, vec2 b) { return a.x * b.x + a.y * b.y; }
96 return a.x * b.x + a.y * b.y;
97}
98 90
99/// Reflect the vector about the normal. 91/// Reflect the vector about the normal.
100static inline vec2 vec2_reflect(vec2 v, vec2 n) { 92static inline vec2 vec2_reflect(vec2 v, vec2 n) {
@@ -108,8 +100,8 @@ static inline vec2 vec2_refract(vec2 v, vec2 n, R e) {
108 const R k = 1.0 - e * e * (1.0 - vec2_dot(n, v) * vec2_dot(n, v)); 100 const R k = 1.0 - e * e * (1.0 - vec2_dot(n, v) * vec2_dot(n, v));
109 assert(k >= 0); 101 assert(k >= 0);
110 // r = e*v - (e * dot(n,v) + sqrt(k)) * n 102 // r = e*v - (e * dot(n,v) + sqrt(k)) * n
111 return vec2_sub(vec2_scale(v, e), 103 return vec2_sub(
112 vec2_scale(n, e * vec2_dot(n, v) * sqrt(k))); 104 vec2_scale(v, e), vec2_scale(n, e * vec2_dot(n, v) * sqrt(k)));
113} 105}
114 106
115/// Elevate the vector to a power. 107/// Elevate the vector to a power.