| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- module Tests;
- import Core.Box;
- import Core.Test;
- import Core.Vector;
- using Core::Box;
- using V3 = Core::Vector3;
- static void testInit() {
- Box box(V3(1.0f, 2.0f, 3.0f));
- Core::testString("Box([0.00, 0.00, 0.00], [1.00, 2.00, 3.00])", box);
- Core::testString("[0.00, 0.00, 0.00]", box.getMin());
- Core::testString("[1.00, 2.00, 3.00]", box.getMax());
- box = Box(V3(-1.0f, -2.0f, -3.0f));
- Core::testString("Box([-1.00, -2.00, -3.00], [0.00, 0.00, 0.00])", box);
- Core::testString("[-1.00, -2.00, -3.00]", box.getMin());
- Core::testString("[0.00, 0.00, 0.00]", box.getMax());
- }
- static void testOffset() {
- Box box(V3(1.0f, 2.0f, 3.0f));
- box = box.offset(V3(7.0f, -4.0f, 6.0f));
- Core::testString("Box([7.00, -4.00, 6.00], [8.00, -2.00, 9.00])", box);
- }
- static void testCollidesWith() {
- Box boxA(V3(1.0f, 2.0f, 3.0f));
- Box boxB(V3(-1.0f, -2.0f, -3.0f));
- Box boxC(V3(2.0f, 2.0f, 2.0f));
- boxC = boxC.offset(V3(-1.0f, -1.0f, -1.0f));
- Core::testTrue(boxC.collidesWith(boxA));
- Core::testTrue(boxC.collidesWith(boxB));
- Core::testTrue(boxA.collidesWith(boxC));
- Core::testTrue(boxB.collidesWith(boxC));
- Core::testFalse(boxA.collidesWith(boxB));
- Core::testFalse(boxB.collidesWith(boxA));
- }
- static void testExpand() {
- Box box(V3(1.0f, 2.0f, 3.0f));
- box = box.expand(V3(7.0f, -4.0f, 6.0f));
- Core::testString("Box([0.00, -4.00, 0.00], [8.00, 2.00, 9.00])", box);
- box = Box(V3(1.0f, 2.0f, 3.0f));
- box = box.expand(V3(-7.0f, 4.0f, -6.0f));
- Core::testString("Box([-7.00, 0.00, -6.00], [1.00, 6.00, 3.00])", box);
- }
- static void testGrow() {
- Box box(V3(1.0f, 2.0f, 3.0f));
- Core::testString(
- "Box([-2.00, -1.00, -3.00], [3.00, 3.00, 6.00])",
- box.grow(V3(4.0f, 2.0f, 6.0f)));
- Core::testString(
- "Box([0.50, 1.00, 1.50], [0.50, 1.00, 1.50])",
- box.grow(V3(-4.0f, -2.0f, -6.0f)));
- Core::testString(
- "Box([0.05, 1.00, 0.50], [0.95, 1.00, 2.50])",
- box.grow(V3(-0.1f, -4.0f, -1.0f)));
- }
- void testBox() {
- testInit();
- testOffset();
- testCollidesWith();
- testExpand();
- testGrow();
- }
|