mirror of
https://github.com/boostorg/geometry.git
synced 2025-05-09 23:24:02 +00:00
[simplify] prepare test for distance object instead of always value, and
added overload accepting a strategy
This commit is contained in:
parent
0315125492
commit
999ba36e06
@ -30,7 +30,10 @@ struct test_inserter
|
||||
template <typename Geometry>
|
||||
struct test_inserter<bg::linestring_tag, Geometry>
|
||||
{
|
||||
static void apply(Geometry& geometry, std::string const& expected, double distance)
|
||||
template <typename DistanceMeasure>
|
||||
static void apply(Geometry& geometry,
|
||||
std::string const& expected,
|
||||
DistanceMeasure const& distance)
|
||||
{
|
||||
Geometry simplified;
|
||||
bg::detail::simplify::simplify_insert(geometry,
|
||||
@ -45,10 +48,10 @@ struct test_inserter<bg::linestring_tag, Geometry>
|
||||
};
|
||||
|
||||
|
||||
template <typename Geometry>
|
||||
template <typename Geometry, typename DistanceMeasure>
|
||||
void check_geometry(Geometry const& geometry,
|
||||
std::string const& expected,
|
||||
double distance)
|
||||
DistanceMeasure const& distance)
|
||||
{
|
||||
Geometry simplified;
|
||||
bg::simplify(geometry, simplified, distance);
|
||||
@ -58,10 +61,10 @@ void check_geometry(Geometry const& geometry,
|
||||
BOOST_CHECK_EQUAL(out.str(), expected);
|
||||
}
|
||||
|
||||
template <typename Geometry, typename Strategy>
|
||||
template <typename Geometry, typename Strategy, typename DistanceMeasure>
|
||||
void check_geometry(Geometry const& geometry,
|
||||
std::string const& expected,
|
||||
double distance,
|
||||
DistanceMeasure const& distance,
|
||||
Strategy const& strategy)
|
||||
{
|
||||
Geometry simplified;
|
||||
@ -72,11 +75,14 @@ void check_geometry(Geometry const& geometry,
|
||||
BOOST_CHECK_EQUAL(out.str(), expected);
|
||||
}
|
||||
|
||||
template <typename Geometry>
|
||||
void test_geometry(std::string const& wkt, std::string const& expected, double distance)
|
||||
template <typename Geometry, typename Strategy, typename DistanceMeasure>
|
||||
void test_geometry(std::string const& wkt,
|
||||
std::string const& expected,
|
||||
DistanceMeasure const& distance,
|
||||
Strategy const& strategy)
|
||||
{
|
||||
// Generate polygon using only integer coordinates and obvious results
|
||||
// Polygon is a hexagon, having one extra point (2,1) on a line which should be filtered out.
|
||||
typedef typename bg::point_type<Geometry>::type point_type;
|
||||
|
||||
Geometry geometry;
|
||||
bg::read_wkt(wkt, geometry);
|
||||
boost::variant<Geometry> v(geometry);
|
||||
@ -84,19 +90,11 @@ void test_geometry(std::string const& wkt, std::string const& expected, double d
|
||||
check_geometry(geometry, expected, distance);
|
||||
check_geometry(v, expected, distance);
|
||||
|
||||
// Check using user-specified strategy
|
||||
typedef typename bg::point_type<Geometry>::type point_type;
|
||||
typedef bg::strategy::distance::projected_point<double> strategy;
|
||||
typedef bg::strategy::simplify::douglas_peucker
|
||||
<
|
||||
point_type,
|
||||
strategy
|
||||
> simplify_strategy_type;
|
||||
|
||||
BOOST_CONCEPT_ASSERT( (bg::concept::SimplifyStrategy<simplify_strategy_type, point_type>) );
|
||||
//BOOST_CONCEPT_ASSERT( (bg::concept::SimplifyStrategy<Strategy, point_type>) );
|
||||
|
||||
check_geometry(geometry, expected, distance, simplify_strategy_type());
|
||||
check_geometry(v, expected, distance, simplify_strategy_type());
|
||||
check_geometry(geometry, expected, distance, strategy);
|
||||
check_geometry(v, expected, distance, strategy);
|
||||
|
||||
// Check inserter (if applicable)
|
||||
test_inserter
|
||||
@ -106,5 +104,20 @@ void test_geometry(std::string const& wkt, std::string const& expected, double d
|
||||
>::apply(geometry, expected, distance);
|
||||
}
|
||||
|
||||
template <typename Geometry, typename DistanceMeasure>
|
||||
void test_geometry(std::string const& wkt,
|
||||
std::string const& expected,
|
||||
DistanceMeasure distance)
|
||||
{
|
||||
// Define default strategy for testing
|
||||
typedef bg::strategy::simplify::douglas_peucker
|
||||
<
|
||||
typename bg::point_type<Geometry>::type,
|
||||
bg::strategy::distance::projected_point<double>
|
||||
> dp;
|
||||
|
||||
test_geometry<Geometry>(wkt, expected, distance, dp());
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user