2
0

PlaneTests.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #include "UnitTestFramework.h"
  5. #include <Jolt/Geometry/Plane.h>
  6. TEST_SUITE("PlaneTests")
  7. {
  8. TEST_CASE("TestPlaneSignedDistance")
  9. {
  10. Plane p = Plane::sFromPointAndNormal(Vec3(0, 2, 0), Vec3(0, 1, 0));
  11. CHECK(p.SignedDistance(Vec3(5, 7, 0)) == 5.0f);
  12. CHECK(p.SignedDistance(Vec3(5, -3, 0)) == -5.0f);
  13. }
  14. TEST_CASE("TestPlaneGetTransformed")
  15. {
  16. Mat44 transform = Mat44::sRotationTranslation(Quat::sRotation(Vec3(1.0f, 2.0f, 3.0f).Normalized(), 0.1f * JPH_PI), Vec3(5.0f, -7.0f, 9.0f));
  17. Vec3 point = Vec3(11.0f, 13.0f, 15.0f);
  18. Vec3 normal = Vec3(-3.0f, 5.0f, -7.0f).Normalized();
  19. Plane p1 = Plane::sFromPointAndNormal(point, normal).GetTransformed(transform);
  20. Plane p2 = Plane::sFromPointAndNormal(transform * point, transform.Multiply3x3(normal));
  21. CHECK_APPROX_EQUAL(p1.GetNormal(), p2.GetNormal());
  22. CHECK_APPROX_EQUAL(p1.GetConstant(), p2.GetConstant());
  23. }
  24. TEST_CASE("TestPlaneIntersectPlanes")
  25. {
  26. Plane p1 = Plane::sFromPointAndNormal(Vec3(0, 2, 0), Vec3(0, 1, 0));
  27. Plane p2 = Plane::sFromPointAndNormal(Vec3(3, 0, 0), Vec3(1, 0, 0));
  28. Plane p3 = Plane::sFromPointAndNormal(Vec3(0, 0, 4), Vec3(0, 0, 1));
  29. {
  30. Vec3 point;
  31. bool found = Plane::sIntersectPlanes(p1, p2, p3, point);
  32. CHECK(found);
  33. CHECK(point == Vec3(3, 2, 4));
  34. }
  35. {
  36. Plane p4 = Plane::sFromPointAndNormal(Vec3(0, 3, 0), Vec3(0, 1, 0));
  37. Vec3 point;
  38. bool found = Plane::sIntersectPlanes(p1, p2, p4, point);
  39. CHECK_FALSE(found);
  40. }
  41. }
  42. }