From eb879fe6215caf0eac14b8c7f5b9a830cc0ad0f8 Mon Sep 17 00:00:00 2001 From: Barend Gehrels Date: Wed, 30 Aug 2023 17:46:27 +0200 Subject: [PATCH] [fix] avoid current get_distance_measure which can make sides indistinguishable --- .../detail/overlay/get_turn_info.hpp | 25 ++++------- test/algorithms/overlay/overlay_cases.hpp | 45 +++++++++++++++++++ .../algorithms/set_operations/union/union.cpp | 3 ++ 3 files changed, 56 insertions(+), 17 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 d8d173db03..ee2b3f5351 100644 --- a/include/boost/geometry/algorithms/detail/overlay/get_turn_info.hpp +++ b/include/boost/geometry/algorithms/detail/overlay/get_turn_info.hpp @@ -1,6 +1,6 @@ -// Boost.Geometry (aka GGL, Generic Geometry Library) +// Boost.Geometry -// Copyright (c) 2007-2021 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2007-2023 Barend Gehrels, Amsterdam, the Netherlands. // Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland. // This file was modified by Oracle on 2015-2022. @@ -852,24 +852,15 @@ struct equal : public base_turn_handler int const side_pk_p = has_pk ? side.pk_wrt_p1() : 0; int const side_qk_p = has_qk ? side.qk_wrt_p1() : 0; - if (BOOST_GEOMETRY_CONDITION(VerifyPolicy::use_side_verification) - && has_pk && has_qk && side_pk_p == side_qk_p) + if (has_pk && has_qk && side_pk_p == side_qk_p) { // They turn to the same side, or continue both collinearly - // Without rescaling, to check for union/intersection, - // try to check side values (without any thresholds) - auto const dm_pk_q2 - = get_distance_measure(range_q.at(1), range_q.at(2), range_p.at(2), - umbrella_strategy); - auto const dm_qk_p2 - = get_distance_measure(range_p.at(1), range_p.at(2), range_q.at(2), - umbrella_strategy); - - if (dm_qk_p2.measure != dm_pk_q2.measure) + // To check for union/intersection, try to check side values + int const side_qk_p2 = side.qk_wrt_p2(); + + if (opposite(side_qk_p2, side_pk_q2)) { - // A (possibly very small) difference is detected, which - // can be used to distinguish between union/intersection - ui_else_iu(dm_qk_p2.measure < dm_pk_q2.measure, ti); + ui_else_iu(side_pk_q2 == 1, ti); return; } } diff --git a/test/algorithms/overlay/overlay_cases.hpp b/test/algorithms/overlay/overlay_cases.hpp index 4bf5cf15f5..4d654eb0c0 100644 --- a/test/algorithms/overlay/overlay_cases.hpp +++ b/test/algorithms/overlay/overlay_cases.hpp @@ -1113,6 +1113,51 @@ static std::string issue_1108[2] = "POLYGON((22 1,22 0,14 0,18 -1.2696790939262529996,12 0,22 1))" }; +static std::string issue_1183[2] = +{ + "POLYGON((\ +-38880.685990792437 6721344.0451435195,\ +-38902.349206128216 6721371.1493254723,\ +-38937.993505971914 6721407.9151819283,\ +-38925.264019448201 6721389.3887558663,\ +-38925.240186032526 6721389.3524003429,\ +-38903.891993208345 6721355.1907963008,\ +-38909.181455691403 6721352.2237809654,\ +-38926.953387540903 6721388.3157829558,\ +-38940.906008282145 6721408.6223519640,\ +-38961.796165266409 6721432.5740491701,\ +-38961.819650679929 6721432.6019898951,\ +-38977.627018370375 6721452.1204930553,\ +-38977.724235665897 6721452.2645238554,\ +-38997.157657657241 6721487.2743892670,\ +-38997.156729985494 6721487.2749042027,\ +-38997.205159411656 6721487.3621566473,\ +-38995.456469315024 6721488.3327662209,\ +-38976.018586129794 6721453.3126770724,\ +-38959.181300235970 6721432.6429256191,\ +-38900.879954713615 6721372.5071140006,\ +-38900.816775977277 6721372.4353842726,\ +-38879.096795985606 6721345.2601805655,\ +-38879.046005852288 6721345.1907021403,\ +-38880.685990792437 6721344.0451435195,\ +))", + "POLYGON((\ +-38880.685990792437 6721344.0451435195,\ +-38902.349206128216 6721371.1493254723,\ +-38960.647313876834 6721431.2817974398,\ +-38960.704662809898 6721431.3463021647,\ +-38977.625225408119 6721452.1182855805,\ +-38977.724248525541 6721452.2645470239,\ +-38997.205159411656 6721487.3621566473,\ +-38995.456469315024 6721488.3327662209,\ +-38976.018586130762 6721453.3126770733,\ +-38959.181300235970 6721432.6429256191,\ +-38900.879954713615 6721372.5071140006,\ +-38879.046005852288 6721345.1907021403,\ +-38880.685990792437 6721344.0451435195,\ +))" +}; + static std::string issue_1184[2] = { "POLYGON((1169 177,2004 177,2004 1977,1262 1977,1169 177))", diff --git a/test/algorithms/set_operations/union/union.cpp b/test/algorithms/set_operations/union/union.cpp index 62e61a0c6f..a009911cc1 100644 --- a/test/algorithms/set_operations/union/union.cpp +++ b/test/algorithms/set_operations/union/union.cpp @@ -465,6 +465,9 @@ void test_areal() TEST_UNION(issue_1108, 1, 0, -1, 12.1742); TEST_UNION_REV(issue_1108, 1, 0, -1, 12.1742); + TEST_UNION(issue_1183, 1, 0, -1, 607.6507); + TEST_UNION_REV(issue_1183, 1, 0, -1, 607.6507); + TEST_UNION(issue_1186, 1, 1, -1, 21.6189); TEST_UNION_REV(issue_1186, 1, 1, -1, 21.6189);