Browse Source

Moved Math::GeometryUtils to Math::Geometry::Intersection.

The namespace will contain classes (and functions) for computing
intersections, distances, areas and volumes.
vectorfields
Vladimír Vondruš 14 years ago
parent
commit
6f94d84b1a
  1. 6
      doc/namespaces.dox
  2. 2
      src/Math/CMakeLists.txt
  3. 7
      src/Math/Geometry/CMakeLists.txt
  4. 26
      src/Math/Geometry/Intersection.h
  5. 1
      src/Math/Geometry/Test/CMakeLists.txt
  6. 20
      src/Math/Geometry/Test/IntersectionTest.cpp
  7. 12
      src/Math/Geometry/Test/IntersectionTest.h
  8. 1
      src/Math/Test/CMakeLists.txt

6
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

2
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

7
src/Math/Geometry/CMakeLists.txt

@ -0,0 +1,7 @@
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
if(BUILD_TESTS)
enable_testing()
add_subdirectory(Test)
endif()

26
src/Math/GeometryUtils.h → 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š <mosra@centrum.cz>
@ -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<class T> static T intersection(const Vector3<T>& planePosition, const Vector3<T>& planeNormal, const Vector3<T>& a, const Vector3<T>& b) {
template<class T> static T planeLine(const Vector3<T>& planePosition, const Vector3<T>& planeNormal, const Vector3<T>& a, const Vector3<T>& b) {
/* Compute f from normal and plane position */
T f = Vector3<T>::dot(planePosition, planeNormal);
@ -65,6 +63,6 @@ class GeometryUtils {
}
};
}}
}}}
#endif

1
src/Math/Geometry/Test/CMakeLists.txt

@ -0,0 +1 @@
corrade_add_test(MathGeometryIntersectionTest IntersectionTest.h IntersectionTest.cpp)

20
src/Math/Test/GeometryUtilsTest.cpp → 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 <limits>
#include <QtTest/QTest>
#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<float> 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<float>::infinity());
}
}}}
}}}}

12
src/Math/Test/GeometryUtilsTest.h → 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š <mosra@centrum.cz>
@ -17,15 +17,15 @@
#include <QtCore/QObject>
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

1
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)

Loading…
Cancel
Save