PlaneTests.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "../Tests.h"
  2. #include "core/Plane.h"
  3. static const float eps = 0.0001f;
  4. #define CV3(a, b, c) (&(CoreVector3){{a, b, c}})
  5. static void testToString1() {
  6. CorePlane p = CORE_PLANE;
  7. char buffer[128];
  8. coreToStringPlane(&p, buffer, sizeof(buffer));
  9. CORE_TEST_STRING("(0.000 x + 0.000 y + 0.000 z + 0.000)", buffer);
  10. }
  11. static void testToString2() {
  12. CorePlane p = CORE_PLANE;
  13. coreInitPlane(&p, CV3(3, 6, 8), CV3(7, 6, 2), CV3(4, 4, 4));
  14. char buffer[128];
  15. coreToStringPlane(&p, buffer, sizeof(buffer));
  16. CORE_TEST_STRING("(-0.684 x + 0.570 y + -0.456 z + 2.279)", buffer);
  17. }
  18. static void testSignedDistance() {
  19. CoreVector3 a = {{3, 6, 8}};
  20. CoreVector3 b = {{7, 6, 2}};
  21. CoreVector3 c = {{4, 4, 4}};
  22. CorePlane p = CORE_PLANE;
  23. coreInitPlane(&p, &a, &b, &c);
  24. CORE_TEST_FLOAT(0.0f, coreSignedDistance(&p, &a), eps);
  25. CORE_TEST_FLOAT(0.0f, coreSignedDistance(&p, &b), eps);
  26. CORE_TEST_FLOAT(0.0f, coreSignedDistance(&p, &c), eps);
  27. CORE_TEST_FLOAT(-1.13960576f, coreSignedDistance(&p, CV3(5, 8, 10)), eps);
  28. CORE_TEST_FLOAT(0.911684612f, coreSignedDistance(&p, CV3(3, 2, 1)), eps);
  29. }
  30. void coreTestPlane() {
  31. testToString1();
  32. testToString2();
  33. testSignedDistance();
  34. }