From 6f94d84b1a4c19a8a8a49e7b923e38d161e5ff60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Fri, 27 Apr 2012 21:28:21 +0200 Subject: [PATCH] Moved Math::GeometryUtils to Math::Geometry::Intersection. The namespace will contain classes (and functions) for computing intersections, distances, areas and volumes. --- doc/namespaces.dox | 6 +++++ src/Math/CMakeLists.txt | 2 ++ src/Math/Geometry/CMakeLists.txt | 7 +++++ .../Intersection.h} | 26 +++++++++---------- src/Math/Geometry/Test/CMakeLists.txt | 1 + .../Test/IntersectionTest.cpp} | 20 +++++++------- .../Test/IntersectionTest.h} | 12 ++++----- src/Math/Test/CMakeLists.txt | 1 - 8 files changed, 44 insertions(+), 31 deletions(-) create mode 100644 src/Math/Geometry/CMakeLists.txt rename src/Math/{GeometryUtils.h => Geometry/Intersection.h} (78%) create mode 100644 src/Math/Geometry/Test/CMakeLists.txt rename src/Math/{Test/GeometryUtilsTest.cpp => Geometry/Test/IntersectionTest.cpp} (69%) rename src/Math/{Test/GeometryUtilsTest.h => Geometry/Test/IntersectionTest.h} (71%) diff --git a/doc/namespaces.dox b/doc/namespaces.dox index 4a7054097..2c09beb5c 100644 --- a/doc/namespaces.dox +++ b/doc/namespaces.dox @@ -1,3 +1,9 @@ +/** @namespace Magnum::Math::Geometry +@brief %Geometry library + +Functions for computing intersections, distances, areas and volumes. +*/ + /** @namespace Magnum::MeshTools @brief %Mesh tools diff --git a/src/Math/CMakeLists.txt b/src/Math/CMakeLists.txt index 2dcb5d6a3..58350ed6e 100644 --- a/src/Math/CMakeLists.txt +++ b/src/Math/CMakeLists.txt @@ -1,5 +1,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +add_subdirectory(Geometry) + if(BUILD_TESTS) # Add Math library for testing purposes diff --git a/src/Math/Geometry/CMakeLists.txt b/src/Math/Geometry/CMakeLists.txt new file mode 100644 index 000000000..7242acb5b --- /dev/null +++ b/src/Math/Geometry/CMakeLists.txt @@ -0,0 +1,7 @@ +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) + +if(BUILD_TESTS) + enable_testing() + add_subdirectory(Test) +endif() + diff --git a/src/Math/GeometryUtils.h b/src/Math/Geometry/Intersection.h similarity index 78% rename from src/Math/GeometryUtils.h rename to src/Math/Geometry/Intersection.h index cd895b2b5..f79eae8dc 100644 --- a/src/Math/GeometryUtils.h +++ b/src/Math/Geometry/Intersection.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Math_GeometryUtils_h -#define Magnum_Math_GeometryUtils_h +#ifndef Magnum_Math_Geometry_Intersection_h +#define Magnum_Math_Geometry_Intersection_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -16,26 +16,24 @@ */ /** @file - * @brief Class Magnum::Math::GeometryUtils + * @brief Class Magnum::Math::Geometry::Intersection */ -#include "Vector3.h" +#include "Math/Vector3.h" -namespace Magnum { namespace Math { +namespace Magnum { namespace Math { namespace Geometry { -/** -@brief Geometry utils -*/ -class GeometryUtils { +/** @brief Functions for computing intersections */ +class Intersection { public: /** - * @brief Intersection of a plane and line + * @brief %Intersection of a plane and line * @param planePosition Plane position * @param planeNormal Plane normal * @param a Starting point of the line * @param b Ending point of the line - * @return Intersection point position, NaN if the line lies on the - * plane or infinity if the intersection doesn't exist. Intersection + * @return %Intersection point position, NaN if the line lies on the + * plane or infinity if the intersection doesn't exist. %Intersection * point can be computed from the position with `a+intersection(...)*b`. * If returned value is in range @f$ [ 0 ; 1 ] @f$, the intersection * is inside the line segment defined by `a` and `b`. @@ -56,7 +54,7 @@ class GeometryUtils { * \end{array} * @f] */ - template static T intersection(const Vector3& planePosition, const Vector3& planeNormal, const Vector3& a, const Vector3& b) { + template static T planeLine(const Vector3& planePosition, const Vector3& planeNormal, const Vector3& a, const Vector3& b) { /* Compute f from normal and plane position */ T f = Vector3::dot(planePosition, planeNormal); @@ -65,6 +63,6 @@ class GeometryUtils { } }; -}} +}}} #endif diff --git a/src/Math/Geometry/Test/CMakeLists.txt b/src/Math/Geometry/Test/CMakeLists.txt new file mode 100644 index 000000000..1cff67c30 --- /dev/null +++ b/src/Math/Geometry/Test/CMakeLists.txt @@ -0,0 +1 @@ +corrade_add_test(MathGeometryIntersectionTest IntersectionTest.h IntersectionTest.cpp) diff --git a/src/Math/Test/GeometryUtilsTest.cpp b/src/Math/Geometry/Test/IntersectionTest.cpp similarity index 69% rename from src/Math/Test/GeometryUtilsTest.cpp rename to src/Math/Geometry/Test/IntersectionTest.cpp index a26c88239..51e76ff89 100644 --- a/src/Math/Test/GeometryUtilsTest.cpp +++ b/src/Math/Geometry/Test/IntersectionTest.cpp @@ -13,41 +13,41 @@ GNU Lesser General Public License version 3 for more details. */ -#include "GeometryUtilsTest.h" +#include "IntersectionTest.h" #include #include -#include "GeometryUtils.h" +#include "Intersection.h" -QTEST_APPLESS_MAIN(Magnum::Math::Test::GeometryUtilsTest) +QTEST_APPLESS_MAIN(Magnum::Math::Geometry::Test::IntersectionTest) using namespace std; -namespace Magnum { namespace Math { namespace Test { +namespace Magnum { namespace Math { namespace Geometry { namespace Test { typedef Magnum::Math::Vector3 Vector3; -void GeometryUtilsTest::intersection() { +void IntersectionTest::planeLine() { Vector3 planePosition; Vector3 planeNormal(0.0f, 0.0f, 1.0f); /* Inside line segment */ - QCOMPARE((GeometryUtils::intersection(planePosition, planeNormal, + QCOMPARE((Intersection::planeLine(planePosition, planeNormal, Vector3(0, 0, -1), Vector3(0, 0, 1))), 0.5f); /* Outside line segment */ - QCOMPARE((GeometryUtils::intersection(planePosition, planeNormal, + QCOMPARE((Intersection::planeLine(planePosition, planeNormal, Vector3(0, 0, 1), Vector3(0, 0, 2))), -1.0f); /* Line lies on the plane */ - float nan = GeometryUtils::intersection(planePosition, planeNormal, + float nan = Intersection::planeLine(planePosition, planeNormal, Vector3(1, 0, 0), Vector3(0, 1, 0)); QVERIFY(nan != nan); /* Line is parallell to the plane */ - QCOMPARE((GeometryUtils::intersection(planePosition, planeNormal, + QCOMPARE((Intersection::planeLine(planePosition, planeNormal, Vector3(1, 0, 1), Vector3(0, 0, 1))), numeric_limits::infinity()); } -}}} +}}}} diff --git a/src/Math/Test/GeometryUtilsTest.h b/src/Math/Geometry/Test/IntersectionTest.h similarity index 71% rename from src/Math/Test/GeometryUtilsTest.h rename to src/Math/Geometry/Test/IntersectionTest.h index bd25c1a79..61bbd0359 100644 --- a/src/Math/Test/GeometryUtilsTest.h +++ b/src/Math/Geometry/Test/IntersectionTest.h @@ -1,5 +1,5 @@ -#ifndef Magnum_Math_Test_GeometryUtilsTest_h -#define Magnum_Math_Test_GeometryUtilsTest_h +#ifndef Magnum_Math_Geometry_Test_IntersectionTest_h +#define Magnum_Math_Geometry_Test_IntersectionTest_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš @@ -17,15 +17,15 @@ #include -namespace Magnum { namespace Math { namespace Test { +namespace Magnum { namespace Math { namespace Geometry { namespace Test { -class GeometryUtilsTest: public QObject { +class IntersectionTest: public QObject { Q_OBJECT private slots: - void intersection(); + void planeLine(); }; -}}} +}}}} #endif diff --git a/src/Math/Test/CMakeLists.txt b/src/Math/Test/CMakeLists.txt index 02c3e4459..ec2adac6f 100644 --- a/src/Math/Test/CMakeLists.txt +++ b/src/Math/Test/CMakeLists.txt @@ -10,4 +10,3 @@ corrade_add_test(MathMatrix3Test Matrix3Test.h Matrix3Test.cpp ${CORRADE_UTILITY corrade_add_test(MathMatrix4Test Matrix4Test.h Matrix4Test.cpp ${CORRADE_UTILITY_LIBRARY}) corrade_add_test(MathTest MathTest.h MathTest.cpp MagnumMath) -corrade_add_test(MathGeometryUtilsTest GeometryUtilsTest.h GeometryUtilsTest.cpp)