PlaneTests.c 872 B

12345678910111213141516171819202122232425262728293031
  1. #include "../Tests.h"
  2. #include "core/Plane.h"
  3. #include "core/ToString.h"
  4. static const float eps = 0.0001f;
  5. static void testToString() {
  6. Plane p;
  7. initPlane(&p, &V(3, 6, 8), &V(7, 6, 2), &V(4, 4, 4));
  8. char buffer[128];
  9. toStringPlane(&p, buffer, sizeof(buffer));
  10. TEST_STRING("(-0.684 x + 0.570 y + -0.456 z + 2.279)", buffer);
  11. }
  12. static void testSignedDistance() {
  13. Vector3 a = V(3, 6, 8);
  14. Vector3 b = V(7, 6, 2);
  15. Vector3 c = V(4, 4, 4);
  16. Plane p;
  17. initPlane(&p, &a, &b, &c);
  18. TEST_FLOAT(0.0f, signedDistance(&p, &a), eps);
  19. TEST_FLOAT(0.0f, signedDistance(&p, &b), eps);
  20. TEST_FLOAT(0.0f, signedDistance(&p, &c), eps);
  21. TEST_FLOAT(-1.13960576f, signedDistance(&p, &V(5, 8, 10)), eps);
  22. TEST_FLOAT(0.911684612f, signedDistance(&p, &V(3, 2, 1)), eps);
  23. }
  24. void testPlane() {
  25. testToString();
  26. testSignedDistance();
  27. }