PlaneTests.cpp 1.0 KB

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