From e8eb3f63822c1bb6c3169a10f72c4255d3d91b20 Mon Sep 17 00:00:00 2001 From: eli_lei Date: Wed, 18 Mar 2026 16:02:52 +0800 Subject: [PATCH] Provide specialized handling for floating-point types in PointInPolygon(). Fixes #1071 --- .../include/clipper2/clipper.core.h | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/CPP/Clipper2Lib/include/clipper2/clipper.core.h b/CPP/Clipper2Lib/include/clipper2/clipper.core.h index 99a52054..42f174a0 100644 --- a/CPP/Clipper2Lib/include/clipper2/clipper.core.h +++ b/CPP/Clipper2Lib/include/clipper2/clipper.core.h @@ -1130,9 +1130,18 @@ namespace Clipper2Lib val = 1 - val; // toggle val else { - int d = CrossProductSign(*prev, *curr, pt); - if (d == 0) return PointInPolygonResult::IsOn; - if ((d < 0) == is_above) val = 1 - val; + if constexpr (std::is_floating_point_v) + { + double d = CrossProduct(*prev, *curr, pt); + if (d == 0) return PointInPolygonResult::IsOn; + if ((d < 0) == is_above) val = 1 - val; + } + else + { + int d = CrossProductSign(*prev, *curr, pt); + if (d == 0) return PointInPolygonResult::IsOn; + if ((d < 0) == is_above) val = 1 - val; + } } is_above = !is_above; ++curr; @@ -1144,9 +1153,18 @@ namespace Clipper2Lib if (curr == cend) curr = cbegin; if (curr == cbegin) prev = cend - 1; else prev = curr - 1; - int d = CrossProductSign(*prev, *curr, pt); - if (d == 0) return PointInPolygonResult::IsOn; - if ((d < 0) == is_above) val = 1 - val; + if constexpr (std::is_floating_point_v) + { + double d = CrossProduct(*prev, *curr, pt); + if (d == 0) return PointInPolygonResult::IsOn; + if ((d < 0) == is_above) val = 1 - val; + } + else + { + int d = CrossProductSign(*prev, *curr, pt); + if (d == 0) return PointInPolygonResult::IsOn; + if ((d < 0) == is_above) val = 1 - val; + } } return (val == 0) ?