Bladeren bron

Imports for Plane and Frustum, refactoring

Kajetan Johannes Hammerle 11 maanden geleden
bovenliggende
commit
feb8e21a85

+ 9 - 1
include/core/Frustum.h

@@ -23,6 +23,14 @@ void coreUpdateFrustumPlanes(CoreFrustum* f, const CoreVector3* pos,
 bool coreIsInsideFrustum(const CoreFrustum* f, const CoreVector3* pos);
 bool coreIsInsideFrustumRadius(const CoreFrustum* f, const CoreVector3* pos,
                                float radius);
-size_t coreToStringFrustum(const CoreFrustum* f, char* buffer, size_t n);
+
+#ifdef IMPORT_CORE
+#define Frustum CoreFrustum
+#define initFrustum coreInitFrustum
+#define updateProjection coreUpdateProjection
+#define updateFrustumPlanes coreUpdateFrustumPlanes
+#define isInsideFrustum coreIsInsideFrustum
+#define isInsideFrustumRadius coreIsInsideFrustumRadius
+#endif
 
 #endif

+ 3 - 3
include/core/Matrix.h

@@ -4,9 +4,10 @@
 #include "core/Quaternion.h"
 #include "core/Vector.h"
 
-typedef struct {
+struct CoreMatrixT {
     CoreVector4 data[4];
-} CoreMatrix;
+};
+typedef struct CoreMatrixT CoreMatrix;
 
 #define CORE_ZERO_MATRIX ((CoreMatrix){0})
 #define CORE_UNIT_MATRIX                                                       \
@@ -30,7 +31,6 @@ CoreMatrix* coreRotateMatrixX(CoreMatrix* m, float degrees);
 CoreMatrix* coreRotateMatrixY(CoreMatrix* m, float degrees);
 CoreMatrix* coreRotateMatrixZ(CoreMatrix* m, float degrees);
 CoreMatrix* coreRotateMatrix(CoreMatrix* m, const CoreQuaternion* q);
-size_t coreToStringMatrix(const CoreMatrix* m, char* buffer, size_t n);
 
 #ifdef IMPORT_CORE
 #define Matrix CoreMatrix

+ 9 - 3
include/core/Plane.h

@@ -3,14 +3,20 @@
 
 #include "core/Vector.h"
 
-typedef struct {
+struct CorePlaneT {
     CoreVector3 abc;
     float d;
-} CorePlane;
+};
+typedef struct CorePlaneT CorePlane;
 
 void coreInitPlane(CorePlane* p, const CoreVector3* a, const CoreVector3* b,
                    const CoreVector3* c);
 float coreSignedDistance(const CorePlane* p, const CoreVector3* v);
-size_t coreToStringPlane(const CorePlane* p, char* buffer, size_t n);
+
+#ifdef IMPORT_CORE
+#define Plane CorePlane
+#define initPlane coreInitPlane
+#define signedDistance coreSignedDistance
+#endif
 
 #endif

+ 7 - 1
include/core/ToString.h

@@ -17,6 +17,8 @@ void coreStringAdd(size_t* w, char** buffer, size_t* n, size_t shift);
 
 CORE_STRUCT_TO_STRING(BitArray)
 CORE_STRUCT_TO_STRING(Box)
+CORE_STRUCT_TO_STRING(Matrix)
+CORE_STRUCT_TO_STRING(Plane)
 
 #ifdef IMPORT_CORE
 #define toStringSize coreToStringSize
@@ -24,6 +26,8 @@ CORE_STRUCT_TO_STRING(Box)
 #define stringAdd coreStringAdd
 #define toStringBitArray coreToStringBitArray
 #define toStringBox coreToStringBox
+#define toStringMatrix coreToStringMatrix
+#define toStringPlane coreToStringPlane
 
 // clang-format off
 #define CORE_PAIR(a, b) a: b
@@ -36,7 +40,9 @@ CORE_STRUCT_TO_STRING(Box)
     _Generic((t),                                                              \
         char*: coreToString,                                                   \
         CORE_STRUCT_PAIR(BitArray),                                            \
-        CORE_STRUCT_PAIR(Box))(t, __VA_ARGS__)
+        CORE_STRUCT_PAIR(Box),                                                 \
+        CORE_STRUCT_PAIR(Matrix),                                              \
+        CORE_STRUCT_PAIR(Plane))(t, __VA_ARGS__)
 #endif
 
 #endif

+ 4 - 0
include/core/Types.h

@@ -16,4 +16,8 @@ typedef uint8_t u8;
 
 typedef size_t (*CoreToString)(const void* data, char* buffer, size_t n);
 
+#ifdef IMPORT_CORE
+#define ARRAY_LENGTH CORE_ARRAY_LENGTH
+#endif
+
 #endif

+ 4 - 1
include/core/Vector.h

@@ -197,7 +197,10 @@ CORE_DEFINE_VECTOR_CONVERSION(CoreVector4, V4, CoreIntVector4, IV4);
 
 #define SELECT_VECTOR(_1, _2, _3, _4, name, ...) name
 #define V(...)                                                                 \
-    ((SELECT_VECTOR(__VA_ARGS__, Vector4, Vector3, Vector2)){__VA_ARGS__})
+    ((SELECT_VECTOR(__VA_ARGS__, Vector4, Vector3, Vector2, 0)){__VA_ARGS__})
+#define IV(...)                                                                \
+    ((SELECT_VECTOR(__VA_ARGS__, IntVector4, IntVector3, IntVector2, 0)){      \
+        __VA_ARGS__})
 
 #endif
 

+ 59 - 70
src/Frustum.c

@@ -1,39 +1,34 @@
 #include "core/Frustum.h"
 
 #include <math.h>
-#include <stdio.h>
 
-#include "core/ToString.h"
+#include "core/Generic.h"
 #include "core/Utility.h"
 
 #define CV30 (&CORE_VECTOR3)
-#define CV4(a, b, c, d) ((CoreVector4){{a, b, c, d}})
 
-void coreInitFrustum(CoreFrustum* f, float fieldOfView, float nearClip,
-                     float farClip) {
-    f->tan = tanf(coreDegreeToRadian(fieldOfView) * 0.5f);
+void initFrustum(Frustum* f, float fieldOfView, float nearClip, float farClip) {
+    f->tan = tanf(degreeToRadian(fieldOfView) * 0.5f);
     f->nearClip = nearClip;
     f->farClip = farClip;
 
     float diff = 1.0f / (nearClip - farClip);
-    f->projection.data[0] = CV4(0.0f, 0.0f, 0.0f, 0.0f);
-    f->projection.data[1] = CV4(0.0f, 1.0f / f->tan, 0.0f, 0.0f);
-    f->projection.data[2] = CV4(0.0f, 0.0f, (nearClip + farClip) * diff,
-                                (2.0f * nearClip * farClip) * diff);
-    f->projection.data[3] = CV4(0.0f, 0.0f, -1.0f, 0.0f);
+    f->projection.data[0] = V(0.0f, 0.0f, 0.0f, 0.0f);
+    f->projection.data[1] = V(0.0f, 1.0f / f->tan, 0.0f, 0.0f);
+    f->projection.data[2] = V(0.0f, 0.0f, (nearClip + farClip) * diff,
+                              (2.0f * nearClip * farClip) * diff);
+    f->projection.data[3] = V(0.0f, 0.0f, -1.0f, 0.0f);
 }
 
-const CoreMatrix* coreUpdateProjection(CoreFrustum* f,
-                                       const CoreIntVector2* size) {
+const Matrix* updateProjection(Frustum* f, const IntVector2* size) {
     float x = (float)size->data[1] / (f->tan * (float)size->data[0]);
-    f->projection.data[0] = CV4(x, 0.0f, 0.0f, 0.0f);
+    f->projection.data[0] = V(x, 0.0f, 0.0f, 0.0f);
     return &f->projection;
 }
 
-void coreUpdateFrustumPlanes(CoreFrustum* f, const CoreVector3* pos,
-                             const CoreVector3* right, const CoreVector3* up,
-                             const CoreVector3* front,
-                             const CoreIntVector2* size) {
+void updateFrustumPlanes(Frustum* f, const Vector3* pos, const Vector3* right,
+                         const Vector3* up, const Vector3* front,
+                         const IntVector2* size) {
     float aspect = (float)size->data[0] / (float)size->data[1];
 
     float hNearHeight = f->tan * f->nearClip;
@@ -42,68 +37,62 @@ void coreUpdateFrustumPlanes(CoreFrustum* f, const CoreVector3* pos,
     float hFarHeight = f->tan * f->farClip;
     float hFarWidth = hFarHeight * aspect;
 
-    CoreVector3 fCenter;
-    coreAddV3(&fCenter, pos, coreMulV3F(CV30, front, f->farClip));
-    CoreVector3 upFar;
-    coreMulV3F(&upFar, up, hFarHeight);
-    CoreVector3 rightFar;
-    coreMulV3F(&rightFar, right, hFarWidth);
-
-    CoreVector3 fTopLeft;
-    coreAddV3(&fTopLeft, &fCenter, coreSubV3(CV30, &upFar, &rightFar));
-    CoreVector3 fTopRight;
-    coreAddV3(&fTopRight, &fCenter, coreAddV3(CV30, &upFar, &rightFar));
-    CoreVector3 fBottomRight;
-    coreSubV3(&fBottomRight, &fCenter, coreSubV3(CV30, &upFar, &rightFar));
-
-    CoreVector3 nCenter;
-    coreAddV3(&nCenter, pos, coreMulV3F(CV30, front, f->nearClip));
-    CoreVector3 upNear;
-    coreMulV3F(&upNear, up, hNearHeight);
-    CoreVector3 rightNear;
-    coreMulV3F(&rightNear, right, hNearWidth);
-
-    CoreVector3 nTopLeft;
-    coreAddV3(&nTopLeft, &nCenter, coreSubV3(CV30, &upNear, &rightNear));
-    CoreVector3 nBottomLeft;
-    coreSubV3(&nBottomLeft, &nCenter, coreAddV3(CV30, &upNear, &rightNear));
-    CoreVector3 nBottomRight;
-    coreSubV3(&nBottomRight, &nCenter, coreSubV3(CV30, &upNear, &rightNear));
-
-    coreInitPlane(f->planes + 0, &nBottomRight, &nTopLeft,
-                  &nBottomLeft); // n plane
-    coreInitPlane(f->planes + 1, &fTopRight, &fBottomRight,
-                  &fTopLeft); // f plane
-    coreInitPlane(f->planes + 2, &nBottomRight, &nBottomLeft,
-                  &fBottomRight); // bottom plane
-    coreInitPlane(f->planes + 3, &fTopLeft, &nTopLeft, &fTopRight); // top plane
-    coreInitPlane(f->planes + 4, &nBottomLeft, &nTopLeft,
-                  &fTopLeft); // left plane
-    coreInitPlane(f->planes + 5, &fBottomRight, &fTopRight,
-                  &nBottomRight); // right plane
+    Vector3 fCenter;
+    add(&fCenter, pos, mul(CV30, front, f->farClip));
+    Vector3 upFar;
+    mul(&upFar, up, hFarHeight);
+    Vector3 rightFar;
+    mul(&rightFar, right, hFarWidth);
+
+    Vector3 fTopLeft;
+    add(&fTopLeft, &fCenter, sub(CV30, &upFar, &rightFar));
+    Vector3 fTopRight;
+    add(&fTopRight, &fCenter, add(CV30, &upFar, &rightFar));
+    Vector3 fBottomRight;
+    sub(&fBottomRight, &fCenter, sub(CV30, &upFar, &rightFar));
+
+    Vector3 nCenter;
+    add(&nCenter, pos, mul(CV30, front, f->nearClip));
+    Vector3 upNear;
+    mul(&upNear, up, hNearHeight);
+    Vector3 rightNear;
+    mul(&rightNear, right, hNearWidth);
+
+    Vector3 nTopLeft;
+    add(&nTopLeft, &nCenter, sub(CV30, &upNear, &rightNear));
+    Vector3 nBottomLeft;
+    sub(&nBottomLeft, &nCenter, add(CV30, &upNear, &rightNear));
+    Vector3 nBottomRight;
+    sub(&nBottomRight, &nCenter, sub(CV30, &upNear, &rightNear));
+
+    // near plane
+    initPlane(f->planes + 0, &nBottomRight, &nTopLeft, &nBottomLeft);
+    // far plane
+    initPlane(f->planes + 1, &fTopRight, &fBottomRight, &fTopLeft);
+    // bottom plane
+    initPlane(f->planes + 2, &nBottomRight, &nBottomLeft, &fBottomRight);
+    // top plane
+    initPlane(f->planes + 3, &fTopLeft, &nTopLeft, &fTopRight);
+    // left plane
+    initPlane(f->planes + 4, &nBottomLeft, &nTopLeft, &fTopLeft);
+    // right plane
+    initPlane(f->planes + 5, &fBottomRight, &fTopRight, &nBottomRight);
 }
 
-bool coreIsInsideFrustum(const CoreFrustum* f, const CoreVector3* pos) {
-    for(size_t i = 0; i < CORE_ARRAY_LENGTH(f->planes); i++) {
-        if(coreSignedDistance(f->planes + i, pos) < 0.0f) {
+bool isInsideFrustum(const Frustum* f, const Vector3* pos) {
+    for(size_t i = 0; i < ARRAY_LENGTH(f->planes); i++) {
+        if(signedDistance(f->planes + i, pos) < 0.0f) {
             return false;
         }
     }
     return true;
 }
 
-bool coreIsInsideFrustumRadius(const CoreFrustum* f, const CoreVector3* pos,
-                               float radius) {
-    for(size_t i = 0; i < CORE_ARRAY_LENGTH(f->planes); i++) {
-        if(coreSignedDistance(f->planes + i, pos) < -radius) {
+bool isInsideFrustumRadius(const Frustum* f, const Vector3* pos, float radius) {
+    for(size_t i = 0; i < ARRAY_LENGTH(f->planes); i++) {
+        if(signedDistance(f->planes + i, pos) < -radius) {
             return false;
         }
     }
     return true;
 }
-
-size_t coreToStringFrustum(const CoreFrustum* f, char* buffer, size_t n) {
-    return coreToString(
-        buffer, n, "(tan = %.3f, nearClip = %.3f, farClip = %.3f)",
-        (double)f->tan, (double)f->nearClip, (double)f->farClip);
-}

+ 4 - 18
src/Matrix.c

@@ -114,26 +114,12 @@ Matrix* rotateMatrix(Matrix* m, const Quaternion* q) {
     Vector3 b;
     Vector3 c;
     Vector3 d;
-    mul(&a, q, (&(Vector3){{M(m, 0, 0), M(m, 1, 0), M(m, 2, 0)}}));
-    mul(&b, q, (&(Vector3){{M(m, 0, 1), M(m, 1, 1), M(m, 2, 1)}}));
-    mul(&c, q, (&(Vector3){{M(m, 0, 2), M(m, 1, 2), M(m, 2, 2)}}));
-    mul(&d, q, (&(Vector3){{M(m, 0, 3), M(m, 1, 3), M(m, 2, 3)}}));
+    mul(&a, q, &V(M(m, 0, 0), M(m, 1, 0), M(m, 2, 0)));
+    mul(&b, q, &V(M(m, 0, 1), M(m, 1, 1), M(m, 2, 1)));
+    mul(&c, q, &V(M(m, 0, 2), M(m, 1, 2), M(m, 2, 2)));
+    mul(&d, q, &V(M(m, 0, 3), M(m, 1, 3), M(m, 2, 3)));
     m->data[0] = (Vector4){{a.data[0], b.data[0], c.data[0], d.data[0]}};
     m->data[1] = (Vector4){{a.data[1], b.data[1], c.data[1], d.data[1]}};
     m->data[2] = (Vector4){{a.data[2], b.data[2], c.data[2], d.data[2]}};
     return m;
 }
-
-size_t toStringMatrix(const Matrix* m, char* buffer, size_t n) {
-    size_t w = 0;
-    stringAdd(&w, &buffer, &n, toString(buffer, n, "["));
-    stringAdd(&w, &buffer, &n, toStringV4(m->data + 0, buffer, n));
-    stringAdd(&w, &buffer, &n, toString(buffer, n, ", "));
-    stringAdd(&w, &buffer, &n, toStringV4(m->data + 1, buffer, n));
-    stringAdd(&w, &buffer, &n, toString(buffer, n, ", "));
-    stringAdd(&w, &buffer, &n, toStringV4(m->data + 2, buffer, n));
-    stringAdd(&w, &buffer, &n, toString(buffer, n, ", "));
-    stringAdd(&w, &buffer, &n, toStringV4(m->data + 3, buffer, n));
-    stringAdd(&w, &buffer, &n, toString(buffer, n, "]"));
-    return w;
-}

+ 8 - 16
src/Plane.c

@@ -1,23 +1,15 @@
 #include "core/Plane.h"
 
-#include "core/ToString.h"
-#include "core/Utility.h"
+#include "core/Generic.h"
 
-#define CV30 (&CORE_VECTOR3)
+#define CV30 (&VECTOR3)
 
-void coreInitPlane(CorePlane* p, const CoreVector3* a, const CoreVector3* b,
-                   const CoreVector3* c) {
-    coreCross(&p->abc, coreSubV3(CV30, b, a), coreSubV3(CV30, c, a));
-    coreNormalizeV3(&p->abc);
-    p->d = -coreDotV3(&p->abc, b);
+void initPlane(Plane* p, const Vector3* a, const Vector3* b, const Vector3* c) {
+    cross(&p->abc, sub(CV30, b, a), sub(CV30, c, a));
+    normalize(&p->abc);
+    p->d = -dot(&p->abc, b);
 }
 
-float coreSignedDistance(const CorePlane* p, const CoreVector3* v) {
-    return coreDotV3(&p->abc, v) + p->d;
-}
-
-size_t coreToStringPlane(const CorePlane* p, char* buffer, size_t n) {
-    return coreToString(buffer, n, "(%.3f x + %.3f y + %.3f z + %.3f)",
-                        (double)p->abc.data[0], (double)p->abc.data[1],
-                        (double)p->abc.data[2], (double)p->d);
+float signedDistance(const Plane* p, const Vector3* v) {
+    return dot(&p->abc, v) + p->d;
 }

+ 22 - 0
src/ToString.c

@@ -5,6 +5,8 @@
 
 #include "core/BitArray.h"
 #include "core/Box.h"
+#include "core/Matrix.h"
+#include "core/Plane.h"
 #include "core/Utility.h"
 
 size_t coreToString(char* buffer, size_t n, const char* format, ...) {
@@ -57,3 +59,23 @@ size_t coreToStringBox(const CoreBox* box, char* buffer, size_t n) {
                         (double)box->min.data[2], (double)box->min.data[3],
                         (double)box->min.data[4], (double)box->min.data[5]);
 }
+
+size_t toStringMatrix(const Matrix* m, char* buffer, size_t n) {
+    size_t w = 0;
+    stringAdd(&w, &buffer, &n, toString(buffer, n, "["));
+    stringAdd(&w, &buffer, &n, toStringV4(m->data + 0, buffer, n));
+    stringAdd(&w, &buffer, &n, toString(buffer, n, ", "));
+    stringAdd(&w, &buffer, &n, toStringV4(m->data + 1, buffer, n));
+    stringAdd(&w, &buffer, &n, toString(buffer, n, ", "));
+    stringAdd(&w, &buffer, &n, toStringV4(m->data + 2, buffer, n));
+    stringAdd(&w, &buffer, &n, toString(buffer, n, ", "));
+    stringAdd(&w, &buffer, &n, toStringV4(m->data + 3, buffer, n));
+    stringAdd(&w, &buffer, &n, toString(buffer, n, "]"));
+    return w;
+}
+
+size_t coreToStringPlane(const Plane* p, char* buffer, size_t n) {
+    return coreToString(buffer, n, "(%.3f x + %.3f y + %.3f z + %.3f)",
+                        (double)p->abc.data[0], (double)p->abc.data[1],
+                        (double)p->abc.data[2], (double)p->d);
+}

+ 45 - 49
test/modules/FrustumTests.c

@@ -1,69 +1,65 @@
 #include "../Tests.h"
 #include "core/Frustum.h"
-
-#define CV3(a, b, c) (&(CoreVector3){{a, b, c}})
+#include "core/ToString.h"
 
 static void testToString() {
-    CoreFrustum f;
-    coreInitFrustum(&f, 60.0f, 0.1f, 1000.0f);
-    char buffer[128];
-    coreToStringFrustum(&f, buffer, sizeof(buffer));
-    CORE_TEST_STRING("(tan = 0.577, nearClip = 0.100, farClip = 1000.000)",
-                     buffer);
+    Frustum f;
+    initFrustum(&f, 60.0f, 0.1f, 1000.0f);
+    TEST_FLOAT(0.577f, f.tan, 0.01f);
+    TEST_FLOAT(0.100f, f.nearClip, 0.01f);
+    TEST_FLOAT(1000.0f, f.farClip, 0.01f);
 }
 
 static void testPointIsInside() {
-    CoreIntVector2 size = {{200, 100}};
-    CoreFrustum f;
-    coreInitFrustum(&f, 60.0f, 0.1f, 1000.0f);
-    coreUpdateFrustumPlanes(&f, CV3(0, 0, 0), CV3(1, 0, 0), CV3(0, 1, 0),
-                            CV3(0, 0, 1), &size);
+    Frustum f;
+    initFrustum(&f, 60.0f, 0.1f, 1000.0f);
+    updateFrustumPlanes(&f, &V(0, 0, 0), &V(1, 0, 0), &V(0, 1, 0), &V(0, 0, 1),
+                        &IV(200, 100));
 
-    CORE_TEST_TRUE(coreIsInsideFrustum(&f, CV3(0, 0, 5)));
-    CORE_TEST_FALSE(coreIsInsideFrustum(&f, CV3(0, 0, 1004)));
-    CORE_TEST_FALSE(coreIsInsideFrustum(&f, CV3(0, 0, -5)));
-    CORE_TEST_FALSE(coreIsInsideFrustum(&f, CV3(0, 50, 5)));
-    CORE_TEST_FALSE(coreIsInsideFrustum(&f, CV3(0, -50, 5)));
-    CORE_TEST_FALSE(coreIsInsideFrustum(&f, CV3(50, 0, 5)));
-    CORE_TEST_FALSE(coreIsInsideFrustum(&f, CV3(-50, 0, 5)));
+    TEST_TRUE(isInsideFrustum(&f, &V(0, 0, 5)));
+    TEST_FALSE(isInsideFrustum(&f, &V(0, 0, 1004)));
+    TEST_FALSE(isInsideFrustum(&f, &V(0, 0, -5)));
+    TEST_FALSE(isInsideFrustum(&f, &V(0, 50, 5)));
+    TEST_FALSE(isInsideFrustum(&f, &V(0, -50, 5)));
+    TEST_FALSE(isInsideFrustum(&f, &V(50, 0, 5)));
+    TEST_FALSE(isInsideFrustum(&f, &V(-50, 0, 5)));
 }
 
 static void testSphereIsInside() {
-    CoreIntVector2 size = {{200, 100}};
-    CoreFrustum f;
-    coreInitFrustum(&f, 60.0f, 0.1f, 1000.0f);
-    coreUpdateFrustumPlanes(&f, CV3(0, 0, 0), CV3(1, 0, 0), CV3(0, 1, 0),
-                            CV3(0, 0, 1), &size);
+    IntVector2 size = {{200, 100}};
+    Frustum f;
+    initFrustum(&f, 60.0f, 0.1f, 1000.0f);
+    updateFrustumPlanes(&f, &V(0, 0, 0), &V(1, 0, 0), &V(0, 1, 0), &V(0, 0, 1),
+                        &size);
 
-    CORE_TEST_TRUE(coreIsInsideFrustumRadius(&f, CV3(0, 0, 5), 3));
-    CORE_TEST_FALSE(coreIsInsideFrustumRadius(&f, CV3(0, 0, 1004), 3));
-    CORE_TEST_FALSE(coreIsInsideFrustumRadius(&f, CV3(0, 0, -5), 3));
-    CORE_TEST_FALSE(coreIsInsideFrustumRadius(&f, CV3(0, 50, 5), 3));
-    CORE_TEST_FALSE(coreIsInsideFrustumRadius(&f, CV3(0, -50, 5), 3));
-    CORE_TEST_FALSE(coreIsInsideFrustumRadius(&f, CV3(50, 0, 5), 3));
-    CORE_TEST_FALSE(coreIsInsideFrustumRadius(&f, CV3(-50, 0, 5), 3));
+    TEST_TRUE(isInsideFrustumRadius(&f, &V(0, 0, 5), 3));
+    TEST_FALSE(isInsideFrustumRadius(&f, &V(0, 0, 1004), 3));
+    TEST_FALSE(isInsideFrustumRadius(&f, &V(0, 0, -5), 3));
+    TEST_FALSE(isInsideFrustumRadius(&f, &V(0, 50, 5), 3));
+    TEST_FALSE(isInsideFrustumRadius(&f, &V(0, -50, 5), 3));
+    TEST_FALSE(isInsideFrustumRadius(&f, &V(50, 0, 5), 3));
+    TEST_FALSE(isInsideFrustumRadius(&f, &V(-50, 0, 5), 3));
 
-    CORE_TEST_TRUE(coreIsInsideFrustumRadius(&f, CV3(0, 0, 5), 3));
-    CORE_TEST_TRUE(coreIsInsideFrustumRadius(&f, CV3(0, 0, 1004), 50));
-    CORE_TEST_TRUE(coreIsInsideFrustumRadius(&f, CV3(0, 0, -5), 50));
-    CORE_TEST_TRUE(coreIsInsideFrustumRadius(&f, CV3(0, 50, 5), 50));
-    CORE_TEST_TRUE(coreIsInsideFrustumRadius(&f, CV3(0, -50, 5), 50));
-    CORE_TEST_TRUE(coreIsInsideFrustumRadius(&f, CV3(50, 0, 5), 50));
-    CORE_TEST_TRUE(coreIsInsideFrustumRadius(&f, CV3(-50, 0, 5), 50));
+    TEST_TRUE(isInsideFrustumRadius(&f, &V(0, 0, 5), 3));
+    TEST_TRUE(isInsideFrustumRadius(&f, &V(0, 0, 1004), 50));
+    TEST_TRUE(isInsideFrustumRadius(&f, &V(0, 0, -5), 50));
+    TEST_TRUE(isInsideFrustumRadius(&f, &V(0, 50, 5), 50));
+    TEST_TRUE(isInsideFrustumRadius(&f, &V(0, -50, 5), 50));
+    TEST_TRUE(isInsideFrustumRadius(&f, &V(50, 0, 5), 50));
+    TEST_TRUE(isInsideFrustumRadius(&f, &V(-50, 0, 5), 50));
 }
 
 static void testUpdateProjection() {
-    CoreFrustum f;
-    coreInitFrustum(&f, 60.0f, 0.1f, 1000.0f);
-    const CoreMatrix* m =
-        coreUpdateProjection(&f, &(CoreIntVector2){{400, 300}});
+    Frustum f;
+    initFrustum(&f, 60.0f, 0.1f, 1000.0f);
+    const Matrix* m = updateProjection(&f, &IV(400, 300));
     char buffer[128];
-    coreToStringMatrix(m, buffer, sizeof(buffer));
-    CORE_TEST_STRING("[[1.299, 0.000, 0.000, 0.000], "
-                     "[0.000, 1.732, 0.000, 0.000], "
-                     "[0.000, 0.000, -1.000, -0.200], "
-                     "[0.000, 0.000, -1.000, 0.000]]",
-                     buffer);
+    toString(m, buffer, sizeof(buffer));
+    TEST_STRING("[[1.299, 0.000, 0.000, 0.000], "
+                "[0.000, 1.732, 0.000, 0.000], "
+                "[0.000, 0.000, -1.000, -0.200], "
+                "[0.000, 0.000, -1.000, 0.000]]",
+                buffer);
 }
 
 void testFrustum() {

+ 1 - 0
test/modules/MatrixTests.c

@@ -1,5 +1,6 @@
 #include "../Tests.h"
 #include "core/Generic.h"
+#include "core/ToString.h"
 
 typedef CoreVector3 V3;
 #define CV3(a, b, c) (&(V3){{a, b, c}})

+ 15 - 16
test/modules/PlaneTests.c

@@ -1,29 +1,28 @@
 #include "../Tests.h"
 #include "core/Plane.h"
+#include "core/ToString.h"
 
 static const float eps = 0.0001f;
 
-#define CV3(a, b, c) (&(CoreVector3){{a, b, c}})
-
 static void testToString() {
-    CorePlane p;
-    coreInitPlane(&p, CV3(3, 6, 8), CV3(7, 6, 2), CV3(4, 4, 4));
+    Plane p;
+    initPlane(&p, &V(3, 6, 8), &V(7, 6, 2), &V(4, 4, 4));
     char buffer[128];
-    coreToStringPlane(&p, buffer, sizeof(buffer));
-    CORE_TEST_STRING("(-0.684 x + 0.570 y + -0.456 z + 2.279)", buffer);
+    toString(&p, buffer, sizeof(buffer));
+    TEST_STRING("(-0.684 x + 0.570 y + -0.456 z + 2.279)", buffer);
 }
 
 static void testSignedDistance() {
-    CoreVector3 a = {{3, 6, 8}};
-    CoreVector3 b = {{7, 6, 2}};
-    CoreVector3 c = {{4, 4, 4}};
-    CorePlane p;
-    coreInitPlane(&p, &a, &b, &c);
-    CORE_TEST_FLOAT(0.0f, coreSignedDistance(&p, &a), eps);
-    CORE_TEST_FLOAT(0.0f, coreSignedDistance(&p, &b), eps);
-    CORE_TEST_FLOAT(0.0f, coreSignedDistance(&p, &c), eps);
-    CORE_TEST_FLOAT(-1.13960576f, coreSignedDistance(&p, CV3(5, 8, 10)), eps);
-    CORE_TEST_FLOAT(0.911684612f, coreSignedDistance(&p, CV3(3, 2, 1)), eps);
+    Vector3 a = V(3, 6, 8);
+    Vector3 b = V(7, 6, 2);
+    Vector3 c = V(4, 4, 4);
+    Plane p;
+    initPlane(&p, &a, &b, &c);
+    TEST_FLOAT(0.0f, signedDistance(&p, &a), eps);
+    TEST_FLOAT(0.0f, signedDistance(&p, &b), eps);
+    TEST_FLOAT(0.0f, signedDistance(&p, &c), eps);
+    TEST_FLOAT(-1.13960576f, signedDistance(&p, &V(5, 8, 10)), eps);
+    TEST_FLOAT(0.911684612f, signedDistance(&p, &V(3, 2, 1)), eps);
 }
 
 void testPlane() {

+ 2 - 1
test/modules/ViewTests.c

@@ -1,4 +1,5 @@
 #include "../Tests.h"
+#include "core/ToString.h"
 #include "core/View.h"
 
 #define CV3(a, b, c) (&(CoreVector3){{a, b, c}})
@@ -30,7 +31,7 @@ static void testUpdateMatrix() {
     CoreMatrix* m = coreUpdateMatrix(&v, CV3(1.0f, 2.0f, 3.0f));
 
     char buffer[128];
-    coreToStringMatrix(m, buffer, sizeof(buffer));
+    toString(m, buffer, sizeof(buffer));
 
     CORE_TEST_STRING("[[0.000, 0.000, 0.000, -0.000], "
                      "[0.000, 0.000, 0.000, -0.000], "