diff options
Diffstat (limited to 'libs/geometry/test/strategies/projected_point.cpp')
-rw-r--r-- | libs/geometry/test/strategies/projected_point.cpp | 71 |
1 files changed, 50 insertions, 21 deletions
diff --git a/libs/geometry/test/strategies/projected_point.cpp b/libs/geometry/test/strategies/projected_point.cpp index e9f65ca467..11ea749a13 100644 --- a/libs/geometry/test/strategies/projected_point.cpp +++ b/libs/geometry/test/strategies/projected_point.cpp @@ -87,33 +87,62 @@ void test_services() } -template <typename P1, typename P2> -void test_all_2d() +template <typename P1, typename P2, typename T> +void test_all_2d(std::string const& wkt_p, + std::string const& wkt_sp1, + std::string const& wkt_sp2, + T expected_distance) { P1 p; P2 sp1, sp2; - bg::read_wkt("POINT(1 1)", p); - bg::read_wkt("POINT(0 0)", sp1); - bg::read_wkt("POINT(2 3)", sp2); - - typedef typename bg::strategy::distance::projected_point - < - P1, - P2 - > strategy_type; - - BOOST_CONCEPT_ASSERT - ( - (bg::concept::PointSegmentDistanceStrategy<strategy_type>) - ); - + bg::read_wkt(wkt_p, p); + bg::read_wkt(wkt_sp1, sp1); + bg::read_wkt(wkt_sp2, sp2); + + { + typedef bg::strategy::distance::projected_point + < + P1, + P2 + > strategy_type; + + BOOST_CONCEPT_ASSERT + ( + (bg::concept::PointSegmentDistanceStrategy<strategy_type>) + ); + + strategy_type strategy; + typedef typename bg::strategy::distance::services::return_type<strategy_type>::type return_type; + return_type d = strategy.apply(p, sp1, sp2); + BOOST_CHECK_CLOSE(d, expected_distance, 0.001); + } + + // Test combination with the comparable strategy + { + typedef bg::strategy::distance::projected_point + < + P1, + P2, + void, + bg::strategy::distance::comparable::pythagoras<P1, P2> + > strategy_type; + strategy_type strategy; + typedef typename bg::strategy::distance::services::return_type<strategy_type>::type return_type; + return_type d = strategy.apply(p, sp1, sp2); + T expected_squared_distance = expected_distance * expected_distance; + BOOST_CHECK_CLOSE(d, expected_squared_distance, 0.01); + } - strategy_type strategy; - typedef typename bg::strategy::distance::services::return_type<strategy_type>::type return_type; - return_type d = strategy.apply(p, sp1, sp2); - BOOST_CHECK_CLOSE(d, return_type(0.27735203958327), 0.001); } +template <typename P1, typename P2> +void test_all_2d() +{ + test_all_2d<P1, P2>("POINT(1 1)", "POINT(0 0)", "POINT(2 3)", 0.27735203958327); + test_all_2d<P1, P2>("POINT(2 2)", "POINT(1 4)", "POINT(4 1)", 0.5 * sqrt(2.0)); + test_all_2d<P1, P2>("POINT(6 1)", "POINT(1 4)", "POINT(4 1)", 2.0); + test_all_2d<P1, P2>("POINT(1 6)", "POINT(1 4)", "POINT(4 1)", 2.0); +} template <typename P> void test_all_2d() |