diff --git a/src/path/PathItem.Boolean.js b/src/path/PathItem.Boolean.js index cb0d4534..fe36bc89 100644 --- a/src/path/PathItem.Boolean.js +++ b/src/path/PathItem.Boolean.js @@ -1145,9 +1145,9 @@ PathItem.inject(new function() { // Support both path and compound-path items paths = children || [this]; - function hasOverlap(seg) { + function hasOverlap(seg, path) { var inter = seg && seg._intersection; - return inter && inter._overlap; + return inter && inter._overlap && inter._path === path; } // First collect all overlaps and crossings while taking not of the @@ -1169,10 +1169,12 @@ PathItem.inject(new function() { return inter.hasOverlap(); }, clearCurves); for (var i = overlaps.length - 1; i >= 0; i--) { - var seg = overlaps[i]._segment, + var overlap = overlaps[i], + path = overlap._path, + seg = overlap._segment, prev = seg.getPrevious(), next = seg.getNext(); - if (hasOverlap(prev) && hasOverlap(next)) { + if (hasOverlap(prev, path) && hasOverlap(next, path)) { seg.remove(); prev._handleOut._set(0, 0); next._handleIn._set(0, 0); diff --git a/test/helpers.js b/test/helpers.js index 4192b66e..20f1b13e 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -226,9 +226,6 @@ var comparePixels = function(actual, expected, message, options) { ok = Math.abs(100 - identical) <= tolerance, text = identical.toFixed(fixed) + '% identical', detail = text; - if (!ok) { - console.log(actual, expected); - } if (!ok && actual instanceof PathItem && expected instanceof PathItem) { detail += '\nExpected:\n' + expected.pathData + diff --git a/test/tests/Path_Boolean.js b/test/tests/Path_Boolean.js index 83bbf048..083b212b 100644 --- a/test/tests/Path_Boolean.js +++ b/test/tests/Path_Boolean.js @@ -21,7 +21,6 @@ function testOperations(path1, path2, results) { compareBoolean(function() { return path2.intersect(path1); }, results[3]); compareBoolean(function() { return path1.exclude(path2); }, results[4]); compareBoolean(function() { return path2.exclude(path1); }, results[4]); - } test('Boolean operations without crossings', function() { @@ -935,6 +934,12 @@ test('#1261', function() { 'M933.13,1023.97l-516.19,-171.71l67.33,-11.27l0.0109,0.00363l539.7591,-90.30363z'); }); +test('#1321', function() { + var path = PathItem.create('M24,38l2,1l-2,1l-2,-1z M26,39l2,1l-2,1l-2,-1z M28,40l2,1l-2,1l-2,-1z') + compareBoolean(function() { return path.unite(); }, + 'M24,38l6,3l-2,1l-6,-3z'); +}) + test('Selected edge-cases from @hari\'s boolean-test suite', function() { var g = PathItem.create('M316.6,266.4Q332.6,266.4,343.8,272.8Q355,279.2,362,289.8Q369,300.4,372.2,313.6Q375.4,326.8,375.4,340.4Q375.4,354.8,372,369.2Q368.6,383.6,361.4,395Q354.2,406.4,342.4,413.4Q330.6,420.4,313.8,420.4Q297,420.4,285.8,413.4Q274.6,406.4,267.8,395Q261,383.6,258.2,369.6Q255.4,355.6,255.4,341.6Q255.4,326.8,258.8,313.2Q262.2,299.6,269.6,289.2Q277,278.8,288.6,272.6Q300.2,266.4,316.6,266.4Z M315,236.4Q288.2,236.4,269.8,246.6Q251.4,256.8,240.2,272.6Q229,288.4,224.2,307.8Q219.4,327.2,219.4,345.6Q219.4,366.8,225.2,385.8Q231,404.8,242.6,419Q254.2,433.2,271.4,441.6Q288.6,450,311.8,450Q331.8,450,349.6,441Q367.4,432,376.2,412.8L377,412.8L377,426.4Q377,443.6,373.6,458Q370.2,472.4,362.6,482.6Q355,492.8,343.4,498.6Q331.8,504.4,315,504.4Q306.6,504.4,297.4,502.6Q288.2,500.8,280.4,496.8Q272.6,492.8,267.2,486.4Q261.8,480,261.4,470.8L227.4,470.8Q228.2,487.6,236.2,499.2Q244.2,510.8,256.4,518Q268.6,525.2,283.6,528.4Q298.6,531.6,313,531.6Q362.6,531.6,385.8,506.4Q409,481.2,409,430.4L409,241.2L377,241.2L377,270.8L376.6,270.8Q367.4,253.6,351,245Q334.6,236.4,315,236.4Z'); var u = PathItem.create('M253,316.74Q242.25,316.74,232.77,318.39Q218.77,320.83,208.21,328.52Q197.65,336.21,191.32,349.4Q185,362.6,183.59,382.95Q182.01,405.69,189.83,423.08Q197.64,440.46,216.05,452.56L215.99,453.36L183.27,451.09L181.06,483.01L387.37,497.31L389.72,463.39L273.2,455.32Q259.23,454.35,247.72,449.74Q236.21,445.14,227.96,436.95Q219.7,428.76,215.7,417.05Q211.7,405.35,212.78,389.78Q214.14,370.23,226.09,359.83Q236.68,350.61,252.94,350.61Q255.02,350.61,257.19,350.76L396.85,360.44L399.2,326.52L263.53,317.12Q258.12,316.74,253,316.74Z');