PlaneTests.cpp 961 B

123456789101112131415161718192021222324252627282930313233343536
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #include "UnitTestFramework.h"
  4. #include <Jolt/Geometry/Plane.h>
  5. TEST_SUITE("PlaneTests")
  6. {
  7. TEST_CASE("TestPlaneSignedDistance")
  8. {
  9. Plane p = Plane::sFromPointAndNormal(Vec3(0, 2, 0), Vec3(0, 1, 0));
  10. CHECK(p.SignedDistance(Vec3(5, 7, 0)) == 5.0f);
  11. CHECK(p.SignedDistance(Vec3(5, -3, 0)) == -5.0f);
  12. }
  13. TEST_CASE("TestPlaneIntersectPlanes")
  14. {
  15. Plane p1 = Plane::sFromPointAndNormal(Vec3(0, 2, 0), Vec3(0, 1, 0));
  16. Plane p2 = Plane::sFromPointAndNormal(Vec3(3, 0, 0), Vec3(1, 0, 0));
  17. Plane p3 = Plane::sFromPointAndNormal(Vec3(0, 0, 4), Vec3(0, 0, 1));
  18. {
  19. Vec3 point;
  20. bool found = Plane::sIntersectPlanes(p1, p2, p3, point);
  21. CHECK(found);
  22. CHECK(point == Vec3(3, 2, 4));
  23. }
  24. {
  25. Plane p4 = Plane::sFromPointAndNormal(Vec3(0, 3, 0), Vec3(0, 1, 0));
  26. Vec3 point;
  27. bool found = Plane::sIntersectPlanes(p1, p2, p4, point);
  28. CHECK_FALSE(found);
  29. }
  30. }
  31. }