diff --git a/include/boost/geometry/strategies/agnostic/simplify_douglas_peucker.hpp b/include/boost/geometry/strategies/agnostic/simplify_douglas_peucker.hpp index e4be713ae..8ad3bbc50 100644 --- a/include/boost/geometry/strategies/agnostic/simplify_douglas_peucker.hpp +++ b/include/boost/geometry/strategies/agnostic/simplify_douglas_peucker.hpp @@ -261,11 +261,7 @@ class douglas_peucker { public : - // See also ticket 5954 https://svn.boost.org/trac/boost/ticket/5954 - // Comparable is currently not possible here because it has to be compared to the squared of max_distance, and more. - // For now we have to take the real distance. typedef PointDistanceStrategy distance_strategy_type; - // typedef typename strategy::distance::services::comparable_type::type distance_strategy_type; typedef typename detail::douglas_peucker < diff --git a/include/boost/geometry/strategies/cartesian/distance_projected_point_ax.hpp b/include/boost/geometry/strategies/cartesian/distance_projected_point_ax.hpp index ace642f7c..2bff55125 100644 --- a/include/boost/geometry/strategies/cartesian/distance_projected_point_ax.hpp +++ b/include/boost/geometry/strategies/cartesian/distance_projected_point_ax.hpp @@ -66,6 +66,12 @@ struct projected_point_ax_result : atd(a), xtd(x) {} + friend inline bool operator<(projected_point_ax_result const& left, + projected_point_ax_result const& right) + { + return left.xtd < right.xtd || left.atd < right.atd; + } + T atd, xtd; }; @@ -81,7 +87,6 @@ public: : m_max_distance(max_distance) {} - template inline bool operator()(Distance const& left, Distance const& right) const { return left.xtd < right.xtd && right.atd < m_max_distance.atd; diff --git a/test/algorithms/simplify.cpp b/test/algorithms/simplify.cpp index 919e84c69..dbffc8b41 100644 --- a/test/algorithms/simplify.cpp +++ b/test/algorithms/simplify.cpp @@ -116,5 +116,7 @@ int test_main(int, char* []) test_spherical > >(); #endif + + return 0; } diff --git a/test/algorithms/test_simplify.hpp b/test/algorithms/test_simplify.hpp index 4f67cade3..94e8d2be3 100644 --- a/test/algorithms/test_simplify.hpp +++ b/test/algorithms/test_simplify.hpp @@ -32,15 +32,43 @@ struct test_inserter { static void apply(Geometry& geometry, std::string const& expected, double distance) { - Geometry simplified; - bg::detail::simplify::simplify_insert(geometry, - std::back_inserter(simplified), distance); + { + Geometry simplified; + bg::detail::simplify::simplify_insert(geometry, + std::back_inserter(simplified), distance); - std::ostringstream out; - // TODO: instead of comparing the full string (with more or less decimal digits), - // we should call something more robust to check the test for example geometry::equals - out << std::setprecision(12) << bg::wkt(simplified); - BOOST_CHECK_EQUAL(out.str(), expected); + std::ostringstream out; + // TODO: instead of comparing the full string (with more or less decimal digits), + // we should call something more robust to check the test for example geometry::equals + out << std::setprecision(12) << bg::wkt(simplified); + BOOST_CHECK_EQUAL(out.str(), expected); + } + + { + typedef typename bg::point_type::type point_type; + typedef typename bg::strategy::distance::detail::projected_point_ax<>::template result_type::type distance_type; + typedef bg::strategy::distance::detail::projected_point_ax_less less_comparator; + + distance_type max_distance(distance); + less_comparator less(max_distance); + + bg::strategy::simplify::detail::douglas_peucker + < + point_type, + bg::strategy::distance::detail::projected_point_ax<>, + less_comparator + > strategy(less); + + Geometry simplified; + bg::detail::simplify::simplify_insert(geometry, + std::back_inserter(simplified), max_distance, strategy); + + std::ostringstream out; + // TODO: instead of comparing the full string (with more or less decimal digits), + // we should call something more robust to check the test for example geometry::equals + out << std::setprecision(12) << bg::wkt(simplified); + BOOST_CHECK_EQUAL(out.str(), expected); + } } }; @@ -104,6 +132,25 @@ void test_geometry(std::string const& wkt, std::string const& expected, double d typename bg::tag::type, Geometry >::apply(geometry, expected, distance); + + // Check using non-default less comparator in douglass_peucker + typedef typename bg::strategy::distance::detail::projected_point_ax<>::template result_type::type distance_type; + typedef bg::strategy::distance::detail::projected_point_ax_less less_comparator; + + distance_type const max_distance(distance); + less_comparator const less(max_distance); + + typedef bg::strategy::simplify::detail::douglas_peucker + < + point_type, + bg::strategy::distance::detail::projected_point_ax<>, + less_comparator + > douglass_peucker_with_less; + + BOOST_CONCEPT_ASSERT( (bg::concept::SimplifyStrategy) ); + + check_geometry(geometry, expected, distance, douglass_peucker_with_less(less)); + check_geometry(v, expected, distance, douglass_peucker_with_less(less)); }