PlaneTests.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "tests/PlaneTests.h"
  2. #include "tests/Test.h"
  3. #include "math/Plane.h"
  4. #include "utils/StringBuffer.h"
  5. typedef StringBuffer<50> String;
  6. const float eps = 0.0001f;
  7. static void testToString1(Test& test) {
  8. Plane p;
  9. test.checkEqual(String("(0.00 x + 0.00 y + 0.00 z + 0.00)"), String(p), "to string 1");
  10. }
  11. static void testToString2(Test& test) {
  12. Plane p(Vector3(3.0f, 6.0f, 8.0f), Vector3(7.0f, 6.0f, 2.0f), Vector3(4.0f, 4.0f, 4.0f));
  13. test.checkEqual(String("(-0.68 x + 0.57 y + -0.46 z + 2.28)"), String(p), "to string 2");
  14. }
  15. static void testSignedDistance(Test& test) {
  16. Vector3 a(3.0f, 6.0f, 8.0f);
  17. Vector3 b(7.0f, 6.0f, 2.0f);
  18. Vector3 c(4.0f, 4.0f, 4.0f);
  19. Plane p(a, b, c);
  20. test.checkFloat(0.0f, p.getSignedDistance(a), eps, "no distance to init points 1");
  21. test.checkFloat(0.0f, p.getSignedDistance(b), eps, "no distance to init points 2");
  22. test.checkFloat(0.0f, p.getSignedDistance(c), eps, "no distance to init points 3");
  23. test.checkFloat(-1.13960576f, p.getSignedDistance(Vector3(5.0f, 8.0f, 10.0f)), eps, "positive distance");
  24. test.checkFloat(0.911684612f, p.getSignedDistance(Vector3(3.0f, 2.0f, 1.0f)), eps, "negative distance");
  25. }
  26. void PlaneTests::test() {
  27. Test test("Plane");
  28. testToString1(test);
  29. testToString2(test);
  30. testSignedDistance(test);
  31. test.finalize();
  32. }