123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #include "../Tests.h"
- #include "core/Box.h"
- static void testInit() {
- Box box = BOX;
- setBox(&box, &V(1.0f, 2.0f, 3.0f));
- char buffer[128];
- toStringBox(&box, buffer, sizeof(buffer));
- TEST_STRING("Box([0.000, 0.000, 0.000], [1.000, 2.000, 3.000])", buffer);
- setBox(&box, &V(-1.0f, -2.0f, -3.0f));
- toStringBox(&box, buffer, sizeof(buffer));
- TEST_STRING("Box([-1.000, -2.000, -3.000], [0.000, 0.000, 0.000])", buffer);
- }
- static void testOffset() {
- Box box = BOX;
- setBox(&box, &V(1.0f, 2.0f, 3.0f));
- offsetBox(&box, &V(7.0f, -4.0f, 6.0f));
- char buffer[128];
- toStringBox(&box, buffer, sizeof(buffer));
- TEST_STRING("Box([7.000, -4.000, 6.000], [8.000, -2.000, 9.000])", buffer);
- }
- static void testCollidesWith() {
- Box boxA = BOX;
- setBox(&boxA, &V(1.0f, 2.0f, 3.0f));
- Box boxB = BOX;
- setBox(&boxB, &V(-1.0f, -2.0f, -3.0f));
- Box boxC = BOX;
- setBox(&boxC, &V(2.0f, 2.0f, 2.0f));
- offsetBox(&boxC, &V(-1.0f, -1.0f, -1.0f));
- TEST_TRUE(collidesWithBox(&boxC, &boxA));
- TEST_TRUE(collidesWithBox(&boxC, &boxB));
- TEST_TRUE(collidesWithBox(&boxA, &boxC));
- TEST_TRUE(collidesWithBox(&boxB, &boxC));
- TEST_FALSE(collidesWithBox(&boxA, &boxB));
- TEST_FALSE(collidesWithBox(&boxB, &boxA));
- }
- static void testExpand() {
- Box box = BOX;
- setBox(&box, &V(1.0f, 2.0f, 3.0f));
- expandBox(&box, &V(7.0f, -4.0f, 6.0f));
- char buffer[128];
- toStringBox(&box, buffer, sizeof(buffer));
- TEST_STRING("Box([0.000, -4.000, 0.000], [8.000, 2.000, 9.000])", buffer);
- setBox(&box, &V(1.0f, 2.0f, 3.0f));
- expandBox(&box, &V(-7.0f, 4.0f, -6.0f));
- toStringBox(&box, buffer, sizeof(buffer));
- TEST_STRING("Box([-7.000, 0.000, -6.000], [1.000, 6.000, 3.000])", buffer);
- }
- static void testGrow() {
- Box box = BOX;
- setBox(&box, &V(1.0f, 2.0f, 3.0f));
- growBox(&box, &V(4.0f, 2.0f, 6.0f));
- char buffer[128];
- toStringBox(&box, buffer, sizeof(buffer));
- TEST_STRING("Box([-2.000, -1.000, -3.000], [3.000, 3.000, 6.000])", buffer);
- setBox(&box, &V(1.0f, 2.0f, 3.0f));
- growBox(&box, &V(-4.0f, -2.0f, -6.0f));
- toStringBox(&box, buffer, sizeof(buffer));
- TEST_STRING("Box([0.500, 1.000, 1.500], [0.500, 1.000, 1.500])", buffer);
- setBox(&box, &V(1.0f, 2.0f, 3.0f));
- growBox(&box, &V(-0.1f, -4.0f, -1.0f));
- toStringBox(&box, buffer, sizeof(buffer));
- TEST_STRING("Box([0.050, 1.000, 0.500], [0.950, 1.000, 2.500])", buffer);
- }
- void testBox() {
- testInit();
- testOffset();
- testCollidesWith();
- testExpand();
- testGrow();
- }
|