From 31acd3ade8148973336ef175147bda8b48fdd1f2 Mon Sep 17 00:00:00 2001 From: angusj Date: Fri, 22 Dec 2023 20:55:45 +1000 Subject: [PATCH] Fixed a compiler error when enabling CLIPPER2_HI_PRECISION. --- .../include/clipper2/clipper.core.h | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/CPP/Clipper2Lib/include/clipper2/clipper.core.h b/CPP/Clipper2Lib/include/clipper2/clipper.core.h index 0368d4b4..dae00653 100644 --- a/CPP/Clipper2Lib/include/clipper2/clipper.core.h +++ b/CPP/Clipper2Lib/include/clipper2/clipper.core.h @@ -1,6 +1,6 @@ /******************************************************************************* * Author : Angus Johnson * -* Date : 13 December 2023 * +* Date : 22 December 2023 * * Website : http://www.angusj.com * * Copyright : Angus Johnson 2010-2023 * * Purpose : Core Clipper Library structures and functions * @@ -754,21 +754,32 @@ namespace Clipper2Lib T bb1miny = CC_MIN(ln2a.y, ln2b.y); T bb1maxx = CC_MAX(ln2a.x, ln2b.x); T bb1maxy = CC_MAX(ln2a.y, ln2b.y); - T originx = (CC_MIN(bb0maxx, bb1maxx) + CC_MAX(bb0minx, bb1minx)) >> 1; - T originy = (CC_MIN(bb0maxy, bb1maxy) + CC_MAX(bb0miny, bb1miny)) >> 1; - double ln0c = (ln1dy * static_cast(ln1a.x - originx)) + - (ln1dx * static_cast(ln1a.y - originy)); - double ln1c = (ln2dy * static_cast(ln2a.x - originx)) + - (ln2dx * static_cast(ln2a.y - originy)); - double hitx = ((ln1dx * ln1c) - (ln2dx * ln0c)) / det; - double hity = ((ln2dy * ln0c) - (ln1dy * ln1c)) / det; + if constexpr (std::numeric_limits::is_integer) { + int64_t originx = (CC_MIN(bb0maxx, bb1maxx) + CC_MAX(bb0minx, bb1minx)) >> 1; + int64_t originy = (CC_MIN(bb0maxy, bb1maxy) + CC_MAX(bb0miny, bb1miny)) >> 1; + double ln0c = (ln1dy * static_cast(ln1a.x - originx)) + + (ln1dx * static_cast(ln1a.y - originy)); + double ln1c = (ln2dy * static_cast(ln2a.x - originx)) + + (ln2dx * static_cast(ln2a.y - originy)); + double hitx = ((ln1dx * ln1c) - (ln2dx * ln0c)) / det; + double hity = ((ln2dy * ln0c) - (ln1dy * ln1c)) / det; + ip.x = originx + (T)nearbyint(hitx); ip.y = originy + (T)nearbyint(hity); } else { + double originx = (CC_MIN(bb0maxx, bb1maxx) + CC_MAX(bb0minx, bb1minx)) / 2.0; + double originy = (CC_MIN(bb0maxy, bb1maxy) + CC_MAX(bb0miny, bb1miny)) / 2.0; + double ln0c = (ln1dy * static_cast(ln1a.x - originx)) + + (ln1dx * static_cast(ln1a.y - originy)); + double ln1c = (ln2dy * static_cast(ln2a.x - originx)) + + (ln2dx * static_cast(ln2a.y - originy)); + double hitx = ((ln1dx * ln1c) - (ln2dx * ln0c)) / det; + double hity = ((ln2dy * ln0c) - (ln1dy * ln1c)) / det; + ip.x = originx + static_cast(hitx); ip.y = originy + static_cast(hity); }