12345678910111213141516171819202122232425262728293031323334353637 |
- #include "tests/PlaneTests.h"
- #include "tests/Test.h"
- #include "math/Plane.h"
- #include "utils/StringBuffer.h"
- typedef StringBuffer<50> String;
- const float eps = 0.0001f;
- static void testToString1(Test& test) {
- Plane p;
- test.checkEqual(String("(0.00 x + 0.00 y + 0.00 z + 0.00)"), String(p), "to string 1");
- }
- static void testToString2(Test& test) {
- Plane p(Vector3(3.0f, 6.0f, 8.0f), Vector3(7.0f, 6.0f, 2.0f), Vector3(4.0f, 4.0f, 4.0f));
- test.checkEqual(String("(-0.68 x + 0.57 y + -0.46 z + 2.28)"), String(p), "to string 2");
- }
- static void testSignedDistance(Test& test) {
- Vector3 a(3.0f, 6.0f, 8.0f);
- Vector3 b(7.0f, 6.0f, 2.0f);
- Vector3 c(4.0f, 4.0f, 4.0f);
- Plane p(a, b, c);
- test.checkFloat(0.0f, p.getSignedDistance(a), eps, "no distance to init points 1");
- test.checkFloat(0.0f, p.getSignedDistance(b), eps, "no distance to init points 2");
- test.checkFloat(0.0f, p.getSignedDistance(c), eps, "no distance to init points 3");
- test.checkFloat(-1.13960576f, p.getSignedDistance(Vector3(5.0f, 8.0f, 10.0f)), eps, "positive distance");
- test.checkFloat(0.911684612f, p.getSignedDistance(Vector3(3.0f, 2.0f, 1.0f)), eps, "negative distance");
- }
- void PlaneTests::test() {
- Test test("Plane");
- testToString1(test);
- testToString2(test);
- testSignedDistance(test);
- test.finalize();
- }
|