From aa2162f56b2dd5cc51a2c49eac6dfeee3bc6e2ed Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Wed, 20 Nov 2024 16:48:25 +0100 Subject: [PATCH] fix: add condition to handle_imperfect_touch Fixes #1345 --- .../detail/overlay/get_turn_info.hpp | 11 +++- .../detail/overlay/get_turn_info_helpers.hpp | 13 ++--- test/algorithms/overlay/overlay_cases.hpp | 53 +++++++++++++++++++ .../set_operations/difference/difference.cpp | 3 ++ .../intersection/intersection.cpp | 3 ++ .../algorithms/set_operations/union/union.cpp | 6 +++ 6 files changed, 82 insertions(+), 7 deletions(-) diff --git a/include/boost/geometry/algorithms/detail/overlay/get_turn_info.hpp b/include/boost/geometry/algorithms/detail/overlay/get_turn_info.hpp index 8a85d37302..bc63357b3b 100644 --- a/include/boost/geometry/algorithms/detail/overlay/get_turn_info.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/get_turn_info.hpp @@ -569,7 +569,7 @@ struct touch : public base_turn_handler // || // |^---- // >----->P - // * * they touch here (P/Q are (nearly) on top) + // * * they touch here (P/Q are (nearly) on top of each other) // // Q continues from where P comes. // P continues from where Q comes @@ -586,6 +586,14 @@ struct touch : public base_turn_handler // >----->P qj is LEFT of P1 and pi is LEFT of Q2 // (the other way round is also possible) + // There are also cases like this: + // P + // ^ + // || + // || + // P----^----- bool { auto const d1 = get_distance_measure(r1.at(0), r1.at(1), r2.at(1), umbrella_strategy); @@ -674,6 +682,7 @@ struct touch : public base_turn_handler { if (side_qk_p1 == 0 && side_pk_q1 == 0 && has_pk && has_qk + && opposite(side.pi_wrt_q1(), side.qk_wrt_p2()) && handle_imperfect_touch(range_p, range_q, side_pk_q2, umbrella_strategy, ti)) { // If q continues collinearly (opposite) with p, it should be blocked diff --git a/include/boost/geometry/algorithms/detail/overlay/get_turn_info_helpers.hpp b/include/boost/geometry/algorithms/detail/overlay/get_turn_info_helpers.hpp index 97be7a1a23..3b3c03ae67 100644 --- a/include/boost/geometry/algorithms/detail/overlay/get_turn_info_helpers.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/get_turn_info_helpers.hpp @@ -58,6 +58,13 @@ struct side_calculator , m_range_q(range_q) {} + inline int pi_wrt_q1() const { return m_side_strategy.apply(get_qi(), get_qj(), get_pi()); } + + inline int pj_wrt_q1() const { return m_side_strategy.apply(get_qi(), get_qj(), get_pj()); } + inline int pj_wrt_q2() const { return m_side_strategy.apply(get_qj(), get_qk(), get_pj()); } + inline int qj_wrt_p1() const { return m_side_strategy.apply(get_pi(), get_pj(), get_qj()); } + inline int qj_wrt_p2() const { return m_side_strategy.apply(get_pj(), get_pk(), get_qj()); } + inline int pk_wrt_p1() const { return m_side_strategy.apply(get_pi(), get_pj(), get_pk()); } inline int pk_wrt_q1() const { return m_side_strategy.apply(get_qi(), get_qj(), get_pk()); } inline int qk_wrt_p1() const { return m_side_strategy.apply(get_pi(), get_pj(), get_qk()); } @@ -66,12 +73,6 @@ struct side_calculator inline int pk_wrt_q2() const { return m_side_strategy.apply(get_qj(), get_qk(), get_pk()); } inline int qk_wrt_p2() const { return m_side_strategy.apply(get_pj(), get_pk(), get_qk()); } - // Necessary when rescaling turns off: - inline int qj_wrt_p1() const { return m_side_strategy.apply(get_pi(), get_pj(), get_qj()); } - inline int qj_wrt_p2() const { return m_side_strategy.apply(get_pj(), get_pk(), get_qj()); } - inline int pj_wrt_q1() const { return m_side_strategy.apply(get_qi(), get_qj(), get_pj()); } - inline int pj_wrt_q2() const { return m_side_strategy.apply(get_qj(), get_qk(), get_pj()); } - inline auto const& get_pi() const { return m_range_p.at(0); } inline auto const& get_pj() const { return m_range_p.at(1); } inline auto const& get_pk() const { return m_range_p.at(2); } diff --git a/test/algorithms/overlay/overlay_cases.hpp b/test/algorithms/overlay/overlay_cases.hpp index 3fcabd6c03..6b54807313 100644 --- a/test/algorithms/overlay/overlay_cases.hpp +++ b/test/algorithms/overlay/overlay_cases.hpp @@ -1231,6 +1231,59 @@ static std::string issue_1342_b[2] = "POLYGON((2.000000861538488 2.944711629068049e-16,2.000000861538488 2.0000008,23.52786548447633 2.0000008,23.52786548447633 2.944711629068049e-16,2.000000861538488 2.944711629068049e-16))" }; +static std::string issue_1345_a[2] = +{ + // Needs check for opposite in handle_imperfect_touch + R""""( + POLYGON(( + -2.0785311235613415 -0.6304193410175202, + -2.0534946127981359 -0.6304193410175202, + -2.0534946127981359 -0.8867932112327471, + -2.3098684830133629 -0.8867932112327471, + -2.3098684830133629 -0.6554558517807265, + -2.2848319722501573 -0.6554558517807265, + -2.0785311235613415 -0.6554558517807265, + -2.0785311235613415 -0.6304193410175202 + )) + )"""", + R""""( + POLYGON(( + -2.0785311235613420 -0.6304193410175202, + -2.0534946127981359 -0.6304193410175202, + -2.0534946127981359 -0.6554558517807265, + -2.0785311235613420 -0.6554558517807265, + -2.0785311235613420 -0.6304193410175202 + )) + )"""" +}; + +static std::string issue_1345_b[2] = +{ + // Needs check for opposite in handle_imperfect_touch + R""""( + POLYGON(( + -6.1723606999999996 3.2834021000000000, + -6.1723606999999996 2.8006724999999992, + -5.7133718999999994 2.8006724999999992, + -5.7133718999999994 3.2834021000000000, + -5.6896310999999997 3.2834021000000000, + -5.6896310999999997 2.7769316999999996, + -6.1961014999999993 2.7769316999999996, + -6.1961014999999993 3.2834021000000000, + -6.1723606999999996 3.2834021000000000 + )) + )"""", + R""""( + POLYGON(( + -6.1723606999999996 2.8006724999999997, + -5.7133718999999994 2.8006724999999997, + -5.7133718999999994 2.7769316999999996, + -6.1723606999999996 2.7769316999999996, + -6.1723606999999996 2.8006724999999997 + )) + )"""" +}; + static std::string ggl_list_20120229_volker[3] = { "POLYGON((1716 1554,2076 2250,2436 2352,2796 1248,3156 2484,3516 2688,3516 2688,3156 2484,2796 1248,2436 2352,2076 2250, 1716 1554))", diff --git a/test/algorithms/set_operations/difference/difference.cpp b/test/algorithms/set_operations/difference/difference.cpp index b2c2dc6ea7..d6112f9118 100644 --- a/test/algorithms/set_operations/difference/difference.cpp +++ b/test/algorithms/set_operations/difference/difference.cpp @@ -647,6 +647,9 @@ void test_all() TEST_DIFFERENCE(issue_1342_a, 2, 5.762381026454777, 0, 0.0, 2); TEST_DIFFERENCE(issue_1342_b, 2, 5.762381026454777, 1, 2.55e-14, 3); + TEST_DIFFERENCE(issue_1345_a, 1, 0.059308854, 0, 0.0, 1); + TEST_DIFFERENCE(issue_1345_b, 2, 0.024048025, 0, 0.0, 2); + TEST_DIFFERENCE(mysql_21977775, 2, 160.856568913, 2, 92.3565689126, 4); TEST_DIFFERENCE(mysql_21965285, 1, 92.0, 1, 14.0, 1); TEST_DIFFERENCE(mysql_23023665_1, 1, 92.0, 1, 142.5, 2); diff --git a/test/algorithms/set_operations/intersection/intersection.cpp b/test/algorithms/set_operations/intersection/intersection.cpp index fe926a6462..2ce4956a86 100644 --- a/test/algorithms/set_operations/intersection/intersection.cpp +++ b/test/algorithms/set_operations/intersection/intersection.cpp @@ -315,6 +315,9 @@ void test_areal() TEST_INTERSECTION(issue_1342_a, 1, -1, 43.05575); TEST_INTERSECTION(issue_1342_b, 1, -1, 43.05575); + TEST_INTERSECTION(issue_1345_a, 1, -1, 0.00062682687); + TEST_INTERSECTION(issue_1345_b, 1, -1, 0.010896761); + test_one("buffer_mp1", buffer_mp1[0], buffer_mp1[1], 1, 31, 2.271707796); test_one("buffer_mp2", buffer_mp2[0], buffer_mp2[1], diff --git a/test/algorithms/set_operations/union/union.cpp b/test/algorithms/set_operations/union/union.cpp index 0473c5cfa2..2824016d2b 100644 --- a/test/algorithms/set_operations/union/union.cpp +++ b/test/algorithms/set_operations/union/union.cpp @@ -493,6 +493,12 @@ void test_areal() TEST_UNION(issue_1342_b, 1, 0, -1, 48.81812749462214); TEST_UNION_REV(issue_1342_b, 1, 0, -1, 48.81812749462214); + TEST_UNION(issue_1345_a, 1, 0, -1, 0.059935681); + TEST_UNION_REV(issue_1345_a, 1, 0, -1, 0.059935681); + + TEST_UNION(issue_1345_b, 1, 0, -1, 0.034944786); + TEST_UNION_REV(issue_1345_b, 1, 0, -1, 0.034944786); + TEST_UNION(geos_1, 1, 0, -1, expectation_limits(3458.0, 3461.3203125)); TEST_UNION(geos_2, 1, 0, -1, expectation_limits(349.0625, 350.55102539)); TEST_UNION(geos_3, 1, 0, -1, 29391548.4998779);