aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2024-02-08 07:52:58 -0800
committer3gg <3gg@shellblade.net>2024-02-08 07:52:58 -0800
commit8145fbe95bebef9517dd3c864e07f96b60a4fcaf (patch)
treeb7385e27290d6f02fdba1e96dfbb7fd91ee4b664
parentebed78f26411a951fd2e94938b6d7aa99ca0fe39 (diff)
Vector min max.
-rw-r--r--include/math/vec2.h14
-rw-r--r--include/math/vec3.h16
2 files changed, 25 insertions, 5 deletions
diff --git a/include/math/vec2.h b/include/math/vec2.h
index 5a74705..5a56a94 100644
--- a/include/math/vec2.h
+++ b/include/math/vec2.h
@@ -57,11 +57,21 @@ static inline vec2 vec2_scale(vec2 v, R s) { return (vec2){v.x * s, v.y * s}; }
57/// Compare two vectors for equality. 57/// Compare two vectors for equality.
58static inline bool vec2_eq(vec2 a, vec2 b) { return a.x == b.x && a.y == b.y; } 58static inline bool vec2_eq(vec2 a, vec2 b) { return a.x == b.x && a.y == b.y; }
59 59
60/// Compare two vectors for inequality.
61static inline bool vec2_ne(vec2 a, vec2 b) { return !(vec2_eq(a, b)); }
62
60/// Return the absolute value of the vector. 63/// Return the absolute value of the vector.
61static inline vec2 vec2_abs(vec2 v) { return (vec2){rabs(v.x), rabs(v.y)}; } 64static inline vec2 vec2_abs(vec2 v) { return (vec2){rabs(v.x), rabs(v.y)}; }
62 65
63/// Compare two vectors for inequality. 66/// Return the component-wise minimum of two vectors.
64static inline bool vec2_ne(vec2 a, vec2 b) { return !(vec2_eq(a, b)); } 67static inline vec2 vec2_min(vec2 a, vec2 b) {
68 return (vec2){.x = min(a.x, b.x), .y = min(a.y, b.y)};
69}
70
71/// Return the component-wise maximum of two vectors.
72static inline vec2 vec2_max(vec2 a, vec2 b) {
73 return (vec2){.x = max(a.x, b.x), .y = max(a.y, b.y)};
74}
65 75
66/// Return the vector's squared magnitude. 76/// Return the vector's squared magnitude.
67static inline R vec2_norm2(vec2 v) { return v.x * v.x + v.y * v.y; } 77static inline R vec2_norm2(vec2 v) { return v.x * v.x + v.y * v.y; }
diff --git a/include/math/vec3.h b/include/math/vec3.h
index d8e1248..ee6d460 100644
--- a/include/math/vec3.h
+++ b/include/math/vec3.h
@@ -61,14 +61,24 @@ static inline bool vec3_eq(vec3 a, vec3 b, R eps) {
61 return R_eq(a.x, b.x, eps) && R_eq(a.y, b.y, eps) && R_eq(a.z, b.z, eps); 61 return R_eq(a.x, b.x, eps) && R_eq(a.y, b.y, eps) && R_eq(a.z, b.z, eps);
62} 62}
63 63
64/// Compare two vectors for inequality.
65static inline bool vec3_ne(vec3 a, vec3 b, R eps) {
66 return !(vec3_eq(a, b, eps));
67}
68
64/// Return the absolute value of the vector. 69/// Return the absolute value of the vector.
65static inline vec3 vec3_abs(vec3 v) { 70static inline vec3 vec3_abs(vec3 v) {
66 return (vec3){rabs(v.x), rabs(v.y), rabs(v.z)}; 71 return (vec3){rabs(v.x), rabs(v.y), rabs(v.z)};
67} 72}
68 73
69/// Compare two vectors for inequality. 74/// Return the component-wise minimum of two vectors.
70static inline bool vec3_ne(vec3 a, vec3 b, R eps) { 75static inline vec3 vec3_min(vec3 a, vec3 b) {
71 return !(vec3_eq(a, b, eps)); 76 return (vec3){.x = min(a.x, b.x), .y = min(a.y, b.y), .z = min(a.z, b.z)};
77}
78
79/// Return the component-wise maximum of two vectors.
80static inline vec3 vec3_max(vec3 a, vec3 b) {
81 return (vec3){.x = max(a.x, b.x), .y = max(a.y, b.y), .z = max(a.z, b.z)};
72} 82}
73 83
74/// Return the vector's squared magnitude. 84/// Return the vector's squared magnitude.