mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 09:22:22 -05:00
Boolean: Only compare segments when determining if paths are identitcal.
This commit is contained in:
parent
3348fb736f
commit
009761d13c
2 changed files with 104 additions and 101 deletions
|
@ -538,18 +538,18 @@ PathItem.inject(new function() {
|
|||
if (!seg._visited && seg._path._overlapsOnly) {
|
||||
// TODO: Don't we also need to check for multiple overlaps?
|
||||
var path1 = seg._path,
|
||||
path2 = inter._segment._path;
|
||||
if (path1.equals(path2)) {
|
||||
path2 = inter._segment._path,
|
||||
segments1 = path1._segments,
|
||||
segments2 = path2._segments;
|
||||
if (Base.equals(segments1, segments2)) {
|
||||
// Only add the path to the result if it has an area.
|
||||
if ((operator.unite || operator.intersect)
|
||||
&& path1.getArea()) {
|
||||
paths.push(path1.clone(false));
|
||||
}
|
||||
// Now mark all involved segments as visited.
|
||||
var segs1 = path1._segments,
|
||||
segs2 = path2._segments;
|
||||
for (var j = 0, m = segs1.length; j < m; j++) {
|
||||
segs1[j]._visited = segs2[j]._visited = true;
|
||||
for (var j = 0, k = segments1.length; j < k; j++) {
|
||||
segments1[j]._visited = segments2[j]._visited = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,6 +142,81 @@ test('#784', function() {
|
|||
'M265.13434,453.46566l-0.03434,0.03434c0,0 -49.1,-14.5 -36.6,-36.6c7.48073,-13.22593 39.10093,-1.6319 63.28843,9.81157l16.18604,-16.18604c-8.05354,-21.53223 -15.90287,-47.40397 -10.27447,-54.42553c9.77623,-12.51358 31.40373,30.40618 32.36674,32.33326l0.03326,-0.03326c0,0.1 65,49.8 65,65c0,15.2 -33.8,65 -65,65c-30.62393,0 -63.75273,-62.62185 -64.96566,-64.93434z');
|
||||
});
|
||||
|
||||
|
||||
test('#784#issuecomment-144653463', function() {
|
||||
var path1 = new Path({
|
||||
segments: [
|
||||
[400, 300, 0, 0, 0, 0],
|
||||
[396.4240965757225, 386.760212367686, 0, 0, 0, 0],
|
||||
[363.8902430603039, 336.3464406833805, 0, 0, 0, 0]
|
||||
],
|
||||
closed: true
|
||||
});
|
||||
var path2 = new Path({
|
||||
segments: [
|
||||
[380.15716053320796, 361.5533174872367, 0, 0, 0, 0],
|
||||
[368.9579765078272, 389.3845783631412, 0, 0, 0, 0],
|
||||
[352.11749924000907, 372.22000125020173, 0, 0, 0, 0]
|
||||
],
|
||||
closed: true
|
||||
});
|
||||
var path3 = new Path({
|
||||
segments: [
|
||||
[381.9248139754118, 360.88087710036456, 0, 0, 0, 0],
|
||||
[352.11749931845384, 372.22000145641056, 0, 0, 0, 0],
|
||||
[353.8723170322086, 346.9400510828104, 0, 0, 0, 0]
|
||||
],
|
||||
closed: true
|
||||
});
|
||||
compareBoolean(function() { return path1.unite(path2).unite(path3); },
|
||||
'M400,300l-3.5759,86.76021l-16.26693,-25.2069l0,0l-11.19918,27.83126l-16.84048,-17.16458l1.75482,-25.27995l24.8115,12.3302l-14.79357,-22.92381z M352.1175,372.22z');
|
||||
});
|
||||
|
||||
test('#784#issuecomment-144993215', function() {
|
||||
var path1 = new Path({
|
||||
segments: [
|
||||
[428.65986693122585, 123.24312916360232, 0, 0, 0, 0],
|
||||
[448.9732353341095, 290.23336023178985, -1.297313778199964, -0.24666929481787747, -0.06896642337790126, -0.004714867204086204],
|
||||
[448.9732339473677, 290.2333601369859, 0.22704183013848933, 0.04316939284507271, 0.24127512029406262, 0.016494695478172616],
|
||||
[375.34013306877415, 150.7568708363977, 0, 0, 0, 0]
|
||||
],
|
||||
closed: true
|
||||
});
|
||||
compareBoolean(function() { return path1.unite(); },
|
||||
'M428.65987,123.24313c0,0 18.24445,159.97772 20.21157,166.76806c-3.05664,-6.18082 -73.53131,-139.25432 -73.53131,-139.25432z M448.97323,290.23336c0,0 0,0 0,0c0.22704,0.04317 -0.06896,-0.00471 0,0c-0.02659,-0.00506 -0.06063,-0.08007 -0.1018,-0.22217c0.07286,0.14733 0.10741,0.22256 0.1018,0.22217z',
|
||||
null, { tolerance: 1e-3 });
|
||||
});
|
||||
|
||||
test('#784#issuecomment-168605018', function() {
|
||||
var path1 = new CompoundPath();
|
||||
path1.setChildren([
|
||||
new Path({
|
||||
segments: [
|
||||
[401.77542835664826, 286.9803609495646],
|
||||
[410.6261525310172, 207.97354059345616],
|
||||
[460.3783408790767, 174.43669899386418],
|
||||
],
|
||||
closed: true
|
||||
}), new Path({
|
||||
segments: [
|
||||
[410.6261524612045, 207.9735406405153],
|
||||
[410.6261525310172, 207.97354059345614, -0.0005059167983745283, -0.0007686158121771314]
|
||||
],
|
||||
closed: true
|
||||
})
|
||||
], true);
|
||||
var path2 = new Path({
|
||||
segments: [
|
||||
[410.6261524612047, 207.97354064051552, 0, 0, 0.19904749518872222, 0.2952886437272184],
|
||||
[409.163896522797, 207.2586618457598, 1.6828473498011363, 0.6114523237241087],
|
||||
[460.3783408790765, 174.43669899386396]
|
||||
],
|
||||
closed: true
|
||||
});
|
||||
compareBoolean(function() { return path1.unite(path2); },
|
||||
'M401.77543,286.98036l8.85044,-79.00432c-0.16499,-0.13413 -0.57872,-0.39645 -1.46198,-0.71738l51.21444,-32.82196z M410.62615,207.97354c0,0 0,0 0,0z');
|
||||
});
|
||||
|
||||
test('#854', function() {
|
||||
var p = new Path({
|
||||
segments:[
|
||||
|
@ -412,6 +487,8 @@ test('#923', function() {
|
|||
var p2 = new Path.Circle({center: [150, 100], radius: 20});
|
||||
var cp = new CompoundPath([p1, p2]);
|
||||
var p3 = new Path.Circle({center: [100, 100], radius: 20});
|
||||
cp.strokeColor = 'red';
|
||||
p3.strokeColor = 'green';
|
||||
compareBoolean(function() { return cp.unite(p3); },
|
||||
'M80,100c0,-11.04569 8.95431,-20 20,-20c11.04569,0 20,8.95431 20,20c0,11.04569 -8.95431,20 -20,20c-11.04569,0 -20,-8.95431 -20,-20z M130,100c0,-11.04569 8.95431,-20 20,-20c11.04569,0 20,8.95431 20,20c0,11.04569 -8.95431,20 -20,20c-11.04569,0 -20,-8.95431 -20,-20z');
|
||||
});
|
||||
|
@ -435,6 +512,27 @@ test('frame.intersect(rect);', function() {
|
|||
'M140,50l10,0l0,150l-10,0z');
|
||||
});
|
||||
|
||||
test('PathItem#resolveCrossings()', function() {
|
||||
var paths = [
|
||||
'M100,300l0,-50l50,-50l-50,0l150,0l-150,0l50,0l-50,0l100,0l-100,0l0,-100l200,0l0,200z',
|
||||
'M50,300l0,-150l50,25l0,-75l200,0l0,200z M100,200l50,0l-50,-25z',
|
||||
'M330.1,388.5l-65,65c0,0 -49.1,-14.5 -36.6,-36.6c12.5,-22.1 92.4,25.1 92.4,25.1c0,0 -33.3,-73.3 -23.2,-85.9c10,-12.8 32.4,32.4 32.4,32.4z',
|
||||
'M570,290l5.8176000300452415,33.58556812220928l-28.17314339506561,-14.439003967264455l31.189735425395614,-4.568209255479985c-5.7225406635552645e-9,-3.907138079739525e-8 -59.366611385062015,8.695139599513823 -59.366611385062015,8.695139599513823z'
|
||||
];
|
||||
var results = [
|
||||
'M100,300l0,-50l50,-50l-50,0l0,-100l200,0l0,200z',
|
||||
'M50,300l0,-150l50,25l0,-75l200,0l0,200z M100,200l50,0l-50,-25z',
|
||||
'M291.85631,426.74369l-26.75631,26.75631c0,0 -49.1,-14.5 -36.6,-36.6c7.48773,-13.23831 39.16013,-1.61018 63.35631,9.84369z M330.1,388.5l-22.09831,22.09831c-8.06306,-21.54667 -15.93643,-47.46883 -10.30169,-54.49831c10,-12.8 32.4,32.4 32.4,32.4z M320.9,442c0,0 -12.84682,-7.58911 -29.04369,-15.25631l16.14539,-16.14539c6.38959,17.07471 12.89831,31.40169 12.89831,31.40169z',
|
||||
'M570,290l5.8176,33.58557l-28.17314,-14.439c-14.32289,2.0978 -28.17688,4.12693 -28.17688,4.12693z'
|
||||
];
|
||||
for (var i = 0; i < paths.length; i++) {
|
||||
var path = createPath(paths[i]),
|
||||
result = createPath(results[i]);
|
||||
path.fillRule = 'evenodd';
|
||||
compareBoolean(path.resolveCrossings(), result, 'path.resolveCrossings(); // Test ' + (i + 1));
|
||||
}
|
||||
});
|
||||
|
||||
test('Selected edge-cases from @hari\'s boolean-test suite', function() {
|
||||
var g = createPath('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 = createPath('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');
|
||||
|
@ -876,98 +974,3 @@ test('Isolated edge-cases from @iconexperience\'s boolean-test suite', function(
|
|||
compareBoolean(path1.intersect(path2), result[1], 'path1.intersect(path2); // Test ' + (i + 1));
|
||||
}
|
||||
});
|
||||
|
||||
test('#784#issuecomment-144653463', function() {
|
||||
var path1 = new Path({
|
||||
segments: [
|
||||
[400, 300, 0, 0, 0, 0],
|
||||
[396.4240965757225, 386.760212367686, 0, 0, 0, 0],
|
||||
[363.8902430603039, 336.3464406833805, 0, 0, 0, 0]
|
||||
],
|
||||
closed: true
|
||||
});
|
||||
var path2 = new Path({
|
||||
segments: [
|
||||
[380.15716053320796, 361.5533174872367, 0, 0, 0, 0],
|
||||
[368.9579765078272, 389.3845783631412, 0, 0, 0, 0],
|
||||
[352.11749924000907, 372.22000125020173, 0, 0, 0, 0]
|
||||
],
|
||||
closed: true
|
||||
});
|
||||
var path3 = new Path({
|
||||
segments: [
|
||||
[381.9248139754118, 360.88087710036456, 0, 0, 0, 0],
|
||||
[352.11749931845384, 372.22000145641056, 0, 0, 0, 0],
|
||||
[353.8723170322086, 346.9400510828104, 0, 0, 0, 0]
|
||||
],
|
||||
closed: true
|
||||
});
|
||||
compareBoolean(function() { return path1.unite(path2).unite(path3); },
|
||||
'M400,300l-3.5759,86.76021l-16.26693,-25.2069l0,0l-11.19918,27.83126l-16.84048,-17.16458l1.75482,-25.27995l24.8115,12.3302l-14.79357,-22.92381z M352.1175,372.22z');
|
||||
});
|
||||
|
||||
test('#784#issuecomment-144993215', function() {
|
||||
var path1 = new Path({
|
||||
segments: [
|
||||
[428.65986693122585, 123.24312916360232, 0, 0, 0, 0],
|
||||
[448.9732353341095, 290.23336023178985, -1.297313778199964, -0.24666929481787747, -0.06896642337790126, -0.004714867204086204],
|
||||
[448.9732339473677, 290.2333601369859, 0.22704183013848933, 0.04316939284507271, 0.24127512029406262, 0.016494695478172616],
|
||||
[375.34013306877415, 150.7568708363977, 0, 0, 0, 0]
|
||||
],
|
||||
closed: true
|
||||
});
|
||||
compareBoolean(function() { return path1.unite(); },
|
||||
'M428.65987,123.24313c0,0 18.24445,159.97772 20.21157,166.76806c-3.05664,-6.18082 -73.53131,-139.25432 -73.53131,-139.25432z M448.97323,290.23336c0,0 0,0 0,0c0.22704,0.04317 -0.06896,-0.00471 0,0c-0.02659,-0.00506 -0.06063,-0.08007 -0.1018,-0.22217c0.07286,0.14733 0.10741,0.22256 0.1018,0.22217z',
|
||||
null, { tolerance: 1e-3 });
|
||||
});
|
||||
|
||||
test('#784#issuecomment-168605018', function() {
|
||||
var path1 = new CompoundPath();
|
||||
path1.setChildren([
|
||||
new Path({
|
||||
segments: [
|
||||
[401.77542835664826, 286.9803609495646],
|
||||
[410.6261525310172, 207.97354059345616],
|
||||
[460.3783408790767, 174.43669899386418],
|
||||
],
|
||||
closed: true
|
||||
}), new Path({
|
||||
segments: [
|
||||
[410.6261524612045, 207.9735406405153],
|
||||
[410.6261525310172, 207.97354059345614, -0.0005059167983745283, -0.0007686158121771314]
|
||||
],
|
||||
closed: true
|
||||
})
|
||||
], true);
|
||||
var path2 = new Path({
|
||||
segments: [
|
||||
[410.6261524612047, 207.97354064051552, 0, 0, 0.19904749518872222, 0.2952886437272184],
|
||||
[409.163896522797, 207.2586618457598, 1.6828473498011363, 0.6114523237241087],
|
||||
[460.3783408790765, 174.43669899386396]
|
||||
],
|
||||
closed: true
|
||||
});
|
||||
compareBoolean(function() { return path1.unite(path2); },
|
||||
'M401.77543,286.98036l8.85044,-79.00432c-0.16499,-0.13413 -0.57872,-0.39645 -1.46198,-0.71738l51.21444,-32.82196z M410.62615,207.97354c0,0 0,0 0,0z');
|
||||
});
|
||||
|
||||
test('PathItem#resolveCrossings()', function() {
|
||||
var paths = [
|
||||
'M100,300l0,-50l50,-50l-50,0l150,0l-150,0l50,0l-50,0l100,0l-100,0l0,-100l200,0l0,200z',
|
||||
'M50,300l0,-150l50,25l0,-75l200,0l0,200z M100,200l50,0l-50,-25z',
|
||||
'M330.1,388.5l-65,65c0,0 -49.1,-14.5 -36.6,-36.6c12.5,-22.1 92.4,25.1 92.4,25.1c0,0 -33.3,-73.3 -23.2,-85.9c10,-12.8 32.4,32.4 32.4,32.4z',
|
||||
'M570,290l5.8176000300452415,33.58556812220928l-28.17314339506561,-14.439003967264455l31.189735425395614,-4.568209255479985c-5.7225406635552645e-9,-3.907138079739525e-8 -59.366611385062015,8.695139599513823 -59.366611385062015,8.695139599513823z'
|
||||
];
|
||||
var results = [
|
||||
'M100,300l0,-50l50,-50l-50,0l0,-100l200,0l0,200z',
|
||||
'M50,300l0,-150l50,25l0,-75l200,0l0,200z M100,200l50,0l-50,-25z',
|
||||
'M291.85631,426.74369l-26.75631,26.75631c0,0 -49.1,-14.5 -36.6,-36.6c7.48773,-13.23831 39.16013,-1.61018 63.35631,9.84369z M330.1,388.5l-22.09831,22.09831c-8.06306,-21.54667 -15.93643,-47.46883 -10.30169,-54.49831c10,-12.8 32.4,32.4 32.4,32.4z M320.9,442c0,0 -12.84682,-7.58911 -29.04369,-15.25631l16.14539,-16.14539c6.38959,17.07471 12.89831,31.40169 12.89831,31.40169z',
|
||||
'M570,290l5.8176,33.58557l-28.17314,-14.439c-14.32289,2.0978 -28.17688,4.12693 -28.17688,4.12693z'
|
||||
];
|
||||
for (var i = 0; i < paths.length; i++) {
|
||||
var path = createPath(paths[i]),
|
||||
result = createPath(results[i]);
|
||||
path.fillRule = 'evenodd';
|
||||
compareBoolean(path.resolveCrossings(), result, 'path.resolveCrossings(); // Test ' + (i + 1));
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue