BoxTests.cpp 2.2 KB

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