diff --git a/test/algorithms/distance.cpp b/test/algorithms/distance.cpp index ab7fc5bf6..04c3f6f3f 100644 --- a/test/algorithms/distance.cpp +++ b/test/algorithms/distance.cpp @@ -12,7 +12,6 @@ // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) -#define TEST_ARRAY #include @@ -150,6 +149,27 @@ void test_distance_segment() BOOST_CHECK_CLOSE(d1, return_type(1), 0.001); } +template +void test_distance_linear(std::string const& wkt_point, std::string const& wkt_geometry, T const& expected) +{ + Point p; + bg::read_wkt(wkt_point, p); + + Geometry g; + bg::read_wkt(wkt_geometry, g); + + typedef typename bg::default_distance_result::type return_type; + return_type d = bg::distance(p, g); + + // For point-to-linestring (or point-to-polygon), both a point-strategy and a point-segment-strategy can be specified. + // Test this. + return_type ds1 = bg::distance(p, g, bg::strategy::distance::pythagoras<>()); + return_type ds2 = bg::distance(p, g, bg::strategy::distance::projected_point<>()); + + BOOST_CHECK_CLOSE(d, return_type(expected), 0.001); + BOOST_CHECK_CLOSE(ds1, return_type(expected), 0.001); + BOOST_CHECK_CLOSE(ds2, return_type(expected), 0.001); +} template void test_distance_array_as_linestring() @@ -233,6 +253,8 @@ void test_all() test_geometry >("POINT(3 1)", "LINESTRING(1 1,4 4)", sqrt(2.0)); + test_distance_linear >("POINT(3 1)", "LINESTRING(1 1,4 4)", sqrt(2.0)); + } template