/* Copyright © 2010, 2011, 2012 Vladimír Vondruš This file is part of Magnum. Magnum is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3 only, as published by the Free Software Foundation. Magnum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License version 3 for more details. */ #include "GeometryUtilsTest.h" #include #include #include "Matrix3.h" #include "GeometryUtils.h" QTEST_APPLESS_MAIN(Magnum::Math::Test::GeometryUtilsTest) typedef Magnum::Math::Matrix3 Matrix3; typedef Magnum::Math::Vector3 Vector3; Q_DECLARE_METATYPE(Matrix3) Q_DECLARE_METATYPE(Vector3) using namespace std; namespace Magnum { namespace Math { namespace Test { using ::Matrix3; using ::Vector3; void GeometryUtilsTest::intersection_data() { QTest::addColumn("plane"); QTest::addColumn("a"); QTest::addColumn("b"); QTest::addColumn("expected"); Matrix3 plane(0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); QTest::newRow("inside") << plane << Vector3(0, 0, -1) << Vector3(0, 0, 1) << 0.5f; QTest::newRow("outside") << plane << Vector3(0, 0, 1) << Vector3(0, 0, 2) << -1.0f; QTest::newRow("NaN") << plane << Vector3(1, 0, 0) << Vector3(0, 1, 0) << numeric_limits::quiet_NaN(); QTest::newRow("inf") << plane << Vector3(1, 0, 1) << Vector3(0, 0, 1) << numeric_limits::infinity(); } void GeometryUtilsTest::intersection() { QFETCH(Matrix3, plane); QFETCH(Vector3, a); QFETCH(Vector3, b); QFETCH(float, expected); /* Handling also NaN, which cannot be fuzzy compared */ float actual = GeometryUtils::intersection(plane, a, b); /* All possible workarounds for comparing to inf and NaN */ if(expected > numeric_limits::max()) QCOMPARE(actual, expected); else if(expected != expected) QVERIFY(actual != actual); else QVERIFY(actual == expected); } }}}