From 1e41a4d5163cb5eafbcb2e4f2f56e50290d4fa7f Mon Sep 17 00:00:00 2001 From: Vissarion Fysikopoulos Date: Mon, 2 Apr 2018 12:14:38 +0300 Subject: [PATCH] [strategies] [tests] Fix pt-seg distance cases for south hemisphere --- .../geographic/distance_cross_track.hpp | 27 ++++--- .../algorithms/distance/distance_geo_pl_l.cpp | 78 ++++++++++--------- .../distance/distance_geo_pl_pl.cpp | 4 +- .../distance/distance_geo_point_box.cpp | 4 +- .../distance/test_distance_geo_common.hpp | 22 ++++++ 5 files changed, 83 insertions(+), 52 deletions(-) diff --git a/include/boost/geometry/strategies/geographic/distance_cross_track.hpp b/include/boost/geometry/strategies/geographic/distance_cross_track.hpp index ba7dc3751..ff6eea211 100644 --- a/include/boost/geometry/strategies/geographic/distance_cross_track.hpp +++ b/include/boost/geometry/strategies/geographic/distance_cross_track.hpp @@ -173,21 +173,22 @@ private : if (g4 < -1.25*pi)//close to -270 { #ifdef BOOST_GEOMETRY_DEBUG_GEOGRAPHIC_CROSS_TRACK - std::cout << "g4=" << g4 << ", close to -270" << std::endl; + std::cout << "g4=" << g4 * math::r2d() << ", close to -270" << std::endl; #endif return g4 + 1.5 * pi; } else if (g4 > 1.25*pi)//close to 270 { #ifdef BOOST_GEOMETRY_DEBUG_GEOGRAPHIC_CROSS_TRACK - std::cout << "g4=" << g4 << ", close to 270" << std::endl; + std::cout << "g4=" << g4 * math::r2d() << ", close to 270" << std::endl; #endif + der = -der; return - g4 + 1.5 * pi; } else if (g4 < 0 && g4 > -0.75*pi)//close to -90 { #ifdef BOOST_GEOMETRY_DEBUG_GEOGRAPHIC_CROSS_TRACK - std::cout << "g4=" << g4 << ", close to -90" << std::endl; + std::cout << "g4=" << g4 * math::r2d() << ", close to -90" << std::endl; #endif der = -der; return -g4 - pi/2; @@ -236,7 +237,7 @@ private : } #ifdef BOOST_GEOMETRY_DEBUG_GEOGRAPHIC_CROSS_TRACK - std::cout << "Segment=(" << lon1 * math::r2d(); + std::cout << ">>\nSegment=(" << lon1 * math::r2d(); std::cout << "," << lat1 * math::r2d(); std::cout << "),(" << lon2 * math::r2d(); std::cout << "," << lat2 * math::r2d(); @@ -280,8 +281,11 @@ private : return non_iterative_case(lon3, lat1, lon3, lat3, spheroid); } - if ( (meridian_not_crossing_pole || meridian_crossing_pole ) && lat1 > lat2) + if ( (meridian_not_crossing_pole || meridian_crossing_pole ) && std::abs(lat1) > std::abs(lat2)) { +#ifdef BOOST_GEOMETRY_DEBUG_GEOGRAPHIC_CROSS_TRACK + std::cout << "Meridian segment not crossing pole" << std::endl; +#endif std::swap(lat1,lat2); } @@ -290,8 +294,9 @@ private : #ifdef BOOST_GEOMETRY_DEBUG_GEOGRAPHIC_CROSS_TRACK std::cout << "Meridian segment crossing pole" << std::endl; #endif - result_distance_point_segment d1 = apply(lon1, lat1, lon1, half_pi, lon3, lat3, spheroid); - result_distance_point_segment d2 = apply(lon2, lat2, lon2, half_pi, lon3, lat3, spheroid); + CT sign_non_zero = lat3 >= c0 ? 1 : -1; + result_distance_point_segment d1 = apply(lon1, lat1, lon1, half_pi * sign_non_zero, lon3, lat3, spheroid); + result_distance_point_segment d2 = apply(lon2, lat2, lon2, half_pi * sign_non_zero, lon3, lat3, spheroid); if (d1.distance < d2.distance) { return d1; @@ -433,13 +438,11 @@ private : lon3, lat3, spheroid); g4 = res34.azimuth - a4; - - CT M43 = res34.geodesic_scale; // cos(s14/earth_radius) is the spherical limit CT m34 = res34.reduced_length; CT der = (M43 / m34) * sin(g4); - // normalize (g4 - pi/2) + //normalize (g4 - pi/2) delta_g4 = normalize(g4, der); s14 = s14 - delta_g4 / der; @@ -449,7 +452,7 @@ private : "," << res14.lat2 * math::r2d() << std::endl; std::cout << "a34=" << res34.azimuth * math::r2d() << std::endl; std::cout << "a4=" << a4 * math::r2d() << std::endl; - std::cout << "g4=" << g4 * math::r2d() << std::endl; + std::cout << "g4(normalized)=" << g4 * math::r2d() << std::endl; std::cout << "delta_g4=" << delta_g4 * math::r2d() << std::endl; std::cout << "der=" << der << std::endl; std::cout << "M43=" << M43 << std::endl; @@ -474,7 +477,7 @@ private : { std::cout << "Stop msg: delta_g4 == 0" << std::endl; } - if (counter == 19) + if (counter == BOOST_GEOMETRY_DETAIL_POINT_SEGMENT_DISTANCE_MAX_STEPS) { std::cout << "Stop msg: counter" << std::endl; } diff --git a/test/algorithms/distance/distance_geo_pl_l.cpp b/test/algorithms/distance/distance_geo_pl_l.cpp index f2d7d446b..8a5e3a70b 100644 --- a/test/algorithms/distance/distance_geo_pl_l.cpp +++ b/test/algorithms/distance/distance_geo_pl_l.cpp @@ -8,6 +8,9 @@ // Licensed under the Boost Software License version 1.0. // http://www.boost.org/users/license.html +#define BOOST_GEOMETRY_TEST_DEBUG +//#define BOOST_GEOMETRY_DEBUG_GEOGRAPHIC_CROSS_TRACK + #ifndef BOOST_TEST_MODULE #define BOOST_TEST_MODULE test_distance_geographic_pl_l #endif @@ -240,7 +243,7 @@ void test_distance_point_segment(Strategy_pp const& strategy_pp, tester::apply("p-s-mer1", "POINT(2.5 2)", "SEGMENT(2 2,2 4)", - pp_distance("POINT(2.5 2)", "POINT(2 2)", strategy_pp), + pp_distance("POINT(2.5 2)", "POINT(2 2.000076608014728)", strategy_pp), strategy_ps, true, true); tester::apply("p-s-mer3", "POINT(2.5 5)", @@ -338,7 +341,6 @@ void test_distance_point_segment(Strategy_pp const& strategy_pp, "SEGMENT(0 0,180 0)", 0, strategy_ps, true, true); - } template @@ -380,7 +382,7 @@ void test_distance_point_segment_no_thomas(Strategy_pp const& strategy_pp, pp_distance("POINT(80 89)", "POINT(0 89.82633489283377)", strategy_pp), strategy_ps, true, true); - tester::apply("p-s-20", + tester::apply("p-s-21", "POINT(80 89)", "SEGMENT(0 -1,180 1)", pp_distance("POINT(80 89)", "POINT(0 89.82633489283377)", strategy_pp), @@ -403,42 +405,42 @@ void test_distance_point_linestring(Strategy_pp const& strategy_pp, "POINT(0 0)", "LINESTRING(2 0,2 0)", pp_distance("POINT(0 0)", "POINT(2 0)", strategy_pp), - strategy_ps); + strategy_ps, true, false, false); tester::apply("p-l-02", "POINT(0 0)", "LINESTRING(2 0,3 0)", pp_distance("POINT(0 0)", "POINT(2 0)", strategy_pp), - strategy_ps); + strategy_ps, true, false, false); tester::apply("p-l-03", "POINT(2.5 3)", "LINESTRING(2 0,3 0)", pp_distance("POINT(2.5 3)", "POINT(2.5 0)", strategy_pp), - strategy_ps); + strategy_ps, true, false, false); tester::apply("p-l-04", "POINT(2 0)", "LINESTRING(2 0,3 0)", 0, - strategy_ps); + strategy_ps, true, false, false); tester::apply("p-l-05", "POINT(3 0)", "LINESTRING(2 0,3 0)", 0, - strategy_ps); + strategy_ps, true, false, false); tester::apply("p-l-06", "POINT(2.5 0)", "LINESTRING(2 0,3 0)", 0, - strategy_ps); + strategy_ps, true, false, false); tester::apply("p-l-07", "POINT(7.5 10)", "LINESTRING(1 0,2 0,3 0,4 0,5 0,6 0,7 0,8 0,9 0)", ps_distance("POINT(7.5 10)", "SEGMENT(7 0,8 0)", strategy_ps), - strategy_ps); + strategy_ps, true, false, false); tester::apply("p-l-08", "POINT(7.5 10)", "LINESTRING(1 1,2 1,3 1,4 1,5 1,6 1,7 1,20 2,21 2)", ps_distance("POINT(7.5 10)", "SEGMENT(7 1,20 2)", strategy_ps), - strategy_ps); + strategy_ps, true, false, false); } void test_distance_point_linestring_strategies() @@ -449,19 +451,22 @@ void test_distance_point_linestring_strategies() "POINT(2.5 3)", "LINESTRING(2 1,3 1)", 221147.24332788656, - vincenty_strategy()); + vincenty_strategy(), + true, false, false); tester::apply("p-l-03", "POINT(2.5 3)", "LINESTRING(2 1,3 1)", 221147.36682199029, - thomas_strategy()); + thomas_strategy(), + true, false, false); tester::apply("p-l-03", "POINT(2.5 3)", "LINESTRING(2 1,3 1)", 221144.76527049288, - andoyer_strategy()); + andoyer_strategy(), + true, false, false); } //=========================================================================== @@ -483,37 +488,37 @@ void test_distance_point_multilinestring(Strategy_pp const& strategy_pp, "POINT(0 0)", "MULTILINESTRING((-5 0,-3 0),(2 0,3 0))", pp_distance("POINT(0 0)", "POINT(2 0)", strategy_pp), - strategy_ps); + strategy_ps, true, false, false); tester::apply("p-ml-02", "POINT(2.5 3)", "MULTILINESTRING((-5 0,-3 0),(2 0,3 0))", pp_distance("POINT(2.5 3)", "POINT(2.5 0)", strategy_pp), - strategy_ps); + strategy_ps, true, false, false); tester::apply("p-ml-03", "POINT(2 0)", "MULTILINESTRING((-5 0,-3 0),(2 0,3 0))", 0, - strategy_ps); + strategy_ps, true, false, false); tester::apply("p-ml-04", "POINT(3 0)", "MULTILINESTRING((-5 0,-3 0),(2 0,3 0))", 0, - strategy_ps); + strategy_ps, true, false, false); tester::apply("p-ml-05", "POINT(2.5 0)", "MULTILINESTRING((-5 0,-3 0),(2 0,3 0))", 0, - strategy_ps); + strategy_ps, true, false, false); tester::apply("p-ml-06", "POINT(7.5 10)", "MULTILINESTRING((-5 0,-3 0),(2 0,3 0,4 0,5 0,6 0,20 1,21 1))", ps_distance("POINT(7.5 10)", "SEGMENT(6 0,20 1)", strategy_ps), - strategy_ps); + strategy_ps, true, false, false); tester::apply("p-ml-07", "POINT(-8 10)", "MULTILINESTRING((-20 10,-19 11,-18 10,-6 0,-5 0,-3 0),(2 0,6 0,20 1,21 1))", ps_distance("POINT(-8 10)", "SEGMENT(-6 0,-18 10)", strategy_ps), - strategy_ps); + strategy_ps, true, false, false); } //=========================================================================== @@ -535,28 +540,27 @@ void test_distance_linestring_multipoint(Strategy_pp const& strategy_pp, "LINESTRING(2 0,0 2,100 80)", "MULTIPOINT(0 0,1 0,0 1,1 1)", ps_distance("POINT(1 1)", "SEGMENT(2 0,0 2)", strategy_ps), - strategy_ps); - + strategy_ps, true, false, false); tester::apply("l-mp-02", "LINESTRING(4 0,0 4,100 80)", "MULTIPOINT(0 0,1 0,0 1,1 1)", ps_distance("POINT(1 1)", "SEGMENT(0 4,4 0)", strategy_ps), - strategy_ps); + strategy_ps, true, false, false); tester::apply("l-mp-03", "LINESTRING(1 1,2 2,100 80)", "MULTIPOINT(0 0,1 0,0 1,1 1)", 0, - strategy_ps); + strategy_ps, true, false, false); tester::apply("l-mp-04", "LINESTRING(3 3,4 4,100 80)", "MULTIPOINT(0 0,1 0,0 1,1 1)", pp_distance("POINT(1 1)", "POINT(3 3)", strategy_pp), - strategy_ps); + strategy_ps, true, false, false); tester::apply("l-mp-05", "LINESTRING(0 0,10 0,10 10,0 10,0 0)", "MULTIPOINT(1 -1,80 80,5 0,150 90)", 0, - strategy_ps); + strategy_ps, true, false, false); } //=========================================================================== @@ -577,22 +581,22 @@ void test_distance_multipoint_multilinestring(Strategy_pp const& strategy_pp, "MULTIPOINT(0 0,1 0,0 1,1 1)", "MULTILINESTRING((2 0,0 2),(2 2,3 3))", ps_distance("POINT(1 1)", "SEGMENT(2 0,0 2)", strategy_ps), - strategy_ps); + strategy_ps, true, false, false); tester::apply("mp-ml-02", "MULTIPOINT(0 0,1 0,0 1,1 1)", "MULTILINESTRING((3 0,0 3),(4 4,5 5))", ps_distance("POINT(1 1)", "SEGMENT(3 0,0 3)", strategy_ps), - strategy_ps); + strategy_ps, true, false, false); tester::apply("mp-ml-03", "MULTIPOINT(0 0,1 0,0 1,1 1)", "MULTILINESTRING((4 4,5 5),(1 1,2 2))", 0, - strategy_ps); + strategy_ps, true, false, false); tester::apply("mp-ml-04", "MULTIPOINT(0 0,1 0,0 1,1 1)", "MULTILINESTRING((4 4,3 3),(4 4,5 5))", pp_distance("POINT(1 1)", "POINT(3 3)", strategy_pp), - strategy_ps); + strategy_ps, true, false, false); } //=========================================================================== @@ -611,27 +615,27 @@ void test_distance_multipoint_segment(Strategy_pp const& strategy_pp, "MULTIPOINT(0 0,1 0,0 1,1 1)", "SEGMENT(2 0,0 2)", ps_distance("POINT(1 1)", "SEGMENT(2 0,0 2)", strategy_ps), - strategy_ps); + strategy_ps, true, false, false); tester::apply("mp-s-02", "MULTIPOINT(0 0,1 0,0 1,1 1)", "SEGMENT(0 -3,1 -10)", pp_distance("POINT(0 0)", "POINT(0 -3)", strategy_pp), - strategy_ps); + strategy_ps, true, false, false); tester::apply("mp-s-03", "MULTIPOINT(0 0,1 0,0 1,1 1)", "SEGMENT(1 1,2 2)", 0, - strategy_ps); + strategy_ps, true, false, false); tester::apply("mp-s-04", "MULTIPOINT(0 0,1 0,0 1,1 1)", "SEGMENT(3 3,4 4)", pp_distance("POINT(1 1)", "POINT(3 3)", strategy_pp), - strategy_ps); + strategy_ps, true, false, false); tester::apply("mp-s-05", "MULTIPOINT(0 0,1 0,0 1,1 1)", "SEGMENT(0.5 -3,1 -10)", pp_distance("POINT(1 0)", "POINT(0.5 -3)", strategy_pp), - strategy_ps); + strategy_ps, true, false, false); } //=========================================================================== @@ -677,6 +681,7 @@ BOOST_AUTO_TEST_CASE( test_all_point_segment ) test_distance_point_segment(thomas_pp(), thomas_strategy()); test_distance_point_segment(andoyer_pp(), andoyer_strategy()); + test_distance_point_segment_no_thomas(vincenty_pp(), vincenty_strategy()); ///test_distance_point_segment_no_thomas(thomas_pp(), thomas_strategy()); test_distance_point_segment_no_thomas(andoyer_pp(), andoyer_strategy()); @@ -705,4 +710,5 @@ BOOST_AUTO_TEST_CASE( test_all_point_segment ) test_empty_input_pointlike_linear(vincenty_strategy()); test_empty_input_pointlike_linear(thomas_strategy()); test_empty_input_pointlike_linear(andoyer_strategy()); + } diff --git a/test/algorithms/distance/distance_geo_pl_pl.cpp b/test/algorithms/distance/distance_geo_pl_pl.cpp index a5a2acbae..60c03de14 100644 --- a/test/algorithms/distance/distance_geo_pl_pl.cpp +++ b/test/algorithms/distance/distance_geo_pl_pl.cpp @@ -62,13 +62,13 @@ void test_distance_multipoint_point(Strategy const& strategy) "MULTIPOINT(1 1,1 2,2 3)", "POINT(0 0)", pp_distance("POINT(0 0)","POINT(1 1)",strategy), - strategy); + strategy, true, false, false); tester::apply("mp-p-01", "MULTIPOINT(0 0,0 2,2 0,2 2)", "POINT(1.1 1.1)", pp_distance("POINT(1.1 1.1)","POINT(2 2)",strategy), - strategy); + strategy, true, false, false); } //=========================================================================== diff --git a/test/algorithms/distance/distance_geo_point_box.cpp b/test/algorithms/distance/distance_geo_point_box.cpp index c72361a66..744acfed6 100644 --- a/test/algorithms/distance/distance_geo_point_box.cpp +++ b/test/algorithms/distance/distance_geo_point_box.cpp @@ -436,11 +436,11 @@ void test_distance_multipoint_box(Strategy_pp const& strategy_pp, tester::apply("mpb1-1a", "MULTIPOINT(5 25,25 26)", box1, pp_distance("POINT(5 25)", "POINT(10 20)", strategy_pp), - strategy_pb); + 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), - strategy_pb); + strategy_pb, true, false, false); } //=========================================================================== diff --git a/test/algorithms/distance/test_distance_geo_common.hpp b/test/algorithms/distance/test_distance_geo_common.hpp index 412ac2a5d..62c5fb433 100644 --- a/test/algorithms/distance/test_distance_geo_common.hpp +++ b/test/algorithms/distance/test_distance_geo_common.hpp @@ -116,6 +116,28 @@ template <> struct dispatch } }; + +// Specialization for points +template <> struct dispatch +{ + template + static inline T swap(T const& t) + { + return t; + } + + template + static inline Point mirror(Point const& p) + { + Point p_mirror; + + bg::set<0>(p_mirror, bg::get<0>(p)); + bg::set<1>(p_mirror, bg::get<1>(p) * -1); + + return p_mirror; + } +}; + //========================================================================