BoxTests.cpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "tests/BoxTests.h"
  2. #include "math/Box.h"
  3. #include "test/Test.h"
  4. static void testInit() {
  5. Core::Box box(Core::Vector3(1.0f, 2.0f, 3.0f));
  6. CORE_TEST_STRING("Box([0.00, 0.00, 0.00], [1.00, 2.00, 3.00])", box);
  7. CORE_TEST_STRING("[0.00, 0.00, 0.00]", box.getMin());
  8. CORE_TEST_STRING("[1.00, 2.00, 3.00]", box.getMax());
  9. box = Core::Box(Core::Vector3(-1.0f, -2.0f, -3.0f));
  10. CORE_TEST_STRING("Box([-1.00, -2.00, -3.00], [0.00, 0.00, 0.00])", box);
  11. CORE_TEST_STRING("[-1.00, -2.00, -3.00]", box.getMin());
  12. CORE_TEST_STRING("[0.00, 0.00, 0.00]", box.getMax());
  13. }
  14. static void testOffset() {
  15. Core::Box box(Core::Vector3(1.0f, 2.0f, 3.0f));
  16. CORE_TEST_STRING("Box([7.00, -4.00, 6.00], [8.00, -2.00, 9.00])",
  17. box.offset(Core::Vector3(7.0f, -4.0f, 6.0f)));
  18. }
  19. static void testCollidesWith() {
  20. Core::Box boxA(Core::Vector3(1.0f, 2.0f, 3.0f));
  21. Core::Box boxB(Core::Vector3(-1.0f, -2.0f, -3.0f));
  22. Core::Box boxC(Core::Vector3(2.0f, 2.0f, 2.0f));
  23. boxC = boxC.offset(Core::Vector3(-1.0f, -1.0f, -1.0f));
  24. CORE_TEST_TRUE(boxC.collidesWith(boxA));
  25. CORE_TEST_TRUE(boxC.collidesWith(boxB));
  26. CORE_TEST_TRUE(boxA.collidesWith(boxC));
  27. CORE_TEST_TRUE(boxB.collidesWith(boxC));
  28. CORE_TEST_FALSE(boxA.collidesWith(boxB));
  29. CORE_TEST_FALSE(boxB.collidesWith(boxA));
  30. }
  31. static void testExpand() {
  32. Core::Box box(Core::Vector3(1.0f, 2.0f, 3.0f));
  33. CORE_TEST_STRING("Box([0.00, -4.00, 0.00], [8.00, 2.00, 9.00])",
  34. box.expand(Core::Vector3(7.0f, -4.0f, 6.0f)));
  35. CORE_TEST_STRING("Box([-7.00, 0.00, -6.00], [1.00, 6.00, 3.00])",
  36. box.expand(Core::Vector3(-7.0f, 4.0f, -6.0f)));
  37. }
  38. static void testGrow() {
  39. Core::Box box(Core::Vector3(1.0f, 2.0f, 3.0f));
  40. CORE_TEST_STRING("Box([-2.00, -1.00, -3.00], [3.00, 3.00, 6.00])",
  41. box.grow(Core::Vector3(4.0f, 2.0f, 6.0f)));
  42. CORE_TEST_STRING("Box([0.50, 1.00, 1.50], [0.50, 1.00, 1.50])",
  43. box.grow(Core::Vector3(-4.0f, -2.0f, -6.0f)));
  44. CORE_TEST_STRING("Box([0.05, 1.00, 0.50], [0.95, 1.00, 2.50])",
  45. box.grow(Core::Vector3(-0.1f, -4.0f, -1.0f)));
  46. }
  47. void Core::BoxTests::test() {
  48. testInit();
  49. testOffset();
  50. testCollidesWith();
  51. testExpand();
  52. testGrow();
  53. }