diff --git a/test/algorithms/distance/distance_brute_force.hpp b/test/algorithms/distance/distance_brute_force.hpp index 82d8f4d77..e1e157569 100644 --- a/test/algorithms/distance/distance_brute_force.hpp +++ b/test/algorithms/distance/distance_brute_force.hpp @@ -348,6 +348,39 @@ struct distance_brute_force } }; +template +< + typename Point, + typename MultiPolygon, + typename Strategy +> +struct distance_brute_force +< + Point, MultiPolygon, Strategy, + point_tag, multi_polygon_tag, false +> +{ + typedef typename distance_result + < + Point, MultiPolygon, Strategy + >::type distance_type; + + static inline distance_type apply(Point const& p, + MultiPolygon const& mp, + Strategy const& strategy) + { + return detail::distance_brute_force::one_to_many + < + distance_brute_force + < + Point, + typename boost::range_value::type, + Strategy + > + >::apply(p, boost::begin(mp), boost::end(mp), strategy); + } +}; + //======================================================================= template @@ -677,6 +710,45 @@ struct distance_brute_force } }; +template +< + typename Polygon, + typename MultiPoint, + typename Strategy +> +struct distance_brute_force +< + Polygon, MultiPoint, Strategy, + polygon_tag, multi_point_tag, false +> +{ + typedef typename distance_result + < + Polygon, MultiPoint, Strategy + >::type distance_type; + + static inline distance_type apply(Polygon const& polygon, + MultiPoint const& mp, + Strategy const& strategy) + { + return detail::distance_brute_force::one_to_many + < + distance_brute_force + < + MultiPoint, + typename std::iterator_traits + < + segment_iterator + >::value_type, + Strategy + > + >::apply(mp, + geometry::segments_begin(polygon), + geometry::segments_end(polygon), + strategy); + } +}; + //======================================================================== template @@ -732,16 +804,55 @@ struct distance_brute_force static inline distance_type apply(MultiPoint const& mp, Linear const& l, Strategy const& strategy) + { + return detail::distance_brute_force::one_to_many + < + distance_brute_force + < + MultiPoint, + typename std::iterator_traits + < + segment_iterator + >::value_type, + Strategy + > + >::apply(mp, + geometry::segments_begin(l), + geometry::segments_end(l), + strategy); + } +}; + +template +< + typename MultiPoint, + typename MultiPolygon, + typename Strategy +> +struct distance_brute_force +< + MultiPoint, MultiPolygon, Strategy, + multi_point_tag, multi_polygon_tag, false +> +{ + typedef typename distance_result + < + MultiPoint, MultiPolygon, Strategy + >::type distance_type; + + static inline distance_type apply(MultiPoint const& mp, + MultiPolygon const& mpl, + Strategy const& strategy) { return detail::distance_brute_force::one_to_many < distance_brute_force < MultiPoint, - typename boost::range_value::type, + typename boost::range_value::type, Strategy > - >::apply(mp, boost::begin(l), boost::end(l), strategy); + >::apply(mp, boost::begin(mpl), boost::end(mpl), strategy); } }; @@ -773,6 +884,48 @@ struct distance_brute_force } }; +template +< + typename MultiPoint, + typename Ring, + typename Strategy +> +struct distance_brute_force +< + MultiPoint, Ring, Strategy, + multi_point_tag, ring_tag, false +> +{ + typedef typename distance_result + < + MultiPoint, Ring, Strategy + >::type distance_type; + + static inline distance_type apply(MultiPoint const& mp, + Ring const& ring, + Strategy const& strategy) + { + + + return detail::distance_brute_force::one_to_many + < + distance_brute_force + < + MultiPoint, + typename std::iterator_traits + < + segment_iterator + >::value_type, + Strategy + > + >::apply(mp, + geometry::segments_begin(ring), + geometry::segments_end(ring), + strategy); + } +}; + + template < typename MultiPoint, diff --git a/test/algorithms/distance/distance_geo_pl_ar.cpp b/test/algorithms/distance/distance_geo_pl_ar.cpp index 61fad3bda..33f671416 100644 --- a/test/algorithms/distance/distance_geo_pl_ar.cpp +++ b/test/algorithms/distance/distance_geo_pl_ar.cpp @@ -22,85 +22,172 @@ #include #include "test_distance_geo_common.hpp" +#include "test_empty_geometry.hpp" -typedef bg::cs::geographic cs_type; -typedef bg::model::point point_type; -typedef bg::model::multi_point multi_point_type; -typedef bg::model::segment segment_type; -typedef bg::model::box box_type; +template +< + typename Point, + typename Strategy_pp, + typename Strategy_ps +> +void test_distance_point_ring(Strategy_pp const& strategy_pp, + Strategy_ps const& strategy_ps) +{ -namespace services = bg::strategy::distance::services; -typedef bg::default_distance_result::type return_type; +#ifdef BOOST_GEOMETRY_TEST_DEBUG + std::cout << std::endl; + std::cout << "point/ring distance tests" << std::endl; +#endif + typedef bg::model::ring ring_type; + typedef test_distance_of_geometries tester; -typedef bg::srs::spheroid stype; + std::string const ring = "POLYGON((10 10,0 20, 15 30, 20 15, 15 10, 10 10))"; -// Strategies for point-point distance - -typedef bg::strategy::distance::andoyer andoyer_pp; -typedef bg::strategy::distance::thomas thomas_pp; -typedef bg::strategy::distance::vincenty vincenty_pp; - -// Strategies for point-segment distance - -typedef bg::strategy::distance::geographic_cross_track - andoyer_ps; - -typedef bg::strategy::distance::geographic_cross_track - thomas_ps; - -typedef bg::strategy::distance::geographic_cross_track - vincenty_ps; - -// Strategies for point-box distance - -typedef bg::strategy::distance::geographic_cross_track_point_box - < - bg::strategy::andoyer, - stype, - double - > andoyer_pb; - -typedef bg::strategy::distance::geographic_cross_track_point_box - < - bg::strategy::thomas, - stype, - double - > thomas_pb; - -typedef bg::strategy::distance::geographic_cross_track_point_box - < - bg::strategy::vincenty, - stype, - double - > vincenty_pb; + tester::apply("pr1", "POINT(0 10)", ring, + ps_distance("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps), + strategy_ps, true, true, false); +} //=========================================================================== -template -inline bg::default_distance_result::type -pp_distance(std::string const& wkt1, - std::string const& wkt2, - Strategy const& strategy) +template +< + typename Point, + typename Strategy_pp, + typename Strategy_ps +> +void test_distance_multipoint_ring(Strategy_pp const& strategy_pp, + Strategy_ps const& strategy_ps) { - point_type p1, p2; - bg::read_wkt(wkt1, p1); - bg::read_wkt(wkt2, p2); - return bg::distance(p1, p2, strategy); + +#ifdef BOOST_GEOMETRY_TEST_DEBUG + std::cout << std::endl; + std::cout << "multipoint/ring distance tests" << std::endl; +#endif + typedef bg::model::ring ring_type; + typedef bg::model::multi_point multi_point_type; + typedef test_distance_of_geometries tester; + + std::string const ring = "POLYGON((10 10,0 20, 15 30, 20 15, 15 10, 10 10))"; + + tester::apply("pr1", "MULTIPOINT(0 10,10 0,0 0)", ring, + ps_distance("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps), + strategy_ps, true, true, false); } -template -inline bg::default_distance_result::type -ps_distance(std::string const& wkt1, - std::string const& wkt2, - Strategy const& strategy) + +//=========================================================================== + +template +< + typename Point, + typename Strategy_pp, + typename Strategy_ps +> +void test_distance_point_polygon(Strategy_pp const& strategy_pp, + Strategy_ps const& strategy_ps) { - point_type p; - segment_type s; - bg::read_wkt(wkt1, p); - bg::read_wkt(wkt2, s); - return bg::distance(p, s, strategy); + +#ifdef BOOST_GEOMETRY_TEST_DEBUG + std::cout << std::endl; + std::cout << "point/polygon distance tests" << std::endl; +#endif + typedef bg::model::polygon polygon_type; + typedef test_distance_of_geometries tester; + + std::string const polygon = "POLYGON((10 10,0 20, 15 30, 20 15, 15 10, 10 10))"; + + tester::apply("pr1", "POINT(0 10)", polygon, + ps_distance("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps), + strategy_ps, true, true, false); } +//=========================================================================== + +template +< + typename Point, + typename Strategy_pp, + typename Strategy_ps +> +void test_distance_multipoint_polygon(Strategy_pp const& strategy_pp, + Strategy_ps const& strategy_ps) +{ + +#ifdef BOOST_GEOMETRY_TEST_DEBUG + std::cout << std::endl; + std::cout << "multipoint/polygon distance tests" << std::endl; +#endif + typedef bg::model::polygon polygon_type; + typedef bg::model::multi_point multi_point_type; + typedef test_distance_of_geometries tester; + + std::string const polygon = "POLYGON((10 10,0 20, 15 30, 20 15, 15 10, 10 10))"; + + tester::apply("pr1", "MULTIPOINT(0 10,10 0,0 0)", polygon, + ps_distance("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps), + strategy_ps, true, true, false); +} + + +//=========================================================================== + +template +< + typename Point, + typename Strategy_pp, + typename Strategy_ps +> +void test_distance_point_multipolygon(Strategy_pp const& strategy_pp, + Strategy_ps const& strategy_ps) +{ + +#ifdef BOOST_GEOMETRY_TEST_DEBUG + std::cout << std::endl; + std::cout << "point/multipolygon distance tests" << std::endl; +#endif + typedef bg::model::polygon polygon_type; + typedef bg::model::multi_polygon multipolygon_type; + typedef test_distance_of_geometries tester; + + std::string const mpoly = "MULTIPOLYGON(((20 20, 20 30, 30 40, 20 20)),\ + ((10 10,0 20, 15 30, 20 15, 15 10, 10 10)))"; + + tester::apply("pr1", "POINT(0 10)", mpoly, + ps_distance("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps), + strategy_ps, true, true, false); +} + +//=========================================================================== + +template +< + typename Point, + typename Strategy_pp, + typename Strategy_ps +> +void test_distance_multipoint_multipolygon(Strategy_pp const& strategy_pp, + Strategy_ps const& strategy_ps) +{ + +#ifdef BOOST_GEOMETRY_TEST_DEBUG + std::cout << std::endl; + std::cout << "point/ring distance tests" << std::endl; +#endif + typedef bg::model::polygon polygon_type; + typedef bg::model::multi_polygon multipolygon_type; + typedef bg::model::multi_point multi_point_type; + typedef test_distance_of_geometries tester; + + std::string const mpoly = "MULTIPOLYGON(((20 20, 20 30, 30 40, 20 20)),\ + ((10 10,0 20, 15 30, 20 15, 15 10, 10 10)))"; + + tester::apply("pr1", "MULTIPOINT(0 10,10 0,0 0)", mpoly, + ps_distance("POINT(0 10)", "SEGMENT(0 20, 10 10)", strategy_ps), + strategy_ps, true, true, false); +} + + //=========================================================================== // Cases for relative location of a point wrt to a box // @@ -149,7 +236,13 @@ ps_distance(std::string const& wkt1, // range [-180, 540) //=========================================================================== -template +template +< + typename Point, + typename Strategy_pp, + typename Strategy_ps, + typename Strategy_pb +> void test_distance_point_box(Strategy_pp const& strategy_pp, Strategy_ps const& strategy_ps, Strategy_pb const& strategy_pb) @@ -159,93 +252,94 @@ void test_distance_point_box(Strategy_pp const& strategy_pp, std::cout << std::endl; std::cout << "point/box distance tests" << std::endl; #endif - typedef test_distance_of_geometries tester; + typedef bg::model::box box_type; + typedef test_distance_of_geometries tester; std::string const box1 = "BOX(10 10,20 20)"; // case 1 tester::apply("pb1-1a", "POINT(5 25)", box1, - pp_distance("POINT(5 25)", "POINT(10 20)", strategy_pp), + pp_distance("POINT(5 25)", "POINT(10 20)", strategy_pp), strategy_pb); // case 1 tester::apply("pb1-1b", "POINT(3 12)", box1, - ps_distance("POINT(3 12)", "SEGMENT(10 10,10 20)", strategy_ps), + ps_distance("POINT(3 12)", "SEGMENT(10 10,10 20)", strategy_ps), strategy_pb); // case 1 tester::apply("pb1-1c", "POINT(3 17)", box1, - ps_distance("POINT(3 17)", "SEGMENT(10 10,10 20)", strategy_ps), + ps_distance("POINT(3 17)", "SEGMENT(10 10,10 20)", strategy_ps), strategy_pb); // case 1 tester::apply("pb1-1d", "POINT(5 4)", box1, - pp_distance("POINT(5 4)", "POINT(10 10)", strategy_pp), + pp_distance("POINT(5 4)", "POINT(10 10)", strategy_pp), strategy_pb); // case 1 tester::apply("pb1-1e", "POINT(-100 20)", box1, - pp_distance("POINT(-100 20)", "POINT(10 20)", strategy_pp), + pp_distance("POINT(-100 20)", "POINT(10 20)", strategy_pp), strategy_pb); // case 1 tester::apply("pb1-1g", "POINT(-100 10)", box1, - ps_distance("POINT(-100 10)", "SEGMENT(10 10,10 20)", strategy_ps), + ps_distance("POINT(-100 10)", "SEGMENT(10 10,10 20)", strategy_ps), strategy_pb); // case 2 tester::apply("pb1-2a", "POINT(31 25)", box1, - pp_distance("POINT(31 25)", "POINT(20 20)", strategy_pp), + pp_distance("POINT(31 25)", "POINT(20 20)", strategy_pp), strategy_pb); // case 2 tester::apply("pb1-2b", "POINT(23 17)", box1, - ps_distance("POINT(23 17)", "SEGMENT(20 10,20 20)", strategy_ps), + ps_distance("POINT(23 17)", "SEGMENT(20 10,20 20)", strategy_ps), strategy_pb); // case 2 tester::apply("pb1-2c", "POINT(29 3)", box1, - pp_distance("POINT(29 3)", "POINT(20 10)", strategy_pp), + pp_distance("POINT(29 3)", "POINT(20 10)", strategy_pp), strategy_pb); // case 2 tester::apply("pb1-2d", "POINT(131 65)", box1, - pp_distance("POINT(131 65)", "POINT(20 20)", strategy_pp), + pp_distance("POINT(131 65)", "POINT(20 20)", strategy_pp), strategy_pb); // case 2 tester::apply("pb1-2e", "POINT(110 10)", box1, - ps_distance("POINT(110 10)", "SEGMENT(20 10,20 20)", strategy_ps), + ps_distance("POINT(110 10)", "SEGMENT(20 10,20 20)", strategy_ps), strategy_pb); // case 2 tester::apply("pb1-2f", "POINT(150 20)", box1, - pp_distance("POINT(150 20)", "POINT(20 20)", strategy_pp), + pp_distance("POINT(150 20)", "POINT(20 20)", strategy_pp), strategy_pb); // case 3 tester::apply("pb1-3a", "POINT(11 25)", box1, - pp_distance("POINT(11 25)", "POINT(11 20)", strategy_pp), + pp_distance("POINT(11 25)", "POINT(11 20)", strategy_pp), strategy_pb); // case 3 tester::apply("pb1-3b", "POINT(15 25)", box1, - pp_distance("POINT(15 25)", "POINT(15 20)", strategy_pp), + pp_distance("POINT(15 25)", "POINT(15 20)", strategy_pp), strategy_pb); // case 3 tester::apply("pb1-3c", "POINT(18 25)", box1, - pp_distance("POINT(18 25)", "POINT(18 20)", strategy_pp), + pp_distance("POINT(18 25)", "POINT(18 20)", strategy_pp), strategy_pb); // case 4 tester::apply("pb1-4a", "POINT(13 4)", box1, - pp_distance("POINT(13 4)", "POINT(13 10)", strategy_pp), + pp_distance("POINT(13 4)", "POINT(13 10)", strategy_pp), strategy_pb); // case 4 tester::apply("pb1-4b", "POINT(19 4)", box1, - pp_distance("POINT(19 4)", "POINT(19 10)", strategy_pp), + pp_distance("POINT(19 4)", "POINT(19 10)", strategy_pp), strategy_pb); // case 5 @@ -253,12 +347,12 @@ void test_distance_point_box(Strategy_pp const& strategy_pp, // case A tester::apply("pb1-A", "POINT(10 28)", box1, - pp_distance("POINT(10 28)", "POINT(10 20)", strategy_pp), + pp_distance("POINT(10 28)", "POINT(10 20)", strategy_pp), strategy_pb); // case B tester::apply("pb1-B", "POINT(20 28)", box1, - pp_distance("POINT(20 28)", "POINT(20 20)", strategy_pp), + pp_distance("POINT(20 28)", "POINT(20 20)", strategy_pp), strategy_pb); @@ -276,12 +370,12 @@ void test_distance_point_box(Strategy_pp const& strategy_pp, // case G tester::apply("pb1-G", "POINT(10 -40)", box1, - pp_distance("POINT(10 -40)", "POINT(10 10)", strategy_pp), + pp_distance("POINT(10 -40)", "POINT(10 10)", strategy_pp), strategy_pb); // case H tester::apply("pb1-H", "POINT(20 -50)", box1, - pp_distance("POINT(20 -50)", "POINT(20 10)", strategy_pp), + pp_distance("POINT(20 -50)", "POINT(20 10)", strategy_pp), strategy_pb); // case a @@ -298,22 +392,22 @@ void test_distance_point_box(Strategy_pp const& strategy_pp, // case 1 - point is closer to western meridian tester::apply("pb2-1a", "POINT(160 0)", box2, - ps_distance("POINT(160 0)", "SEGMENT(170 -60,170 80)", strategy_ps), + ps_distance("POINT(160 0)", "SEGMENT(170 -60,170 80)", strategy_ps), strategy_pb); // case 1 - point is closer to eastern meridian tester::apply("pb2-1b", "POINT(50 0)", box2, - ps_distance("POINT(50 0)", "SEGMENT(40 -60,40 80)", strategy_ps), + ps_distance("POINT(50 0)", "SEGMENT(40 -60,40 80)", strategy_ps), strategy_pb); // case 3 - equivalent point POINT(390 85) is above the box tester::apply("pb2-3", "POINT(30 85)", box2, - pp_distance("POINT(30 85)", "POINT(30 80)", strategy_pp), + pp_distance("POINT(30 85)", "POINT(30 80)", strategy_pp), strategy_pb); // case 4 - equivalent point POINT(390 -75) is below the box tester::apply("pb2-4", "POINT(30 -75)", box2, - pp_distance("POINT(30 -75)", "POINT(30 -60)", strategy_pp), + pp_distance("POINT(30 -75)", "POINT(30 -60)", strategy_pp), strategy_pb); // case 5 - equivalent point POINT(390 0) is inside box @@ -324,27 +418,27 @@ void test_distance_point_box(Strategy_pp const& strategy_pp, // case 1 - point is closer to western meridian tester::apply("pb3-1a", "POINT(-170 10)", box3, - ps_distance("POINT(-170 10)", "SEGMENT(-150 -50,-150 70)", strategy_ps), + ps_distance("POINT(-170 10)", "SEGMENT(-150 -50,-150 70)", strategy_ps), strategy_pb); // case 2 - point is closer to eastern meridian tester::apply("pb3-2a", "POINT(5 10)", box3, - ps_distance("POINT(5 10)", "SEGMENT(-40 -50,-40 70)", strategy_ps), + ps_distance("POINT(5 10)", "SEGMENT(-40 -50,-40 70)", strategy_ps), strategy_pb); // case 2 - point is closer to western meridian tester::apply("pb3-2a", "POINT(160 10)", box3, - ps_distance("POINT(160 10)", "SEGMENT(-150 -50,-150 70)", strategy_ps), + ps_distance("POINT(160 10)", "SEGMENT(-150 -50,-150 70)", strategy_ps), strategy_pb); // case 2 - point is at equal distance from eastern and western meridian tester::apply("pb3-2c1", "POINT(85 20)", box3, - ps_distance("POINT(85 20)", "SEGMENT(-150 -50,-150 70)", strategy_ps), + ps_distance("POINT(85 20)", "SEGMENT(-150 -50,-150 70)", strategy_ps), strategy_pb); // case 2 - point is at equal distance from eastern and western meridian tester::apply("pb3-2c2", "POINT(85 20)", box3, - ps_distance("POINT(85 20)", "SEGMENT(-40 -50,-40 70)", strategy_ps), + ps_distance("POINT(85 20)", "SEGMENT(-40 -50,-40 70)", strategy_ps), strategy_pb); // box that is symmetric wrt the prime meridian @@ -352,75 +446,69 @@ void test_distance_point_box(Strategy_pp const& strategy_pp, // case 1 - point is closer to western meridian tester::apply("pb4-1a", "POINT(-100 10)", box4, - ps_distance("POINT(-100 10)", "SEGMENT(-75 -45,-75 65)", strategy_ps), + ps_distance("POINT(-100 10)", "SEGMENT(-75 -45,-75 65)", strategy_ps), strategy_pb); // case 2 - point is closer to eastern meridian tester::apply("pb4-2a", "POINT(90 15)", box4, - ps_distance("POINT(90 15)", "SEGMENT(75 -45,75 65)", strategy_ps), + ps_distance("POINT(90 15)", "SEGMENT(75 -45,75 65)", strategy_ps), strategy_pb); // case 2 - point is at equal distance from eastern and western meridian tester::apply("pb4-2c1", "POINT(-180 20)", box4, - ps_distance("POINT(-180 20)", "SEGMENT(-75 -45,-75 65)", strategy_ps), + ps_distance("POINT(-180 20)", "SEGMENT(-75 -45,-75 65)", strategy_ps), strategy_pb); // case 2 - point is at equal distance from eastern and western meridian tester::apply("pb4-2c2", "POINT(-180 20)", box4, - ps_distance("POINT(-180 20)", "SEGMENT(75 -45,75 65)", strategy_ps), + ps_distance("POINT(-180 20)", "SEGMENT(75 -45,75 65)", strategy_ps), strategy_pb); -} -template -void test_distance_point_deg_box(Strategy_pp const& strategy_pp, - Strategy_ps const& strategy_ps, - Strategy_pb const& strategy_pb) -{ - -#ifdef BOOST_GEOMETRY_TEST_DEBUG - std::cout << std::endl; - std::cout << "point/box distance tests" << std::endl; -#endif - typedef test_distance_of_geometries tester; //box degenerates to a meridian segment - std::string const box1 = "BOX(0 10,0 20)"; + std::string const boxdeg1 = "BOX(0 10,0 20)"; - tester::apply("pbd1", "POINT(1 10)", box1, - ps_distance("POINT(1 10)", "SEGMENT(0 10, 0 20)", strategy_ps), + tester::apply("pbd1", "POINT(1 10)", boxdeg1, + ps_distance("POINT(1 10)", "SEGMENT(0 10, 0 20)", strategy_ps), strategy_pb); - tester::apply("pbd2", "POINT(1 5)", box1, - ps_distance("POINT(1 5)", "SEGMENT(0 10, 0 20)", strategy_ps), + tester::apply("pbd2", "POINT(1 5)", boxdeg1, + ps_distance("POINT(1 5)", "SEGMENT(0 10, 0 20)", strategy_ps), strategy_pb); - tester::apply("pbd3", "POINT(1 15)", box1, - ps_distance("POINT(1 15)", "SEGMENT(0 10, 0 20)", strategy_ps), + tester::apply("pbd3", "POINT(1 15)", boxdeg1, + ps_distance("POINT(1 15)", "SEGMENT(0 10, 0 20)", strategy_ps), strategy_pb); - tester::apply("pbd4", "POINT(1 25)", box1, - ps_distance("POINT(1 25)", "SEGMENT(0 10, 0 20)", strategy_ps), + tester::apply("pbd4", "POINT(1 25)", boxdeg1, + ps_distance("POINT(1 25)", "SEGMENT(0 10, 0 20)", strategy_ps), strategy_pb); //box degenerates to a horizontal line; that is not a geodesic segment - std::string const box2 = "BOX(10 10,20 10)"; + std::string const boxdeg2 = "BOX(10 10,20 10)"; - tester::apply("pbd5", "POINT(15 15)", box2, - pp_distance("POINT(15 15)", "POINT(15 10)", strategy_pp), + tester::apply("pbd5", "POINT(15 15)", boxdeg2, + pp_distance("POINT(15 15)", "POINT(15 10)", strategy_pp), strategy_pb); - tester::apply("pbd6", "POINT(5 15)", box2, - pp_distance("POINT(5 15)", "POINT(10 10)", strategy_pp), + tester::apply("pbd6", "POINT(5 15)", boxdeg2, + pp_distance("POINT(5 15)", "POINT(10 10)", strategy_pp), strategy_pb); - tester::apply("pbd7", "POINT(25 15)", box2, - pp_distance("POINT(25 15)", "POINT(20 10)", strategy_pp), + tester::apply("pbd7", "POINT(25 15)", boxdeg2, + pp_distance("POINT(25 15)", "POINT(20 10)", strategy_pp), strategy_pb); //box degenerates to a point - std::string const box3 = "BOX(0 10,0 10)"; + std::string const boxdeg3 = "BOX(0 10,0 10)"; - tester::apply("pbd8", "POINT(1 11)", box3, - pp_distance("POINT(1 11)", "POINT(0 10)", strategy_pp), + tester::apply("pbd8", "POINT(1 11)", boxdeg3, + pp_distance("POINT(1 11)", "POINT(0 10)", strategy_pp), strategy_pb); } -template +template +< + typename Point, + typename Strategy_pp, + typename Strategy_ps, + typename Strategy_pb +> void test_distance_multipoint_box(Strategy_pp const& strategy_pp, Strategy_ps const& strategy_ps, Strategy_pb const& strategy_pb) @@ -430,16 +518,18 @@ void test_distance_multipoint_box(Strategy_pp const& strategy_pp, std::cout << std::endl; std::cout << "multipoint/box distance tests" << std::endl; #endif + typedef bg::model::box box_type; + typedef bg::model::multi_point multi_point_type; typedef test_distance_of_geometries tester; std::string const box1 = "BOX(10 10,20 20)"; tester::apply("mpb1-1a", "MULTIPOINT(5 25,25 26)", box1, - pp_distance("POINT(5 25)", "POINT(10 20)", strategy_pp), + pp_distance("POINT(5 25)", "POINT(10 20)", strategy_pp), strategy_pb, true, false, false); tester::apply("mpb1-2e", "MULTIPOINT(110 10,110 9,110 0)", box1, - ps_distance("POINT(110 10)", "SEGMENT(20 10,20 20)", strategy_ps), + ps_distance("POINT(110 10)", "SEGMENT(20 10,20 20)", strategy_ps), strategy_pb, true, false, false); } @@ -447,17 +537,41 @@ void test_distance_multipoint_box(Strategy_pp const& strategy_pp, //=========================================================================== //=========================================================================== +template +< + typename Point, + typename Strategy_pp, + typename Strategy_ps, + typename Strategy_pb +> +void test_all_pl_ar(Strategy_pp pp_strategy, + Strategy_ps ps_strategy, + Strategy_pb pb_strategy) +{ + test_distance_point_ring(pp_strategy, ps_strategy); + test_distance_multipoint_ring(pp_strategy, ps_strategy); + + test_distance_point_polygon(pp_strategy, ps_strategy); + test_distance_multipoint_polygon(pp_strategy, ps_strategy); + + test_distance_point_multipolygon(pp_strategy, ps_strategy); + test_distance_multipoint_multipolygon(pp_strategy, ps_strategy); + + test_distance_point_box(pp_strategy, ps_strategy, pb_strategy); + test_distance_multipoint_box(pp_strategy, ps_strategy, pb_strategy); + + test_more_empty_input_pointlike_areal(ps_strategy); +} + BOOST_AUTO_TEST_CASE( test_all_pointlike_areal ) { - test_distance_point_box(vincenty_pp(), vincenty_ps(), vincenty_pb()); - test_distance_point_box(thomas_pp(), thomas_ps(), thomas_pb()); - test_distance_point_box(andoyer_pp(), andoyer_ps(), andoyer_pb()); + typedef bg::model::point > + sph_point; + test_all_pl_ar(spherical_pp(), spherical_ps(), spherical_pb()); - test_distance_point_deg_box(vincenty_pp(), vincenty_ps(), vincenty_pb()); - test_distance_point_deg_box(thomas_pp(), thomas_ps(), thomas_pb()); - test_distance_point_deg_box(andoyer_pp(), andoyer_ps(), andoyer_pb()); + typedef bg::model::point > geo_point; - test_distance_multipoint_box(vincenty_pp(), vincenty_ps(), vincenty_pb()); - test_distance_multipoint_box(thomas_pp(), thomas_ps(), thomas_pb()); - test_distance_multipoint_box(andoyer_pp(), andoyer_ps(), andoyer_pb()); + test_all_pl_ar(vincenty_pp(), vincenty_ps(), vincenty_pb()); + test_all_pl_ar(thomas_pp(), thomas_ps(), thomas_pb()); + test_all_pl_ar(andoyer_pp(), andoyer_ps(), andoyer_pb()); } diff --git a/test/algorithms/distance/test_distance_geo_common.hpp b/test/algorithms/distance/test_distance_geo_common.hpp index a60a5214b..72f50beaf 100644 --- a/test/algorithms/distance/test_distance_geo_common.hpp +++ b/test/algorithms/distance/test_distance_geo_common.hpp @@ -71,6 +71,34 @@ typedef bg::strategy::distance::geographic_cross_track vincenty_ps; +// Spherical strategy for point-box distance + +typedef bg::strategy::distance::cross_track_point_box<> spherical_pb; + +// Geo strategies for point-box distance + +typedef bg::strategy::distance::geographic_cross_track_point_box +< + bg::strategy::andoyer, + stype, + double +> andoyer_pb; + +typedef bg::strategy::distance::geographic_cross_track_point_box +< + bg::strategy::thomas, + stype, + double +> thomas_pb; + +typedef bg::strategy::distance::geographic_cross_track_point_box +< + bg::strategy::vincenty, + stype, + double +> vincenty_pb; + + //=========================================================================== template diff --git a/test/algorithms/distance/test_empty_geometry.hpp b/test/algorithms/distance/test_empty_geometry.hpp index 3e438739c..082ba7903 100644 --- a/test/algorithms/distance/test_empty_geometry.hpp +++ b/test/algorithms/distance/test_empty_geometry.hpp @@ -140,4 +140,39 @@ void test_more_empty_input_linear_areal(Strategy const& strategy) #endif } +template +void test_more_empty_input_pointlike_areal(Strategy const& strategy) +{ +#ifdef BOOST_GEOMETRY_TEST_DEBUG + std::cout << std::endl; + std::cout << "testing on empty inputs... " << std::flush; +#endif + bg::model::multi_point multipoint_empty; + + bg::model::polygon polygon_empty; + bg::model::multi_polygon > multipolygon_empty; + + Point point = from_wkt("POINT(0 0)"); + bg::model::polygon polygon = + from_wkt >("POLYGON((0 0,1 0,1 1,0 1,0 0))"); + + // 1st geometry is empty + test_empty_input(multipoint_empty, polygon, strategy); + test_empty_input(polygon_empty, point, strategy); + test_empty_input(multipolygon_empty, point, strategy); + + // 2nd geometry is empty + test_empty_input(point, polygon_empty, strategy); + test_empty_input(point, multipolygon_empty, strategy); + test_empty_input(polygon, multipoint_empty, strategy); + + // both geometries are empty + test_empty_input(multipoint_empty, polygon_empty, strategy); + test_empty_input(multipoint_empty, multipolygon_empty, strategy); + +#ifdef BOOST_GEOMETRY_TEST_DEBUG + std::cout << "done!" << std::endl; +#endif +} + #endif // BOOST_GEOMETRY_TEST_EMPTY_GEOMETRY_HPP