mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 10:48:38 -05:00
Fix handling of overlapping paths for subtract and exclude operations.
Closes #1139
This commit is contained in:
parent
0018b69e4d
commit
46fce16bff
2 changed files with 33 additions and 28 deletions
|
@ -810,10 +810,8 @@ PathItem.inject(new function() {
|
||||||
path2 = seg._intersection._segment._path;
|
path2 = seg._intersection._segment._path;
|
||||||
if (path1.compare(path2)) {
|
if (path1.compare(path2)) {
|
||||||
// Only add the path to the result if it has an area.
|
// Only add the path to the result if it has an area.
|
||||||
if ((operator.unite || operator.intersect)
|
if (path1.getArea())
|
||||||
&& path1.getArea()) {
|
|
||||||
paths.push(path1.clone(false));
|
paths.push(path1.clone(false));
|
||||||
}
|
|
||||||
// Now mark all involved segments as visited.
|
// Now mark all involved segments as visited.
|
||||||
visitPath(path1);
|
visitPath(path1);
|
||||||
visitPath(path2);
|
visitPath(path2);
|
||||||
|
|
|
@ -685,6 +685,33 @@ test('#1075', function() {
|
||||||
'M140,125l0,-65l210,0l0,65l-35,0l0,-5l-137,0l0,5z M315,85l-137,0l0,25l137,0z');
|
'M140,125l0,-65l210,0l0,65l-35,0l0,-5l-137,0l0,5z M315,85l-137,0l0,25l137,0z');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('#1091', function() {
|
||||||
|
var data = [
|
||||||
|
'M91.24228100000002,45.622281000000015v396.89171899999997c0,25.195925999999986 -20.426355000000015,45.622281000000044 -45.62000000000001,45.622281000000044c-25.198207000000007,0 -45.620000000000005,-20.42407400000002 -45.620000000000005,-45.622281000000044v-396.889438c0,-25.19820700000001 20.421792999999997,-45.62228100000001 45.620000000000005,-45.62228100000001c25.193644999999997,0 45.617719000000015,20.424074000000015 45.62000000000001,45.62000000000001z0',
|
||||||
|
'M223.67029800000003,488.13628100000005h-178.05029800000003c-25.198207000000004,0 -45.620000000000005,-20.426355000000058 -45.620000000000005,-45.622281000000044v0c0,25.198207000000025 20.421793,45.622281000000044 45.620000000000005,45.622281000000044c25.193645000000004,0 45.620000000000005,-20.426355000000058 45.620000000000005,-45.622281000000044v-45.620000000000005h132.430298v0c-25.193645000000004,0 -45.620000000000005,20.42407400000002 -45.620000000000005,45.620000000000005c0.0022810000000106356,25.198207000000025 20.426355,45.622281000000044 45.620000000000005,45.622281000000044',
|
||||||
|
'M225.369643,488.13628100000005h-1.6993449999999939c1.0013589999999795,0 2.0004369999999767,-0.006843000000003485 2.9995150000000024,-0.01824800000002824c-0.4311089999999922,0.011404999999967913 -0.8644990000000234,0.01824800000002824 -1.3001700000000085,0.01824800000002824z',
|
||||||
|
'M45.62228100000001,488.13628100000005c-25.198207000000007,0 -45.620000000000005,-20.426355000000058 -45.620000000000005,-45.622281000000044c0,-25.193644999999947 20.421792999999997,-45.620000000000005 45.620000000000005,-45.620000000000005h45.62000000000001v45.620000000000005c-0.0022809999999964248,25.198207000000025 -20.426355000000015,45.622281000000044 -45.62000000000001,45.622281000000044z',
|
||||||
|
'M223.67029800000003,91.242281h-132.430298v-45.620000000000005c0,-25.195926000000004 -20.424074000000005,-45.62228100000001 -45.620000000000005,-45.62228100000001h179.667527c0.41742300000001364,0 0.8325649999999882,0.004561999999999999 1.2477069999999912,0.015967000000000002c-0.9511770000000013,-0.011405000000000002 -1.9137589999999989,-0.015967000000000002 -2.867217000000011,-0.015967000000000002c-25.193645000000004,0 -45.620000000000005,20.424074 -45.620000000000005,45.62228100000001c0.0045619999999928496,25.195926 20.42863600000004,45.620000000000005 45.622281000000044,45.620000000000005z',
|
||||||
|
'M91.24000000000001,91.242281h-45.620000000000005c-25.198207000000004,0 -45.620000000000005,-20.424074000000005 -45.620000000000005,-45.620000000000005c0,-25.195926000000004 20.421793,-45.62228100000001 45.620000000000005,-45.62228100000001v0c25.193645000000004,0 45.620000000000005,20.424074 45.620000000000005,45.62228100000001z',
|
||||||
|
'M226.66981300000003,488.118033c24.59146100000001,-0.6888619999999719 44.31982999999997,-20.841497000000004 44.31982999999997,-45.604033000000015c0,-25.193644999999947 -20.42407400000002,-45.620000000000005 -45.620000000000005,-45.620000000000005h-1.6993449999999939c80.626507,0 139.143281,-64.27173699999997 139.143281,-152.827v0c0,25.198207000000025 20.42407400000002,45.620000000000005 45.622281000000044,45.620000000000005c25.193644999999947,0 45.620000000000005,-20.42179299999998 45.620000000000005,-45.620000000000005c0,138.080335 -97.54012200000005,242.46573800000004 -227.38604700000002,244.05103300000002z',
|
||||||
|
'M223.67029800000003,488.13628100000005v0c-25.193645000000004,0 -45.620000000000005,-20.426355000000058 -45.620000000000005,-45.622281000000044c0,-25.193644999999947 20.426355,-45.620000000000005 45.620000000000005,-45.620000000000005v0h1.6993450000000223c25.193645000000004,0 45.620000000000005,20.42407400000002 45.620000000000005,45.620000000000005c0,24.76253600000001 -19.726088000000004,44.91517100000004 -44.319829999999996,45.604033000000015c-0.9967969999999866,0.011404999999967913 -1.9958750000000407,0.01824800000002824 -2.999515000000031,0.01824800000002824z',
|
||||||
|
'M454.05586000000005,244.06928100000002c0,-25.198206999999996 -20.42407400000002,-45.617718999999994 -45.620000000000005,-45.617718999999994c-25.198207000000025,0 -45.622281000000044,20.421793000000008 -45.622281000000044,45.617718999999994v0c0,-88.55298200000001 -58.516774,-152.827 -139.143281,-152.827v0h1.617229000000009c25.198206999999996,0 45.62228099999999,-20.424074000000005 45.62228099999999,-45.620000000000005c0,-24.778503 -19.755740999999972,-44.942543 -44.372292999999985,-45.606314000000005c129.918917,1.5123030000000002 227.51834500000004,105.922797 227.51834500000004,244.053314z',
|
||||||
|
'M225.28980800000002,91.242281h-1.617229000000009c-25.193645000000004,0 -45.620000000000005,-20.424074000000005 -45.620000000000005,-45.620000000000005c0,-25.195926000000004 20.426355,-45.62228100000001 45.620000000000005,-45.62228100000001c0.9534580000000119,0 1.9160400000000095,0.006843000000000001 2.867217000000011,0.015967000000000002c24.618833000000024,0.6637710000000001 44.37229300000001,20.827811 44.37229300000001,45.60631400000001c0,25.195926 -20.426355,45.620000000000005 -45.622281000000015,45.620000000000005z',
|
||||||
|
'M408.43586000000005,289.687c-25.198207000000025,0 -45.622281000000044,-20.42179299999998 -45.622281000000044,-45.620000000000005v0v0c0,-25.198206999999996 20.42407400000002,-45.617718999999994 45.622281000000044,-45.617718999999994c25.193644999999947,0 45.620000000000005,20.421793000000008 45.620000000000005,45.617718999999994v0v0c0,25.198207000000025 -20.42407400000002,45.620000000000005 -45.620000000000005,45.620000000000005z'
|
||||||
|
];
|
||||||
|
var res = new CompoundPath();
|
||||||
|
|
||||||
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
var path = PathItem.create(data[i]);
|
||||||
|
path.remove();
|
||||||
|
var prev = res;
|
||||||
|
res = res.unite(path);
|
||||||
|
prev.remove();
|
||||||
|
};
|
||||||
|
compareBoolean(function() { return res; },
|
||||||
|
'M91.24228,396.894h132.42802c-25.19365,0 -45.62,20.42407 -45.62,45.62c0,-25.19364 20.42635,-45.62 45.62,-45.62c80.62581,0 139.14228,-64.27063 139.14328,-152.82472l0,-0.00228c-0.001,-88.55097 -58.51636,-152.82351 -139.141,-152.82472l-0.00228,0c-25.1926,-0.00123 -45.61772,-20.42483 -45.61772,-45.62c0,-25.1955 20.42566,-45.62158 45.61871,-45.62228h1.61624c0.4166,0 0.83093,0.00454 1.24526,0.0159c0.00234,0.00002 0.00467,0.00004 0.00701,0.00007c0.00058,0.00002 0.00116,0.00003 0.00173,0.00005c129.91593,1.5144 227.51285,105.92259 227.51433,244.05012c0,0.00029 0,0.00057 0,0.00086c0,0.00012 0,0.00024 0,0.00036l0,0.00192c-0.00107,138.0792 -97.54084,242.46347 -227.38605,244.04875c-0.43111,0.0114 -0.8645,0.01825 -1.30017,0.01825h-1.69934c-12.59632,0 -24.00091,-5.10618 -32.25663,-13.36168c8.2555,8.25572 19.65987,13.36168 32.25663,13.36168l-178.04574,0c-0.00076,0 -0.00152,0 -0.00228,0c-0.00076,0 -0.00152,0 -0.00228,0h0c-25.19716,-0.00123 -45.61772,-20.42483 -45.61772,-45.62228v-396.88944c0,-25.19821 20.42179,-45.62228 45.62,-45.62228c14.89455,0 28.12203,7.13863 36.44812,18.18156c-8.3258,-11.04405 -21.55413,-18.18384 -36.4504,-18.18384h178.04802c-25.19365,0 -45.62,20.42407 -45.62,45.62228c0.00456,25.19593 20.42864,45.62 45.62228,45.62l-132.42802,0zM45.62,488.13628c-25.19821,0 -45.62,-20.42407 -45.62,-45.62228c0,25.19593 20.42179,45.62228 45.62,45.62228zM226.51682,0.01575c-0.93686,-0.01114 -1.88465,-0.01567 -2.82377,-0.01575c0.93909,0.0001 1.88688,0.0068 2.82377,0.01575zM362.81358,244.06928c0.00123,25.19716 20.42483,45.61772 45.62228,45.61772c-25.19745,0 -45.62105,-20.42056 -45.62228,-45.61772z');
|
||||||
|
});
|
||||||
|
|
||||||
test('#1109', function() {
|
test('#1109', function() {
|
||||||
var segments = [
|
var segments = [
|
||||||
[274.616046379547, 215.30654471841746],
|
[274.616046379547, 215.30654471841746],
|
||||||
|
@ -739,31 +766,11 @@ test('#1123', function() {
|
||||||
'M29.56257,132.54192c-1.1465,0.14077 -9.00925,-6.09934 -19.31903,-7.59213c2.44054,-1.04008 4.85728,-1.65337 7.21093,-1.94237c13.88763,-1.70519 25.57836,7.88056 26.99629,7.70646zM44.75533,130.3897c0.31974,0.14538 0.55147,0.21908 0.68798,0.20232l-0.99255,0.12187c0.09534,-0.01171 0.14423,-0.06753 0.14423,-0.17388c0.05357,-0.05007 0.10701,-0.10017 0.16033,-0.1503z');
|
'M29.56257,132.54192c-1.1465,0.14077 -9.00925,-6.09934 -19.31903,-7.59213c2.44054,-1.04008 4.85728,-1.65337 7.21093,-1.94237c13.88763,-1.70519 25.57836,7.88056 26.99629,7.70646zM44.75533,130.3897c0.31974,0.14538 0.55147,0.21908 0.68798,0.20232l-0.99255,0.12187c0.09534,-0.01171 0.14423,-0.06753 0.14423,-0.17388c0.05357,-0.05007 0.10701,-0.10017 0.16033,-0.1503z');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('#1091', function() {
|
test('#1123', function() {
|
||||||
var data = [
|
var p1 = new Path.Rectangle(100, 100, 100, 100);
|
||||||
'M91.24228100000002,45.622281000000015v396.89171899999997c0,25.195925999999986 -20.426355000000015,45.622281000000044 -45.62000000000001,45.622281000000044c-25.198207000000007,0 -45.620000000000005,-20.42407400000002 -45.620000000000005,-45.622281000000044v-396.889438c0,-25.19820700000001 20.421792999999997,-45.62228100000001 45.620000000000005,-45.62228100000001c25.193644999999997,0 45.617719000000015,20.424074000000015 45.62000000000001,45.62000000000001z0',
|
var p2 = new Path.Rectangle(120, 120, 60, 60);
|
||||||
'M223.67029800000003,488.13628100000005h-178.05029800000003c-25.198207000000004,0 -45.620000000000005,-20.426355000000058 -45.620000000000005,-45.622281000000044v0c0,25.198207000000025 20.421793,45.622281000000044 45.620000000000005,45.622281000000044c25.193645000000004,0 45.620000000000005,-20.426355000000058 45.620000000000005,-45.622281000000044v-45.620000000000005h132.430298v0c-25.193645000000004,0 -45.620000000000005,20.42407400000002 -45.620000000000005,45.620000000000005c0.0022810000000106356,25.198207000000025 20.426355,45.622281000000044 45.620000000000005,45.622281000000044',
|
compareBoolean(function() { return p1.subtract(p2).subtract(p2); },
|
||||||
'M225.369643,488.13628100000005h-1.6993449999999939c1.0013589999999795,0 2.0004369999999767,-0.006843000000003485 2.9995150000000024,-0.01824800000002824c-0.4311089999999922,0.011404999999967913 -0.8644990000000234,0.01824800000002824 -1.3001700000000085,0.01824800000002824z',
|
'M100,200v-100h100v100zM180,180v-60h-60v60z');
|
||||||
'M45.62228100000001,488.13628100000005c-25.198207000000007,0 -45.620000000000005,-20.426355000000058 -45.620000000000005,-45.622281000000044c0,-25.193644999999947 20.421792999999997,-45.620000000000005 45.620000000000005,-45.620000000000005h45.62000000000001v45.620000000000005c-0.0022809999999964248,25.198207000000025 -20.426355000000015,45.622281000000044 -45.62000000000001,45.622281000000044z',
|
|
||||||
'M223.67029800000003,91.242281h-132.430298v-45.620000000000005c0,-25.195926000000004 -20.424074000000005,-45.62228100000001 -45.620000000000005,-45.62228100000001h179.667527c0.41742300000001364,0 0.8325649999999882,0.004561999999999999 1.2477069999999912,0.015967000000000002c-0.9511770000000013,-0.011405000000000002 -1.9137589999999989,-0.015967000000000002 -2.867217000000011,-0.015967000000000002c-25.193645000000004,0 -45.620000000000005,20.424074 -45.620000000000005,45.62228100000001c0.0045619999999928496,25.195926 20.42863600000004,45.620000000000005 45.622281000000044,45.620000000000005z',
|
|
||||||
'M91.24000000000001,91.242281h-45.620000000000005c-25.198207000000004,0 -45.620000000000005,-20.424074000000005 -45.620000000000005,-45.620000000000005c0,-25.195926000000004 20.421793,-45.62228100000001 45.620000000000005,-45.62228100000001v0c25.193645000000004,0 45.620000000000005,20.424074 45.620000000000005,45.62228100000001z',
|
|
||||||
'M226.66981300000003,488.118033c24.59146100000001,-0.6888619999999719 44.31982999999997,-20.841497000000004 44.31982999999997,-45.604033000000015c0,-25.193644999999947 -20.42407400000002,-45.620000000000005 -45.620000000000005,-45.620000000000005h-1.6993449999999939c80.626507,0 139.143281,-64.27173699999997 139.143281,-152.827v0c0,25.198207000000025 20.42407400000002,45.620000000000005 45.622281000000044,45.620000000000005c25.193644999999947,0 45.620000000000005,-20.42179299999998 45.620000000000005,-45.620000000000005c0,138.080335 -97.54012200000005,242.46573800000004 -227.38604700000002,244.05103300000002z',
|
|
||||||
'M223.67029800000003,488.13628100000005v0c-25.193645000000004,0 -45.620000000000005,-20.426355000000058 -45.620000000000005,-45.622281000000044c0,-25.193644999999947 20.426355,-45.620000000000005 45.620000000000005,-45.620000000000005v0h1.6993450000000223c25.193645000000004,0 45.620000000000005,20.42407400000002 45.620000000000005,45.620000000000005c0,24.76253600000001 -19.726088000000004,44.91517100000004 -44.319829999999996,45.604033000000015c-0.9967969999999866,0.011404999999967913 -1.9958750000000407,0.01824800000002824 -2.999515000000031,0.01824800000002824z',
|
|
||||||
'M454.05586000000005,244.06928100000002c0,-25.198206999999996 -20.42407400000002,-45.617718999999994 -45.620000000000005,-45.617718999999994c-25.198207000000025,0 -45.622281000000044,20.421793000000008 -45.622281000000044,45.617718999999994v0c0,-88.55298200000001 -58.516774,-152.827 -139.143281,-152.827v0h1.617229000000009c25.198206999999996,0 45.62228099999999,-20.424074000000005 45.62228099999999,-45.620000000000005c0,-24.778503 -19.755740999999972,-44.942543 -44.372292999999985,-45.606314000000005c129.918917,1.5123030000000002 227.51834500000004,105.922797 227.51834500000004,244.053314z',
|
|
||||||
'M225.28980800000002,91.242281h-1.617229000000009c-25.193645000000004,0 -45.620000000000005,-20.424074000000005 -45.620000000000005,-45.620000000000005c0,-25.195926000000004 20.426355,-45.62228100000001 45.620000000000005,-45.62228100000001c0.9534580000000119,0 1.9160400000000095,0.006843000000000001 2.867217000000011,0.015967000000000002c24.618833000000024,0.6637710000000001 44.37229300000001,20.827811 44.37229300000001,45.60631400000001c0,25.195926 -20.426355,45.620000000000005 -45.622281000000015,45.620000000000005z',
|
|
||||||
'M408.43586000000005,289.687c-25.198207000000025,0 -45.622281000000044,-20.42179299999998 -45.622281000000044,-45.620000000000005v0v0c0,-25.198206999999996 20.42407400000002,-45.617718999999994 45.622281000000044,-45.617718999999994c25.193644999999947,0 45.620000000000005,20.421793000000008 45.620000000000005,45.617718999999994v0v0c0,25.198207000000025 -20.42407400000002,45.620000000000005 -45.620000000000005,45.620000000000005z'
|
|
||||||
];
|
|
||||||
var res = new CompoundPath();
|
|
||||||
|
|
||||||
for (var i = 0; i < data.length; i++) {
|
|
||||||
var path = PathItem.create(data[i]);
|
|
||||||
path.remove();
|
|
||||||
var prev = res;
|
|
||||||
res = res.unite(path);
|
|
||||||
prev.remove();
|
|
||||||
};
|
|
||||||
compareBoolean(function() { return res; },
|
|
||||||
'M91.24228,396.894h132.42802c-25.19365,0 -45.62,20.42407 -45.62,45.62c0,-25.19364 20.42635,-45.62 45.62,-45.62c80.62581,0 139.14228,-64.27063 139.14328,-152.82472l0,-0.00228c-0.001,-88.55097 -58.51636,-152.82351 -139.141,-152.82472l-0.00228,0c-25.1926,-0.00123 -45.61772,-20.42483 -45.61772,-45.62c0,-25.1955 20.42566,-45.62158 45.61871,-45.62228h1.61624c0.4166,0 0.83093,0.00454 1.24526,0.0159c0.00234,0.00002 0.00467,0.00004 0.00701,0.00007c0.00058,0.00002 0.00116,0.00003 0.00173,0.00005c129.91593,1.5144 227.51285,105.92259 227.51433,244.05012c0,0.00029 0,0.00057 0,0.00086c0,0.00012 0,0.00024 0,0.00036l0,0.00192c-0.00107,138.0792 -97.54084,242.46347 -227.38605,244.04875c-0.43111,0.0114 -0.8645,0.01825 -1.30017,0.01825h-1.69934c-12.59632,0 -24.00091,-5.10618 -32.25663,-13.36168c8.2555,8.25572 19.65987,13.36168 32.25663,13.36168l-178.04574,0c-0.00076,0 -0.00152,0 -0.00228,0c-0.00076,0 -0.00152,0 -0.00228,0h0c-25.19716,-0.00123 -45.61772,-20.42483 -45.61772,-45.62228v-396.88944c0,-25.19821 20.42179,-45.62228 45.62,-45.62228c14.89455,0 28.12203,7.13863 36.44812,18.18156c-8.3258,-11.04405 -21.55413,-18.18384 -36.4504,-18.18384h178.04802c-25.19365,0 -45.62,20.42407 -45.62,45.62228c0.00456,25.19593 20.42864,45.62 45.62228,45.62l-132.42802,0zM45.62,488.13628c-25.19821,0 -45.62,-20.42407 -45.62,-45.62228c0,25.19593 20.42179,45.62228 45.62,45.62228zM226.51682,0.01575c-0.93686,-0.01114 -1.88465,-0.01567 -2.82377,-0.01575c0.93909,0.0001 1.88688,0.0068 2.82377,0.01575zM362.81358,244.06928c0.00123,25.19716 20.42483,45.61772 45.62228,45.61772c-25.19745,0 -45.62105,-20.42056 -45.62228,-45.61772z');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('frame.intersect(rect);', function() {
|
test('frame.intersect(rect);', function() {
|
||||||
|
|
Loading…
Reference in a new issue