#include "tests/PlaneTests.h"

#include "math/Plane.h"
#include "test/Test.h"

const float eps = 0.0001f;

using V3 = Core::Vector3;

static void testToString1() {
    Core::Plane p;
    CORE_TEST_STRING("(0.00 x + 0.00 y + 0.00 z + 0.00)", p);
}

static void testToString2() {
    Core::Plane p(V3(3.0f, 6.0f, 8.0f), V3(7.0f, 6.0f, 2.0f),
                  V3(4.0f, 4.0f, 4.0f));
    CORE_TEST_STRING("(-0.68 x + 0.57 y + -0.46 z + 2.28)", p);
}

static void testSignedDistance() {
    V3 a(3.0f, 6.0f, 8.0f);
    V3 b(7.0f, 6.0f, 2.0f);
    V3 c(4.0f, 4.0f, 4.0f);
    Core::Plane p(a, b, c);
    CORE_TEST_FLOAT(0.0f, p.getSignedDistance(a), eps);
    CORE_TEST_FLOAT(0.0f, p.getSignedDistance(b), eps);
    CORE_TEST_FLOAT(0.0f, p.getSignedDistance(c), eps);
    CORE_TEST_FLOAT(-1.13960576f, p.getSignedDistance(V3(5.0f, 8.0f, 10.0f)),
                    eps);
    CORE_TEST_FLOAT(0.911684612f, p.getSignedDistance(V3(3.0f, 2.0f, 1.0f)),
                    eps);
}

void Core::PlaneTests::test() {
    testToString1();
    testToString2();
    testSignedDistance();
}