PlaneTests.cpp 862 B

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