BoxTests.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. module Tests;
  2. import Core.Box;
  3. import Core.Test;
  4. import Core.Vector;
  5. using Core::Box;
  6. using V3 = Core::Vector3;
  7. static void testInit() {
  8. Box box(V3(1.0f, 2.0f, 3.0f));
  9. Core::testString("Box([0.00, 0.00, 0.00], [1.00, 2.00, 3.00])", box);
  10. Core::testString("[0.00, 0.00, 0.00]", box.getMin());
  11. Core::testString("[1.00, 2.00, 3.00]", box.getMax());
  12. box = Box(V3(-1.0f, -2.0f, -3.0f));
  13. Core::testString("Box([-1.00, -2.00, -3.00], [0.00, 0.00, 0.00])", box);
  14. Core::testString("[-1.00, -2.00, -3.00]", box.getMin());
  15. Core::testString("[0.00, 0.00, 0.00]", box.getMax());
  16. }
  17. static void testOffset() {
  18. Box box(V3(1.0f, 2.0f, 3.0f));
  19. box = box.offset(V3(7.0f, -4.0f, 6.0f));
  20. Core::testString("Box([7.00, -4.00, 6.00], [8.00, -2.00, 9.00])", box);
  21. }
  22. static void testCollidesWith() {
  23. Box boxA(V3(1.0f, 2.0f, 3.0f));
  24. Box boxB(V3(-1.0f, -2.0f, -3.0f));
  25. Box boxC(V3(2.0f, 2.0f, 2.0f));
  26. boxC = boxC.offset(V3(-1.0f, -1.0f, -1.0f));
  27. Core::testTrue(boxC.collidesWith(boxA));
  28. Core::testTrue(boxC.collidesWith(boxB));
  29. Core::testTrue(boxA.collidesWith(boxC));
  30. Core::testTrue(boxB.collidesWith(boxC));
  31. Core::testFalse(boxA.collidesWith(boxB));
  32. Core::testFalse(boxB.collidesWith(boxA));
  33. }
  34. static void testExpand() {
  35. Box box(V3(1.0f, 2.0f, 3.0f));
  36. box = box.expand(V3(7.0f, -4.0f, 6.0f));
  37. Core::testString("Box([0.00, -4.00, 0.00], [8.00, 2.00, 9.00])", box);
  38. box = Box(V3(1.0f, 2.0f, 3.0f));
  39. box = box.expand(V3(-7.0f, 4.0f, -6.0f));
  40. Core::testString("Box([-7.00, 0.00, -6.00], [1.00, 6.00, 3.00])", box);
  41. }
  42. static void testGrow() {
  43. Box box(V3(1.0f, 2.0f, 3.0f));
  44. Core::testString(
  45. "Box([-2.00, -1.00, -3.00], [3.00, 3.00, 6.00])",
  46. box.grow(V3(4.0f, 2.0f, 6.0f)));
  47. Core::testString(
  48. "Box([0.50, 1.00, 1.50], [0.50, 1.00, 1.50])",
  49. box.grow(V3(-4.0f, -2.0f, -6.0f)));
  50. Core::testString(
  51. "Box([0.05, 1.00, 0.50], [0.95, 1.00, 2.50])",
  52. box.grow(V3(-0.1f, -4.0f, -1.0f)));
  53. }
  54. void testBox() {
  55. testInit();
  56. testOffset();
  57. testCollidesWith();
  58. testExpand();
  59. testGrow();
  60. }