From 5b4eb2a558d395c6420e85912a64fe4575cd2ad5 Mon Sep 17 00:00:00 2001 From: Joey Andres Date: Fri, 24 Apr 2015 21:51:14 -0600 Subject: [PATCH] fixed test, added documentation, refactor --- include/DouglasPeucker.h | 72 +++++++++++++++++++++++++++++++++ test/src/DouglasPeuckerTest.cpp | 22 +++++----- 2 files changed, 82 insertions(+), 12 deletions(-) diff --git a/include/DouglasPeucker.h b/include/DouglasPeucker.h index 9053394..0b79504 100644 --- a/include/DouglasPeucker.h +++ b/include/DouglasPeucker.h @@ -148,6 +148,13 @@ struct p2dAccessor{ inline static double getY(const p2d& p) { return std::get<1>(p); } }; +/*!@class Distance2D + * @brief cartesian distance in 2D. + * + * @typename T 2D data type. + * @typename TAccessor2D an accessor class that contains getX and getY. + * defaults to void if T have getX and getY method. + */ template class Distance2D{ public: @@ -158,6 +165,11 @@ class Distance2D{ } }; +/*!@class Distance2D + * @brief cartesian distance in 2D. + * + * @typename T 2D data type. + */ template class Distance2D{ public: @@ -168,6 +180,13 @@ class Distance2D{ } }; +/*!@class PointSegmentDistance2D + * @brief Distance between point and a line segment. + * + * @typename T 2D data type. + * @typename TAccessor2D an accessor class that contains getX and getY. + * defaults to void if T have getX and getY method. + */ template class PointSegmentDistance2D{ public: @@ -188,6 +207,11 @@ class PointSegmentDistance2D{ } }; +/*!@class PointSegmentDistance2D + * @brief Distance between point and a line segment. + * + * @typename T 2D data type. + */ template class PointSegmentDistance2D{ public: @@ -207,6 +231,13 @@ class PointSegmentDistance2D{ } }; +/*!@class DouglasPuecker2D + * @brief Douglas-Peucker implementation for 2D line. + * + * @typename T 2D data type. + * @typename TAccessor2D an accessor class that contains getX and getY. + * defaults to void if T have getX and getY method. + */ template class DouglasPuecker2D final : public DouglasPeuckerAbstract{ public: @@ -223,6 +254,11 @@ class DouglasPuecker2D final : public DouglasPeuckerAbstract{ } }; +/*!@class DouglasPuecker2D + * @brief Douglas-Peucker implementation for 2D line. + * + * @typename T 2D data type. + */ template class DouglasPuecker2D final : public DouglasPeuckerAbstract{ public: @@ -256,6 +292,13 @@ struct p3dAccessor{ } }; +/*!@class Distance3D + * @brief cartesian distance in 3D. + * + * @typename T 3D data type. + * @typename TAccessor3D an accessor class that contains getX, getY and getZ. + * defaults to void if T have getX, getY, getZ. + */ template class Distance3D{ public: @@ -267,6 +310,11 @@ class Distance3D{ } }; +/*!@class Distance3D + * @brief cartesian distance in 3D. + * + * @typename T 3D data type. + */ template class Distance3D{ public: @@ -278,6 +326,13 @@ class Distance3D{ } }; +/*!@class PointSegmentDistance3D + * @brief Distance between point and a line segment. + * + * @typename T 3D data type. + * @typename TAccessor3D an accessor class that contains getX, getY and getZ. + * defaults to void if T have getX, getY, getZ. + */ template class PointSegmentDistance3D{ public: @@ -319,6 +374,11 @@ class PointSegmentDistance3D{ } }; +/*!@class PointSegmentDistance3D + * @brief Distance between point and a line segment. + * + * @typename T 3D data type. + */ template class PointSegmentDistance3D{ public: @@ -361,6 +421,13 @@ class PointSegmentDistance3D{ } }; +/*!@class DouglasPuecker3D + * @brief Douglas-Peucker implementation for 3d line. + * + * @typename T 3D data type. + * @typename TAccessor3D an accessor class that contains getX, getY and getZ. + * defaults to void if T have getX, getY, getZ. + */ template class DouglasPuecker3D final : public DouglasPeuckerAbstract{ public: @@ -379,6 +446,11 @@ class DouglasPuecker3D final : public DouglasPeuckerAbstract{ } }; +/*!@class DouglasPuecker3D + * @brief Douglas-Peucker implementation for 3d line. + * + * @typename T 3D data type. + */ template class DouglasPuecker3D final : public DouglasPeuckerAbstract{ public: diff --git a/test/src/DouglasPeuckerTest.cpp b/test/src/DouglasPeuckerTest.cpp index 1256a52..db91a80 100644 --- a/test/src/DouglasPeuckerTest.cpp +++ b/test/src/DouglasPeuckerTest.cpp @@ -48,22 +48,20 @@ struct point3dAccessor{ }; void DouglasPeuckerTest::distanceTest() { - DouglasPuecker2D dp2d; - CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, - dp2d._distance(p2d(-2, 1), - p2d(1, 5)), 0.001F); + double result = Distance2D::getDistance(p2d(-2, 1), + p2d(1, 5)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, result, 0.001F); } void DouglasPeuckerTest::distanceTest2() { - DouglasPuecker2D dp2d; - CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, - dp2d._distance(point2d(-2, 1), - point2d(1, 5)), 0.001F); + double result = Distance2D::getDistance(point2d(-2, 1), + point2d(1, 5)); + CPPUNIT_ASSERT_DOUBLES_EQUAL(5.0, result, 0.001F); } void DouglasPeuckerTest::pointSegmentDistance() { - DouglasPuecker2D dp2d; + DouglasPuecker2D dp2d(std::list({})); double result = dp2d._pointSegmentDistance(p2d(1.0F, -2.0F/3.0F), p2d(2.0F, 0.0F), p2d(5.0F, 6.0F)); @@ -71,7 +69,7 @@ void DouglasPeuckerTest::pointSegmentDistance() { } void DouglasPeuckerTest::pointSegmentDistance2() { - DouglasPuecker2D dp2d; + DouglasPuecker2D dp2d(std::list({})); double result = dp2d._pointSegmentDistance(point2d(1.0F, -2.0F/3.0F), point2d(2.0F, 0.0F), point2d(5.0F, 6.0F)); @@ -81,7 +79,7 @@ void DouglasPeuckerTest::pointSegmentDistance2() { // For simplicity, we are just going to test if this is consistent with the 2D, // by just adding 0 as the magntide of 3rd dimension. void DouglasPeuckerTest::pointSegmentDistance3D() { - DouglasPuecker3D dp3d; + DouglasPuecker3D dp3d(std::list({})); double result = dp3d._pointSegmentDistance(p3d(1.0F, -2.0F/3.0F, 0.0f), p3d(2.0F, 0.0F, 0.0f), p3d(5.0F, 6.0F, 0.0f)); @@ -89,7 +87,7 @@ void DouglasPeuckerTest::pointSegmentDistance3D() { } void DouglasPeuckerTest::pointSegmentDistance3D2() { - DouglasPuecker3D dp3d; + DouglasPuecker3D dp3d(std::list({})); double result = dp3d._pointSegmentDistance(point3d(1.0F, -2.0F/3.0F, 0.0f), point3d(2.0F, 0.0F, 0.0f), point3d(5.0F, 6.0F, 0.0f));