PlaneTests.cpp 830 B

1234567891011121314151617181920212223242526272829
  1. #include "../Tests.hpp"
  2. #include "core/Plane.hpp"
  3. #include "core/Test.hpp"
  4. static const float eps = 0.0001f;
  5. using V3 = Core::Vector3;
  6. static void testToString() {
  7. Core::Plane p(V3(3, 6, 8), V3(7, 6, 2), V3(4, 4, 4));
  8. TEST_STRING("(-0.684 x + 0.570 y + -0.456 z + 2.279)", p);
  9. TEST_STRING("(0.000 x + 0.000 y + 0.000 z + 0.000)", Core::Plane());
  10. }
  11. static void testSignedDistance() {
  12. V3 a(3, 6, 8);
  13. V3 b(7, 6, 2);
  14. V3 c(4, 4, 4);
  15. Core::Plane p(a, b, c);
  16. TEST_FLOAT(0.0f, p.signedDistance(a), eps);
  17. TEST_FLOAT(0.0f, p.signedDistance(b), eps);
  18. TEST_FLOAT(0.0f, p.signedDistance(c), eps);
  19. TEST_FLOAT(-1.13960576f, p.signedDistance(V3(5, 8, 10)), eps);
  20. TEST_FLOAT(0.911684612f, p.signedDistance(V3(3, 2, 1)), eps);
  21. }
  22. void testPlane() {
  23. testToString();
  24. testSignedDistance();
  25. }