Boolean: Always return CompoundPath items.

Relates to #1221
This commit is contained in:
Jürg Lehni 2017-03-22 23:26:26 +01:00
parent 3c9d2eea1d
commit 15471c76ab
2 changed files with 31 additions and 15 deletions

View file

@ -61,12 +61,11 @@ PathItem.inject(new function() {
: res;
}
function createResult(ctor, paths, reduce, path1, path2, options) {
var result = new ctor(Item.NO_INSERT);
function createResult(paths, simplify, path1, path2, options) {
var result = new CompoundPath(Item.NO_INSERT);
result.addChildren(paths, true);
// See if the item can be reduced to just a simple Path.
if (reduce)
result = result.reduce({ simplify: true });
result = result.reduce({ simplify: simplify });
if (!(options && options.insert == false)) {
// Insert the resulting path above whichever of the two paths appear
// further up in the stack.
@ -157,7 +156,7 @@ PathItem.inject(new function() {
});
}
return createResult(CompoundPath, paths, true, path1, path2, options);
return createResult(paths, true, path1, path2, options);
}
function splitBoolean(path1, path2, subtract) {
@ -194,7 +193,7 @@ PathItem.inject(new function() {
}
// At the end, add what's left from our path after all the splitting.
addPath(_path1);
return createResult(CompoundPath, paths, true, path1, path2);
return createResult(paths, false, path1, path2);
}
/*
@ -1114,7 +1113,7 @@ PathItem.inject(new function() {
* @return {Group} the resulting group item
*/
divide: function(path, options) {
return createResult(Group, [
return createResult([
this.subtract(path, options),
this.intersect(path, options)
], true, this, path, options);

View file

@ -475,17 +475,34 @@ var compareBoolean = function(actual, expected, message, options) {
message = getFunctionMessage(actual);
actual = actual();
}
var style = {
strokeColor: 'black',
fillColor: expected && (expected.closed
|| expected.firstChild && expected.firstChild.closed && 'yellow')
|| null
};
if (actual)
var parent,
index,
style = {
strokeColor: 'black',
fillColor: expected && (expected.closed
|| expected.firstChild && expected.firstChild.closed && 'yellow')
|| null
};
if (actual) {
parent = actual.parent;
index = actual.index;
// Remove it from parent already now, in case we're comparing children
// of compound-paths, so we can apply styling to them.
if (parent && parent instanceof CompoundPath) {
actual.remove();
} else {
parent = null;
}
actual.style = style;
if (expected)
}
if (expected) {
expected.style = style;
}
equals(actual, expected, message, Base.set({ rasterize: true }, options));
if (parent) {
// Insert it back.
parent.insertChild(index, actual);
}
};
var createSVG = function(str, attrs) {