add more vector arithmetic functions

Tue, 22 Jul 2025 20:50:50 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 22 Jul 2025 20:50:50 +0200
changeset 218
2ead0699ce77
parent 217
4b3c974eab44
child 219
62508d957a22

add more vector arithmetic functions

src/ascension/datatypes.h file | annotate | diff | comparison | revisions
--- a/src/ascension/datatypes.h	Mon Jul 21 21:28:34 2025 +0200
+++ b/src/ascension/datatypes.h	Tue Jul 22 20:50:50 2025 +0200
@@ -354,12 +354,38 @@
     return v.x*v.x + v.y*v.y + v.z*v.z;
 }
 
+static inline asc_vec2i asc_vec2i_sub(asc_vec2i a, asc_vec2i b) {
+    return ASC_VEC2I(a.x-b.x, a.y-b.y);
+}
+
+static inline asc_vec2u asc_vec2u_sub(asc_vec2u a, asc_vec2u b) {
+    // this may overflow - responsibility lies with the caller
+    return ASC_VEC2U(a.x-b.x, a.y-b.y);
+}
+
 static inline asc_vec2f asc_vec2f_sub(asc_vec2f a, asc_vec2f b) {
     return ASC_VEC2F(a.x-b.x, a.y-b.y);
 }
 
-// TODO: add sub-functions for other types
-// TODO: add add-functions
+static inline asc_vec3f asc_vec3f_sub(asc_vec3f a, asc_vec3f b) {
+    return ASC_VEC3F(a.x-b.x, a.y-b.y, a.z-b.z);
+}
+
+static inline asc_vec2i asc_vec2i_add(asc_vec2i a, asc_vec2i b) {
+    return ASC_VEC2I(a.x+b.x, a.y+b.y);
+}
+
+static inline asc_vec2u asc_vec2u_add(asc_vec2u a, asc_vec2u b) {
+    return ASC_VEC2U(a.x+b.x, a.y+b.y);
+}
+
+static inline asc_vec2f asc_vec2f_add(asc_vec2f a, asc_vec2f b) {
+    return ASC_VEC2F(a.x+b.x, a.y+b.y);
+}
+
+static inline asc_vec3f asc_vec3f_add(asc_vec3f a, asc_vec3f b) {
+    return ASC_VEC3F(a.x+b.x, a.y+b.y, a.z+b.z);
+}
 
 // --------------------------------------------------------------------------
 //   Matrix Functions

mercurial