[strategies] Fix projected_point_ax+douglass_peucker compilation errors.

Add again operator< for projected_point_ax_result needed to compare the distance with 0 (explicitly converted into the same type).
Remove template parameter from projected_point_ax_less::operator().
Add tests for simplify() and detail::simplify_insert().
This commit is contained in:
Adam Wulkiewicz 2014-07-09 12:58:02 +02:00
parent e49434ec6c
commit c55cee5dd3
4 changed files with 63 additions and 13 deletions

View File

@ -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<PointDistanceStrategy>::type distance_strategy_type;
typedef typename detail::douglas_peucker
<

View File

@ -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 <typename T>
inline bool operator()(Distance const& left, Distance const& right) const
{
return left.xtd < right.xtd && right.atd < m_max_distance.atd;

View File

@ -116,5 +116,7 @@ int test_main(int, char* [])
test_spherical<bg::model::point<ttmath_big, 2, bg::cs::spherical_equatorial<bg::degree> > >();
#endif
return 0;
}

View File

@ -32,15 +32,43 @@ struct test_inserter<bg::linestring_tag, Geometry>
{
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<Geometry>::type point_type;
typedef typename bg::strategy::distance::detail::projected_point_ax<>::template result_type<point_type, point_type>::type distance_type;
typedef bg::strategy::distance::detail::projected_point_ax_less<distance_type> 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<Geometry>::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<point_type, point_type>::type distance_type;
typedef bg::strategy::distance::detail::projected_point_ax_less<distance_type> 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<douglass_peucker_with_less, point_type>) );
check_geometry(geometry, expected, distance, douglass_peucker_with_less(less));
check_geometry(v, expected, distance, douglass_peucker_with_less(less));
}