PlaneTests.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include "tests/PlaneTests.hpp"
  2. #include "math/Plane.hpp"
  3. #include "test/Test.hpp"
  4. const float eps = 0.0001f;
  5. using V3 = Core::Vector3;
  6. static void testToString1() {
  7. Core::Plane p;
  8. CORE_TEST_STRING("(0.00 x + 0.00 y + 0.00 z + 0.00)", p);
  9. }
  10. static void testToString2() {
  11. Core::Plane p(V3(3.0f, 6.0f, 8.0f), V3(7.0f, 6.0f, 2.0f),
  12. V3(4.0f, 4.0f, 4.0f));
  13. CORE_TEST_STRING("(-0.68 x + 0.57 y + -0.46 z + 2.28)", p);
  14. }
  15. static void testSignedDistance() {
  16. V3 a(3.0f, 6.0f, 8.0f);
  17. V3 b(7.0f, 6.0f, 2.0f);
  18. V3 c(4.0f, 4.0f, 4.0f);
  19. Core::Plane p(a, b, c);
  20. CORE_TEST_FLOAT(0.0f, p.getSignedDistance(a), eps);
  21. CORE_TEST_FLOAT(0.0f, p.getSignedDistance(b), eps);
  22. CORE_TEST_FLOAT(0.0f, p.getSignedDistance(c), eps);
  23. CORE_TEST_FLOAT(-1.13960576f, p.getSignedDistance(V3(5.0f, 8.0f, 10.0f)),
  24. eps);
  25. CORE_TEST_FLOAT(0.911684612f, p.getSignedDistance(V3(3.0f, 2.0f, 1.0f)),
  26. eps);
  27. }
  28. void Core::PlaneTests::test() {
  29. testToString1();
  30. testToString2();
  31. testSignedDistance();
  32. }