From 0651f445cdac3fae6b309c78c9a932a61dd52676 Mon Sep 17 00:00:00 2001 From: roberto Date: Fri, 17 May 2024 17:39:18 +0200 Subject: [PATCH] handle case of split region fully contained in base region --- app/public/js/tools/splitRegion.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/public/js/tools/splitRegion.js b/app/public/js/tools/splitRegion.js index 9f598fb..54bbfd2 100644 --- a/app/public/js/tools/splitRegion.js +++ b/app/public/js/tools/splitRegion.js @@ -67,13 +67,20 @@ window.ToolSplitRegion = {splitRegion: (function() { (new paper.Path({insert: false})).importJSON(childj) ]; const intersection = path1.intersect(path2); - const [path1Area, path2Area, intersectArea] = [path1.area, path2.area, intersection.area]; - const [overlap1, overlap2] = [intersectArea/path1Area, intersectArea/path2Area]; + const [path1Area, path2Area, intersect] = [path1.area, path2.area, intersection.area]; - return [ - Math.abs(1 - Math.abs(overlap1)) < tool._tol ? 1 : 0, - Math.abs(1 - Math.abs(overlap2)) < tool._tol ? 1 : 0 - ]; + if (intersect <= 0) { + return [0, 0]; + } + + if (path1Area > 0 && path2Area < 0 && path1Area > -path2Area) { + return [0, -1]; + } + if (path2Area > 0 && path1Area < 0 && path2Area > -path1Area) { + return [-1, 0]; + } + + return [0, 0]; }, _overlaps: function (children) { @@ -109,9 +116,9 @@ window.ToolSplitRegion = {splitRegion: (function() { let resultPath = new paper.Path({insert: false}); resultPath.importJSON(children[i]); - // look for a columns with overlap 1: they're the holes + // look for a columns with overlap -1: they're the holes for (let j = 0; j < children.length; j++) { - if (overlap[j][i] === 1) { + if (overlap[j][i] === -1) { const hole = new paper.Path({insert: false}); hole.importJSON(children[j]).reorient(); resultPath = resultPath.subtract(hole);