PlaneTests.c 989 B

1234567891011121314151617181920212223242526272829303132
  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 testToString() {
  6. CorePlane p;
  7. coreInitPlane(&p, CV3(3, 6, 8), CV3(7, 6, 2), CV3(4, 4, 4));
  8. char buffer[128];
  9. coreToStringPlane(&p, buffer, sizeof(buffer));
  10. CORE_TEST_STRING("(-0.684 x + 0.570 y + -0.456 z + 2.279)", buffer);
  11. }
  12. static void testSignedDistance() {
  13. CoreVector3 a = {{3, 6, 8}};
  14. CoreVector3 b = {{7, 6, 2}};
  15. CoreVector3 c = {{4, 4, 4}};
  16. CorePlane p;
  17. coreInitPlane(&p, &a, &b, &c);
  18. CORE_TEST_FLOAT(0.0f, coreSignedDistance(&p, &a), eps);
  19. CORE_TEST_FLOAT(0.0f, coreSignedDistance(&p, &b), eps);
  20. CORE_TEST_FLOAT(0.0f, coreSignedDistance(&p, &c), eps);
  21. CORE_TEST_FLOAT(-1.13960576f, coreSignedDistance(&p, CV3(5, 8, 10)), eps);
  22. CORE_TEST_FLOAT(0.911684612f, coreSignedDistance(&p, CV3(3, 2, 1)), eps);
  23. }
  24. void coreTestPlane() {
  25. testToString();
  26. testSignedDistance();
  27. }