|
@@ -0,0 +1,100 @@
|
|
|
|
+#include "../Tests.h"
|
|
|
|
+#include "core/Box.h"
|
|
|
|
+
|
|
|
|
+#define CV3(a, b, c) (&(CoreVector3){{a, b, c}})
|
|
|
|
+
|
|
|
|
+static void testInit() {
|
|
|
|
+ CoreBox box = {0};
|
|
|
|
+ coreSetBox(&box, CV3(1.0f, 2.0f, 3.0f));
|
|
|
|
+ char buffer[128];
|
|
|
|
+ coreToStringBox(&box, buffer, sizeof(buffer));
|
|
|
|
+ CORE_TEST_STRING("Box([0.000, 0.000, 0.000], [1.000, 2.000, 3.000])",
|
|
|
|
+ buffer);
|
|
|
|
+ coreToStringV3(&box.min, buffer, sizeof(buffer));
|
|
|
|
+ CORE_TEST_STRING("[0.000, 0.000, 0.000]", buffer);
|
|
|
|
+ coreToStringV3(&box.max, buffer, sizeof(buffer));
|
|
|
|
+ CORE_TEST_STRING("[1.000, 2.000, 3.000]", buffer);
|
|
|
|
+
|
|
|
|
+ coreSetBox(&box, CV3(-1.0f, -2.0f, -3.0f));
|
|
|
|
+ coreToStringBox(&box, buffer, sizeof(buffer));
|
|
|
|
+ CORE_TEST_STRING("Box([-1.000, -2.000, -3.000], [0.000, 0.000, 0.000])",
|
|
|
|
+ buffer);
|
|
|
|
+ coreToStringV3(&box.min, buffer, sizeof(buffer));
|
|
|
|
+ CORE_TEST_STRING("[-1.000, -2.000, -3.000]", buffer);
|
|
|
|
+ coreToStringV3(&box.max, buffer, sizeof(buffer));
|
|
|
|
+ CORE_TEST_STRING("[0.000, 0.000, 0.000]", buffer);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void testOffset() {
|
|
|
|
+ CoreBox box = {0};
|
|
|
|
+ coreSetBox(&box, CV3(1.0f, 2.0f, 3.0f));
|
|
|
|
+ coreOffsetBox(&box, CV3(7.0f, -4.0f, 6.0f));
|
|
|
|
+ char buffer[128];
|
|
|
|
+ coreToStringBox(&box, buffer, sizeof(buffer));
|
|
|
|
+ CORE_TEST_STRING("Box([7.000, -4.000, 6.000], [8.000, -2.000, 9.000])",
|
|
|
|
+ buffer);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void testCollidesWith() {
|
|
|
|
+ CoreBox boxA = {0};
|
|
|
|
+ coreSetBox(&boxA, CV3(1.0f, 2.0f, 3.0f));
|
|
|
|
+ CoreBox boxB = {0};
|
|
|
|
+ coreSetBox(&boxB, CV3(-1.0f, -2.0f, -3.0f));
|
|
|
|
+ CoreBox boxC = {0};
|
|
|
|
+ coreSetBox(&boxC, CV3(2.0f, 2.0f, 2.0f));
|
|
|
|
+ coreOffsetBox(&boxC, CV3(-1.0f, -1.0f, -1.0f));
|
|
|
|
+
|
|
|
|
+ CORE_TEST_TRUE(coreCollidesWithBox(&boxC, &boxA));
|
|
|
|
+ CORE_TEST_TRUE(coreCollidesWithBox(&boxC, &boxB));
|
|
|
|
+ CORE_TEST_TRUE(coreCollidesWithBox(&boxA, &boxC));
|
|
|
|
+ CORE_TEST_TRUE(coreCollidesWithBox(&boxB, &boxC));
|
|
|
|
+ CORE_TEST_FALSE(coreCollidesWithBox(&boxA, &boxB));
|
|
|
|
+ CORE_TEST_FALSE(coreCollidesWithBox(&boxB, &boxA));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void testExpand() {
|
|
|
|
+ CoreBox box = {0};
|
|
|
|
+ coreSetBox(&box, CV3(1.0f, 2.0f, 3.0f));
|
|
|
|
+ coreExpandBox(&box, CV3(7.0f, -4.0f, 6.0f));
|
|
|
|
+
|
|
|
|
+ char buffer[128];
|
|
|
|
+ coreToStringBox(&box, buffer, sizeof(buffer));
|
|
|
|
+ CORE_TEST_STRING("Box([0.000, -4.000, 0.000], [8.000, 2.000, 9.000])",
|
|
|
|
+ buffer);
|
|
|
|
+
|
|
|
|
+ coreSetBox(&box, CV3(1.0f, 2.0f, 3.0f));
|
|
|
|
+ coreExpandBox(&box, CV3(-7.0f, 4.0f, -6.0f));
|
|
|
|
+ coreToStringBox(&box, buffer, sizeof(buffer));
|
|
|
|
+ CORE_TEST_STRING("Box([-7.000, 0.000, -6.000], [1.000, 6.000, 3.000])",
|
|
|
|
+ buffer);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void testGrow() {
|
|
|
|
+ CoreBox box = {0};
|
|
|
|
+ coreSetBox(&box, CV3(1.0f, 2.0f, 3.0f));
|
|
|
|
+ coreGrowBox(&box, CV3(4.0f, 2.0f, 6.0f));
|
|
|
|
+ char buffer[128];
|
|
|
|
+ coreToStringBox(&box, buffer, sizeof(buffer));
|
|
|
|
+ CORE_TEST_STRING("Box([-2.000, -1.000, -3.000], [3.000, 3.000, 6.000])",
|
|
|
|
+ buffer);
|
|
|
|
+
|
|
|
|
+ coreSetBox(&box, CV3(1.0f, 2.0f, 3.0f));
|
|
|
|
+ coreGrowBox(&box, CV3(-4.0f, -2.0f, -6.0f));
|
|
|
|
+ coreToStringBox(&box, buffer, sizeof(buffer));
|
|
|
|
+ CORE_TEST_STRING("Box([0.500, 1.000, 1.500], [0.500, 1.000, 1.500])",
|
|
|
|
+ buffer);
|
|
|
|
+
|
|
|
|
+ coreSetBox(&box, CV3(1.0f, 2.0f, 3.0f));
|
|
|
|
+ coreGrowBox(&box, CV3(-0.1f, -4.0f, -1.0f));
|
|
|
|
+ coreToStringBox(&box, buffer, sizeof(buffer));
|
|
|
|
+ CORE_TEST_STRING("Box([0.050, 1.000, 0.500], [0.950, 1.000, 2.500])",
|
|
|
|
+ buffer);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void coreTestBox() {
|
|
|
|
+ testInit();
|
|
|
|
+ testOffset();
|
|
|
|
+ testCollidesWith();
|
|
|
|
+ testExpand();
|
|
|
|
+ testGrow();
|
|
|
|
+}
|