PlaneTests.c 887 B

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