浏览代码

Tests and implementation for float vector 2, 3 and 4

Kajetan Johannes Hammerle 3 周之前
父节点
当前提交
bf06ed795d
共有 2 个文件被更改,包括 360 次插入235 次删除
  1. 127 112
      src/Vector.c
  2. 233 123
      test/modules/VectorTests.c

+ 127 - 112
src/Vector.c

@@ -5,110 +5,9 @@
 
 #include "core/Utility.h"
 
+#define V2 CoreVector2
 #define V3 CoreVector3
-#define IV3 CoreIntVector3
-
-V3* coreAddSetV3(V3* r, const V3* a) {
-    return coreAddV3(r, r, a);
-}
-
-V3* coreAddV3(V3* r, const V3* a, const V3* b) {
-    for(int i = 0; i < 3; i++) {
-        r->data[i] = a->data[i] + b->data[i];
-    }
-    return r;
-}
-
-V3* coreSubSetV3(V3* r, const V3* a) {
-    return coreSubV3(r, r, a);
-}
-
-V3* coreSubV3(V3* r, const V3* a, const V3* b) {
-    for(int i = 0; i < 3; i++) {
-        r->data[i] = a->data[i] - b->data[i];
-    }
-    return r;
-}
-
-V3* coreMulSetV3(V3* r, const V3* a) {
-    return coreMulV3(r, r, a);
-}
-
-V3* coreMulV3(V3* r, const V3* a, const V3* b) {
-    for(int i = 0; i < 3; i++) {
-        r->data[i] = a->data[i] * b->data[i];
-    }
-    return r;
-}
-
-V3* coreDivSetV3(V3* r, const V3* a) {
-    return coreDivV3(r, r, a);
-}
-
-V3* coreDivV3(V3* r, const V3* a, const V3* b) {
-    for(int i = 0; i < 3; i++) {
-        r->data[i] = a->data[i] / b->data[i];
-    }
-    return r;
-}
-
-V3* coreMulSetV3F(V3* r, float f) {
-    return coreMulV3F(r, r, f);
-}
-
-V3* coreMulV3F(V3* r, const V3* a, float f) {
-    for(int i = 0; i < 3; i++) {
-        r->data[i] = a->data[i] * f;
-    }
-    return r;
-}
-
-V3* coreDivSetV3F(V3* r, float f) {
-    return coreDivV3F(r, r, f);
-}
-
-V3* coreDivV3F(V3* r, const V3* a, float f) {
-    for(int i = 0; i < 3; i++) {
-        r->data[i] = a->data[i] / f;
-    }
-    return r;
-}
-
-V3* coreInvertSetV3(V3* r) {
-    return coreInvertV3(r, r);
-}
-
-V3* coreInvertV3(V3* r, const V3* a) {
-    for(int i = 0; i < 3; i++) {
-        r->data[i] = -a->data[i];
-    }
-    return r;
-}
-
-float coreDotV3(const V3* a, const V3* b) {
-    float length = 0.0f;
-    for(int i = 0; i < 3; i++) {
-        length += a->data[i] * b->data[i];
-    }
-    return length;
-}
-
-float coreSquareLengthV3(const V3* a) {
-    return coreDotV3(a, a);
-}
-
-float coreLengthV3(const V3* a) {
-    return sqrtf(coreSquareLengthV3(a));
-}
-
-V3* coreNormalizeV3(V3* r) {
-    return coreMulSetV3F(r, 1.0f / coreLengthV3(r));
-}
-
-void coreToStringV3(const V3* a, char* buffer, size_t n) {
-    snprintf(buffer, n, "[%.3f, %.3f, %.3f]", (double)a->data[0],
-             (double)a->data[1], (double)a->data[2]);
-}
+#define V4 CoreVector4
 
 V3* coreAngles(V3* r, float lengthAngle, float widthAngle) {
     lengthAngle = coreDegreeToRadian(lengthAngle);
@@ -132,16 +31,132 @@ V3* coreCross(V3* r, const V3* a, const V3* b) {
     return r;
 }
 
-V3* coreConvertIV3(V3* r, const IV3* a) {
-    for(int i = 0; i < 3; i++) {
-        r->data[i] = (float)a->data[i];
+#define VECTOR_IMPL(T, N, SN, F, CN)                                           \
+    T* coreAddSet##SN(T* r, const T* a) {                                      \
+        return coreAdd##SN(r, r, a);                                           \
+    }                                                                          \
+                                                                               \
+    T* coreAdd##SN(T* r, const T* a, const T* b) {                             \
+        for(int i = 0; i < N; i++) {                                           \
+            r->data[i] = a->data[i] + b->data[i];                              \
+        }                                                                      \
+        return r;                                                              \
+    }                                                                          \
+                                                                               \
+    T* coreSubSet##SN(T* r, const T* a) {                                      \
+        return coreSub##SN(r, r, a);                                           \
+    }                                                                          \
+                                                                               \
+    T* coreSub##SN(T* r, const T* a, const T* b) {                             \
+        for(int i = 0; i < N; i++) {                                           \
+            r->data[i] = a->data[i] - b->data[i];                              \
+        }                                                                      \
+        return r;                                                              \
+    }                                                                          \
+                                                                               \
+    T* coreMulSet##SN(T* r, const T* a) {                                      \
+        return coreMul##SN(r, r, a);                                           \
+    }                                                                          \
+                                                                               \
+    T* coreMul##SN(T* r, const T* a, const T* b) {                             \
+        for(int i = 0; i < N; i++) {                                           \
+            r->data[i] = a->data[i] * b->data[i];                              \
+        }                                                                      \
+        return r;                                                              \
+    }                                                                          \
+                                                                               \
+    T* coreDivSet##SN(T* r, const T* a) {                                      \
+        return coreDiv##SN(r, r, a);                                           \
+    }                                                                          \
+                                                                               \
+    T* coreDiv##SN(T* r, const T* a, const T* b) {                             \
+        for(int i = 0; i < N; i++) {                                           \
+            r->data[i] = a->data[i] / b->data[i];                              \
+        }                                                                      \
+        return r;                                                              \
+    }                                                                          \
+                                                                               \
+    T* coreMulSet##SN##F(T* r, float f) {                                      \
+        return coreMul##SN##F(r, r, f);                                        \
+    }                                                                          \
+                                                                               \
+    T* coreMul##SN##F(T* r, const T* a, float f) {                             \
+        for(int i = 0; i < N; i++) {                                           \
+            r->data[i] = a->data[i] * f;                                       \
+        }                                                                      \
+        return r;                                                              \
+    }                                                                          \
+                                                                               \
+    T* coreDivSet##SN##F(T* r, float f) {                                      \
+        return coreDiv##SN##F(r, r, f);                                        \
+    }                                                                          \
+                                                                               \
+    T* coreDiv##SN##F(T* r, const T* a, float f) {                             \
+        for(int i = 0; i < N; i++) {                                           \
+            r->data[i] = a->data[i] / f;                                       \
+        }                                                                      \
+        return r;                                                              \
+    }                                                                          \
+                                                                               \
+    T* coreInvertSet##SN(T* r) {                                               \
+        return coreInvert##SN(r, r);                                           \
+    }                                                                          \
+                                                                               \
+    T* coreInvert##SN(T* r, const T* a) {                                      \
+        for(int i = 0; i < N; i++) {                                           \
+            r->data[i] = -a->data[i];                                          \
+        }                                                                      \
+        return r;                                                              \
+    }                                                                          \
+                                                                               \
+    float coreDot##SN(const T* a, const T* b) {                                \
+        float length = 0;                                                      \
+        for(int i = 0; i < N; i++) {                                           \
+            length += a->data[i] * b->data[i];                                 \
+        }                                                                      \
+        return length;                                                         \
+    }                                                                          \
+                                                                               \
+    float coreSquareLength##SN(const T* a) {                                   \
+        return coreDot##SN(a, a);                                              \
+    }                                                                          \
+                                                                               \
+    float coreLength##SN(const T* a) {                                         \
+        return sqrtf(coreSquareLength##SN(a));                                 \
+    }                                                                          \
+                                                                               \
+    T* coreNormalize##SN(T* r) {                                               \
+        return coreMulSet##SN##F(r, 1.0f / coreLength##SN(r));                 \
+    }                                                                          \
+                                                                               \
+    T* coreConvertI##SN(T* r, const CN* a) {                                   \
+        for(int i = 0; i < N; i++) {                                           \
+            r->data[i] = (float)a->data[i];                                    \
+        }                                                                      \
+        return r;                                                              \
+    }                                                                          \
+                                                                               \
+    CN* coreConvert##SN(CN* r, const T* a) {                                   \
+        for(int i = 0; i < N; i++) {                                           \
+            r->data[i] = (int)a->data[i];                                      \
+        }                                                                      \
+        return r;                                                              \
     }
-    return r;
+
+VECTOR_IMPL(CoreVector2, 2, V2, F, CoreIntVector2)
+VECTOR_IMPL(CoreVector3, 3, V3, F, CoreIntVector3)
+VECTOR_IMPL(CoreVector4, 4, V4, F, CoreIntVector4)
+
+void coreToStringV2(const V2* a, char* buffer, size_t n) {
+    snprintf(buffer, n, "[%.3f, %.3f]", (double)a->data[0], (double)a->data[1]);
 }
 
-IV3* coreConvertV3(IV3* r, const V3* a) {
-    for(int i = 0; i < 3; i++) {
-        r->data[i] = (int)a->data[i];
-    }
-    return r;
+void coreToStringV3(const V3* a, char* buffer, size_t n) {
+    snprintf(buffer, n, "[%.3f, %.3f, %.3f]", (double)a->data[0],
+             (double)a->data[1], (double)a->data[2]);
+}
+
+void coreToStringV4(const V4* a, char* buffer, size_t n) {
+    snprintf(buffer, n, "[%.3f, %.3f, %.3f, %.3f]", (double)a->data[0],
+             (double)a->data[1], (double)a->data[2], (double)a->data[3]);
 }

+ 233 - 123
test/modules/VectorTests.c

@@ -5,205 +5,315 @@
 
 const float eps = 0.0001f;
 
+#define V2 CoreVector2
+#define CV2(a, b, c, d) (&(V2){a, b})
+#define FV2(a, b) CV2(a, b, 0, 0)
+#define CV20 CV2(0, 0, 0, 0)
+
 #define V3 CoreVector3
-#define CV3(a, b, c)                                                           \
-    &(V3) {                                                                    \
-        a, b, c                                                                \
-    }
-#define CV30 CV3(0, 0, 0)
+#define CV3(a, b, c, d) (&(V3){a, b, c})
+#define FV3(a, b, c) CV3(a, b, c, 0)
+#define CV30 CV3(0, 0, 0, 0)
 
-#define IV3 CoreIntVector3
-#define CIV3(a, b, c)                                                          \
-    &(IV3) {                                                                   \
-        a, b, c                                                                \
-    }
-#define CIV30 CIV3(0, 0, 0)
+#define V4 CoreVector4
+#define CV4(a, b, c, d) (&(V4){a, b, c, d})
+#define CV40 CV4(0, 0, 0, 0)
+
+#define IV2 CoreIntVector2
+#define CIV2(a, b, c, d) (&(IV2){a, b})
+#define FIV2(a, b) CIV2(a, b, 0, 0)
+#define CIV20 CIV2(0, 0, 0, 0)
 
-static void testVector3B(const char* file, int line, const V3* wanted,
-                         const V3* actual) {
-    for(int i = 0; i < 3; i++) {
-        coreTestFloat(file, line, wanted->data[i], actual->data[i], eps);
+#define IV3 CoreIntVector3
+#define CIV3(a, b, c, d) (&(IV3){a, b, c})
+#define FIV3(a, b, c) CIV3(a, b, c, 0)
+#define CIV30 CIV3(0, 0, 0, 0)
+
+#define IV4 CoreIntVector4
+#define CIV4(a, b, c, d) (&(IV4){a, b, c, d})
+#define CIV40 CIV4(0, 0, 0, 0)
+
+static void testV(const char* file, int line, const float* wanted,
+                  const float* actual, size_t n) {
+    for(size_t i = 0; i < n; i++) {
+        coreTestFloat(file, line, wanted[i], actual[i], eps);
     }
 }
 
-#define testVector3(wanted, actual)                                            \
-    testVector3B(__FILE__, __LINE__, wanted, actual)
-
-static void testIntVector3(const IV3* wanted, const IV3* actual) {
-    for(int i = 0; i < 3; i++) {
-        CORE_TEST_INT(wanted->data[i], actual->data[i]);
+#define testV2(wanted, actual)                                                 \
+    testV(__FILE__, __LINE__, (wanted)->data, (actual)->data, 2)
+#define testV3(wanted, actual)                                                 \
+    testV(__FILE__, __LINE__, (wanted)->data, (actual)->data, 3)
+#define testV4(wanted, actual)                                                 \
+    testV(__FILE__, __LINE__, (wanted)->data, (actual)->data, 4)
+
+static void testIV(const char* file, int line, const int* wanted,
+                   const int* actual, size_t n) {
+    for(size_t i = 0; i < n; i++) {
+        coreTestInt(file, line, wanted[i], actual[i]);
     }
 }
 
+#define testIV2(wanted, actual)                                                \
+    testIV(__FILE__, __LINE__, (wanted)->data, (actual)->data, 2)
+#define testIV3(wanted, actual)                                                \
+    testIV(__FILE__, __LINE__, (wanted)->data, (actual)->data, 3)
+#define testIV4(wanted, actual)                                                \
+    testIV(__FILE__, __LINE__, (wanted)->data, (actual)->data, 4)
+
 static void testSetAngles() {
     float root = sqrtf(2) * 0.5f;
-    testVector3(CV3(1, 0, 0), coreAngles(CV30, 0, 0));
-    testVector3(CV3(root, 0, -root), coreAngles(CV30, 45, 0));
-    testVector3(CV3(0, 0, -1), coreAngles(CV30, 90, 0));
-    testVector3(CV3(-root, 0, -root), coreAngles(CV30, 135, 0));
-    testVector3(CV3(-1, 0, 0), coreAngles(CV30, 180, 0));
-    testVector3(CV3(-root, 0, root), coreAngles(CV30, 225, 0));
-    testVector3(CV3(0, 0, 1), coreAngles(CV30, 270, 0));
-    testVector3(CV3(root, 0, root), coreAngles(CV30, 315, 0));
-
-    testVector3(CV3(0, 1, 0), coreAngles(CV30, 0, 90));
-    testVector3(CV3(0, 1, 0), coreAngles(CV30, 90, 90));
-    testVector3(CV3(0, 1, 0), coreAngles(CV30, 180, 90));
-    testVector3(CV3(0, 1, 0), coreAngles(CV30, 270, 90));
-
-    testVector3(CV3(0, -1, 0), coreAngles(CV30, 0, -90));
-    testVector3(CV3(0, -1, 0), coreAngles(CV30, 90, -90));
-    testVector3(CV3(0, -1, 0), coreAngles(CV30, 180, -90));
-    testVector3(CV3(0, -1, 0), coreAngles(CV30, 270, -90));
-
-    testVector3(CV3(root, root, 0), coreAngles(CV30, 0, 45));
-    testVector3(CV3(0, root, -root), coreAngles(CV30, 90, 45));
-    testVector3(CV3(-root, root, 0), coreAngles(CV30, 180, 45));
-    testVector3(CV3(0, root, root), coreAngles(CV30, 270, 45));
-
-    testVector3(CV3(root, -root, 0), coreAngles(CV30, 0, -45));
-    testVector3(CV3(0, -root, -root), coreAngles(CV30, 90, -45));
-    testVector3(CV3(-root, -root, 0), coreAngles(CV30, 180, -45));
-    testVector3(CV3(0, -root, root), coreAngles(CV30, 270, -45));
-
-    testVector3(CV3(0.5f, root, -0.5f), coreAngles(CV30, 45, 45));
+    testV3(FV3(1, 0, 0), coreAngles(CV30, 0, 0));
+    testV3(FV3(root, 0, -root), coreAngles(CV30, 45, 0));
+    testV3(FV3(0, 0, -1), coreAngles(CV30, 90, 0));
+    testV3(FV3(-root, 0, -root), coreAngles(CV30, 135, 0));
+    testV3(FV3(-1, 0, 0), coreAngles(CV30, 180, 0));
+    testV3(FV3(-root, 0, root), coreAngles(CV30, 225, 0));
+    testV3(FV3(0, 0, 1), coreAngles(CV30, 270, 0));
+    testV3(FV3(root, 0, root), coreAngles(CV30, 315, 0));
+
+    testV3(FV3(0, 1, 0), coreAngles(CV30, 0, 90));
+    testV3(FV3(0, 1, 0), coreAngles(CV30, 90, 90));
+    testV3(FV3(0, 1, 0), coreAngles(CV30, 180, 90));
+    testV3(FV3(0, 1, 0), coreAngles(CV30, 270, 90));
+
+    testV3(FV3(0, -1, 0), coreAngles(CV30, 0, -90));
+    testV3(FV3(0, -1, 0), coreAngles(CV30, 90, -90));
+    testV3(FV3(0, -1, 0), coreAngles(CV30, 180, -90));
+    testV3(FV3(0, -1, 0), coreAngles(CV30, 270, -90));
+
+    testV3(FV3(root, root, 0), coreAngles(CV30, 0, 45));
+    testV3(FV3(0, root, -root), coreAngles(CV30, 90, 45));
+    testV3(FV3(-root, root, 0), coreAngles(CV30, 180, 45));
+    testV3(FV3(0, root, root), coreAngles(CV30, 270, 45));
+
+    testV3(FV3(root, -root, 0), coreAngles(CV30, 0, -45));
+    testV3(FV3(0, -root, -root), coreAngles(CV30, 90, -45));
+    testV3(FV3(-root, -root, 0), coreAngles(CV30, 180, -45));
+    testV3(FV3(0, -root, root), coreAngles(CV30, 270, -45));
+
+    testV3(FV3(0.5f, root, -0.5f), coreAngles(CV30, 45, 45));
 }
 
 static void testCross() {
-    testVector3(CV3(0, 0, 1), coreCross(CV30, CV3(1, 0, 0), CV3(0, 1, 0)));
-    testVector3(CV3(0, -1, 0), coreCross(CV30, CV3(1, 0, 0), CV3(0, 0, 1)));
-    testVector3(CV3(0, 0, -1), coreCross(CV30, CV3(0, 1, 0), CV3(1, 0, 0)));
-    testVector3(CV3(1, 0, 0), coreCross(CV30, CV3(0, 1, 0), CV3(0, 0, 1)));
-    testVector3(CV3(0, 1, 0), coreCross(CV30, CV3(0, 0, 1), CV3(1, 0, 0)));
-    testVector3(CV3(-1, 0, 0), coreCross(CV30, CV3(0, 0, 1), CV3(0, 1, 0)));
+    testV3(FV3(0, 0, 1), coreCross(CV30, FV3(1, 0, 0), FV3(0, 1, 0)));
+    testV3(FV3(0, -1, 0), coreCross(CV30, FV3(1, 0, 0), FV3(0, 0, 1)));
+    testV3(FV3(0, 0, -1), coreCross(CV30, FV3(0, 1, 0), FV3(1, 0, 0)));
+    testV3(FV3(1, 0, 0), coreCross(CV30, FV3(0, 1, 0), FV3(0, 0, 1)));
+    testV3(FV3(0, 1, 0), coreCross(CV30, FV3(0, 0, 1), FV3(1, 0, 0)));
+    testV3(FV3(-1, 0, 0), coreCross(CV30, FV3(0, 0, 1), FV3(0, 1, 0)));
 }
 
+#define TEST_SET_ADD(T)                                                        \
+    {                                                                          \
+        T v = {0};                                                             \
+        coreAddSet##T(&v, C##T(1, 2, 3, 4));                                   \
+        test##T(C##T(1, 2, 3, 4), &v);                                         \
+        coreAddSet##T(&v, C##T(2, 3, 4, 5));                                   \
+        test##T(C##T(3, 5, 7, 9), &v);                                         \
+    }
+
 static void testSetAdd() {
-    V3 v = {0};
-    coreAddSetV3(&v, CV3(1, 2, 3));
-    testVector3(CV3(1, 2, 3), &v);
-    coreAddSetV3(&v, CV3(2, 3, 4));
-    testVector3(CV3(3, 5, 7), &v);
+    TEST_SET_ADD(V2)
+    TEST_SET_ADD(V3)
+    TEST_SET_ADD(V4)
 }
 
 static void testAdd() {
-    testVector3(CV3(1, 2, 3), coreAddV3(CV30, CV30, CV3(1, 2, 3)));
-    testVector3(CV3(3, 5, 7), coreAddV3(CV30, CV3(1, 2, 3), CV3(2, 3, 4)));
+    testV3(FV3(1, 2, 3), coreAddV3(CV30, CV30, FV3(1, 2, 3)));
+    testV3(FV3(3, 5, 7), coreAddV3(CV30, FV3(1, 2, 3), FV3(2, 3, 4)));
 }
 
+#define TEST_SET_SUB(T)                                                        \
+    {                                                                          \
+        T v = {0};                                                             \
+        coreSubSet##T(&v, C##T(1, 2, 3, 4));                                   \
+        test##T(C##T(-1, -2, -3, -4), &v);                                     \
+        coreSubSet##T(&v, C##T(2, 3, 4, 5));                                   \
+        test##T(C##T(-3, -5, -7, -9), &v);                                     \
+    }
+
 static void testSetSub() {
-    V3 v = {0};
-    coreSubSetV3(&v, CV3(1, 2, 3));
-    testVector3(CV3(-1, -2, -3), &v);
-    coreSubSetV3(&v, CV3(2, 3, 4));
-    testVector3(CV3(-3, -5, -7), &v);
+    TEST_SET_SUB(V2)
+    TEST_SET_SUB(V3)
+    TEST_SET_SUB(V4)
 }
 
 static void testSub() {
-    testVector3(CV3(1, 2, 3), coreSubV3(CV30, CV30, CV3(-1, -2, -3)));
-    testVector3(CV3(-1, -1, -1), coreSubV3(CV30, CV3(1, 2, 3), CV3(2, 3, 4)));
+    testV3(FV3(1, 2, 3), coreSubV3(CV30, CV30, FV3(-1, -2, -3)));
+    testV3(FV3(-1, -1, -1), coreSubV3(CV30, FV3(1, 2, 3), FV3(2, 3, 4)));
 }
 
+#define TEST_SET_MUL(T)                                                        \
+    {                                                                          \
+        T v = *C##T(1, 2, 3, 4);                                               \
+        coreMulSet##T##F(&v, 3);                                               \
+        test##T(C##T(3, 6, 9, 12), &v);                                        \
+        coreMulSet##T##F(&v, -2);                                              \
+        test##T(C##T(-6, -12, -18, -24), &v);                                  \
+    }
+
 static void testSetMul() {
-    V3 v = {1, 2, 3};
-    coreMulSetV3F(&v, 3);
-    testVector3(CV3(3, 6, 9), &v);
-    coreMulSetV3F(&v, -2);
-    testVector3(CV3(-6, -12, -18), &v);
+    TEST_SET_MUL(V2)
+    TEST_SET_MUL(V3)
+    TEST_SET_MUL(V4)
 }
 
 static void testMul() {
-    testVector3(CV3(3, 6, 9), coreMulV3F(CV30, CV3(1, 2, 3), 3));
+    testV3(FV3(3, 6, 9), coreMulV3F(CV30, FV3(1, 2, 3), 3));
 }
 
+#define TEST_SET_MUL_VECTOR(T)                                                 \
+    {                                                                          \
+        T v = *C##T(1, 2, 3, 4);                                               \
+        coreMulSet##T(&v, C##T(2, 1, 3, 4));                                   \
+        test##T(C##T(2, 2, 9, 16), &v);                                        \
+        coreMulSet##T(&v, C##T(-3, 4, -2, -2));                                \
+        test##T(C##T(-6, 8, -18, -32), &v);                                    \
+    }
+
 static void testSetMulVector() {
-    V3 v = {1, 2, 3};
-    coreMulSetV3(&v, CV3(2, 1, 3));
-    testVector3(CV3(2, 2, 9), &v);
-    coreMulSetV3(&v, CV3(-3, 4, -2));
-    testVector3(CV3(-6, 8, -18), &v);
+    TEST_SET_MUL_VECTOR(V2)
+    TEST_SET_MUL_VECTOR(V3)
+    TEST_SET_MUL_VECTOR(V4)
 }
 
 static void testMulVector() {
-    testVector3(CV3(-2, -2, -9),
-                coreMulV3(CV30, CV3(2, 1, 3), CV3(-1, -2, -3)));
-    testVector3(CV3(2, 2, 9), coreMulV3(CV30, CV3(1, 2, 3), CV3(2, 1, 3)));
+    testV3(FV3(-2, -2, -9), coreMulV3(CV30, FV3(2, 1, 3), FV3(-1, -2, -3)));
+    testV3(FV3(2, 2, 9), coreMulV3(CV30, FV3(1, 2, 3), FV3(2, 1, 3)));
 }
 
+#define TEST_SET_DIV(T)                                                        \
+    {                                                                          \
+        T v = *C##T(12, 24, 9, 27);                                            \
+        coreDivSet##T##F(&v, 3);                                               \
+        test##T(C##T(4, 8, 3, 9), &v);                                         \
+        coreDivSet##T##F(&v, -2);                                              \
+        test##T(C##T(-2, -4, -1.5f, -4.5f), &v);                               \
+    }
+
 static void testSetDiv() {
-    V3 v = {12, 24, 9};
-    coreDivSetV3F(&v, 3);
-    testVector3(CV3(4, 8, 3), &v);
-    coreDivSetV3F(&v, -2);
-    testVector3(CV3(-2, -4, -1.5f), &v);
+    TEST_SET_DIV(V2);
+    TEST_SET_DIV(V3);
+    TEST_SET_DIV(V4);
 }
 
 static void testDiv() {
-    testVector3(CV3(-1, -2, -3), coreDivV3F(CV30, CV3(-3, -6, -9), 3));
+    testV3(FV3(-1, -2, -3), coreDivV3F(CV30, FV3(-3, -6, -9), 3));
 }
 
+#define TEST_SET_DIV_VECTOR(T)                                                 \
+    {                                                                          \
+        T v = *C##T(3, 4, 6, 8);                                               \
+        coreDivSet##T(&v, C##T(2, 1, 3, 4));                                   \
+        test##T(C##T(1.5f, 4, 2, 2), &v);                                      \
+        coreDivSet##T(&v, C##T(-3, 4, -2, -1));                                \
+        test##T(C##T(-0.5f, 1, -1, -2), &v);                                   \
+    }
+
 static void testSetDivVector() {
-    V3 v = {3, 4, 6};
-    coreDivSetV3(&v, CV3(2, 1, 3));
-    testVector3(CV3(1.5f, 4, 2), &v);
-    coreDivSetV3(&v, CV3(-3, 4, -2));
-    testVector3(CV3(-0.5f, 1, -1), &v);
+    TEST_SET_DIV_VECTOR(V2)
+    TEST_SET_DIV_VECTOR(V3)
+    TEST_SET_DIV_VECTOR(V4)
 }
 
 static void testDivVector() {
-    testVector3(CV3(-2, -0.5f, -1),
-                coreDivV3(CV30, CV3(2, 1, 3), CV3(-1, -2, -3)));
-    testVector3(CV3(0.5f, 2, 1), coreDivV3(CV30, CV3(1, 2, 3), CV3(2, 1, 3)));
+    testV3(FV3(-2, -0.5f, -1), coreDivV3(CV30, FV3(2, 1, 3), FV3(-1, -2, -3)));
+    testV3(FV3(0.5f, 2, 1), coreDivV3(CV30, FV3(1, 2, 3), FV3(2, 1, 3)));
 }
 
 static void testSetInvert() {
-    testVector3(CV3(-1, 2, 3), coreInvertSetV3(CV3(1, -2, -3)));
+    testV2(FV2(-1, 2), coreInvertSetV2(FV2(1, -2)));
+    testV3(FV3(-1, 2, 3), coreInvertSetV3(FV3(1, -2, -3)));
+    testV4(CV4(-1, 2, 3, 4), coreInvertSetV4(CV4(1, -2, -3, -4)));
 }
 
 static void testInvert() {
-    testVector3(CV3(-1, 2, 3), coreInvertV3(CV30, CV3(1, -2, -3)));
+    testV3(FV3(-1, 2, 3), coreInvertV3(CV30, FV3(1, -2, -3)));
 }
 
 static void testDot() {
-    CORE_TEST_FLOAT(9, coreDotV3(CV3(-4, 2, -3), CV3(-1, -2, -3)), eps);
-    CORE_TEST_FLOAT(-22, coreDotV3(CV3(2, 2, -4), CV3(1, -2, 5)), eps);
+    CORE_TEST_FLOAT(0, coreDotV2(FV2(-4, 2), FV2(-1, -2)), eps);
+    CORE_TEST_FLOAT(9, coreDotV3(FV3(-4, 2, -3), FV3(-1, -2, -3)), eps);
+    CORE_TEST_FLOAT(16, coreDotV4(CV4(-4, 2, -3, 1), CV4(-1, -2, -3, 7)), eps);
 }
 
 static void testSquareLength() {
-    CORE_TEST_FLOAT(29, coreSquareLengthV3(CV3(-4, 2, -3)), eps);
-    CORE_TEST_FLOAT(24, coreSquareLengthV3(CV3(2, 2, -4)), eps);
+    CORE_TEST_FLOAT(20, coreSquareLengthV2(FV2(-4, 2)), eps);
+    CORE_TEST_FLOAT(29, coreSquareLengthV3(FV3(-4, 2, -3)), eps);
+    CORE_TEST_FLOAT(54, coreSquareLengthV4(CV4(-4, 2, -3, 5)), eps);
 }
 
 static void testLength() {
-    CORE_TEST_FLOAT(3, coreLengthV3(CV3(-2, 2, -1)), eps);
-    CORE_TEST_FLOAT(7, coreLengthV3(CV3(6, 2, -3)), eps);
+    CORE_TEST_FLOAT(5, coreLengthV2(FV2(-3, 4)), eps);
+    CORE_TEST_FLOAT(13, coreLengthV2(FV2(5, 12)), eps);
+    CORE_TEST_FLOAT(3, coreLengthV3(FV3(-2, 2, -1)), eps);
+    CORE_TEST_FLOAT(7, coreLengthV3(FV3(6, 2, -3)), eps);
+    CORE_TEST_FLOAT(3, coreLengthV4(CV4(-2, 2, 0, -1)), eps);
+    CORE_TEST_FLOAT(9, coreLengthV4(CV4(6, 0, -6, 3)), eps);
 }
 
 static void testNormalize() {
-    V3 v1 = {-2, 2, -1};
-    V3 v2;
-    coreMulV3F(&v2, &v1, 1.0f / 3.0f);
-    coreNormalizeV3(&v1);
-    testVector3(&v2, &v1);
-
-    V3 v3 = {6, 2, -3};
-    V3 v4;
-    coreMulV3F(&v4, &v3, 1.0f / 7.0f);
-    coreNormalizeV3(&v3);
-    testVector3(&v4, &v3);
+    {
+        V2 v1 = {-15, 20};
+        V2 v2;
+        coreMulV2F(&v2, &v1, 1.0f / 25.0f);
+        coreNormalizeV2(&v1);
+        testV2(&v2, &v1);
+
+        V2 v3 = {15, 36};
+        V2 v4;
+        coreMulV2F(&v4, &v3, 1.0f / 39.0f);
+        coreNormalizeV2(&v3);
+        testV2(&v4, &v3);
+    }
+    {
+        V3 v1 = {-2, 2, -1};
+        V3 v2;
+        coreMulV3F(&v2, &v1, 1.0f / 3.0f);
+        coreNormalizeV3(&v1);
+        testV3(&v2, &v1);
+
+        V3 v3 = {6, 2, -3};
+        V3 v4;
+        coreMulV3F(&v4, &v3, 1.0f / 7.0f);
+        coreNormalizeV3(&v3);
+        testV3(&v4, &v3);
+    }
+    {
+        V4 v1 = {-2, 2, 0, -1};
+        V4 v2;
+        coreMulV4F(&v2, &v1, 1.0f / 3.0f);
+        coreNormalizeV4(&v1);
+        testV4(&v2, &v1);
+
+        V4 v3 = {6, 0, -6, 3};
+        V4 v4;
+        coreMulV4F(&v4, &v3, 1.0f / 9.0f);
+        coreNormalizeV4(&v3);
+        testV4(&v4, &v3);
+    }
 }
 
 static void testCast() {
-    testVector3(CV3(-2.0f, 2.0f, 9.0f), coreConvertIV3(CV30, CIV3(-2, 2, 9)));
-    testIntVector3(CIV3(-2, 2, 9),
-                   coreConvertV3(CIV30, CV3(-2.5f, 2.6f, 9.0f)));
+    testV2(FV2(-2.0f, 2.0f), coreConvertIV2(CV20, FIV2(-2, 2)));
+    testIV2(FIV2(-2, 2), coreConvertV2(CIV20, FV2(-2.5f, 2.6f)));
+    testV3(FV3(-2.0f, 2.0f, 9.0f), coreConvertIV3(CV30, FIV3(-2, 2, 9)));
+    testIV3(FIV3(-2, 2, 9), coreConvertV3(CIV30, FV3(-2.5f, 2.6f, 9.0f)));
+    testV4(CV4(-2.0f, 2.0f, 9.0f, 6.0f),
+           coreConvertIV4(CV40, CIV4(-2, 2, 9, 6)));
+    testIV4(CIV4(-2, 2, 9, 3),
+            coreConvertV4(CIV40, CV4(-2.5f, 2.6f, 9.0f, 3.2f)));
 }
 
 static void testToString() {
-    V3 v = {4, 5, 6};
     char buffer[64];
-    coreToStringV3(&v, buffer, sizeof(buffer));
+    coreToStringV2(FV2(4, 5), buffer, sizeof(buffer));
+    CORE_TEST_STRING("[4.000, 5.000]", buffer);
+    coreToStringV3(FV3(4, 5, 6), buffer, sizeof(buffer));
     CORE_TEST_STRING("[4.000, 5.000, 6.000]", buffer);
+    coreToStringV4(CV4(4, 5, 6, 7), buffer, sizeof(buffer));
+    CORE_TEST_STRING("[4.000, 5.000, 6.000, 7.000]", buffer);
 }
 
 void coreTestVector() {