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

View file

@ -475,17 +475,34 @@ var compareBoolean = function(actual, expected, message, options) {
message = getFunctionMessage(actual); message = getFunctionMessage(actual);
actual = actual(); actual = actual();
} }
var style = { var parent,
strokeColor: 'black', index,
fillColor: expected && (expected.closed style = {
|| expected.firstChild && expected.firstChild.closed && 'yellow') strokeColor: 'black',
|| null fillColor: expected && (expected.closed
}; || expected.firstChild && expected.firstChild.closed && 'yellow')
if (actual) || 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; actual.style = style;
if (expected) }
if (expected) {
expected.style = style; expected.style = style;
}
equals(actual, expected, message, Base.set({ rasterize: true }, options)); equals(actual, expected, message, Base.set({ rasterize: true }, options));
if (parent) {
// Insert it back.
parent.insertChild(index, actual);
}
}; };
var createSVG = function(str, attrs) { var createSVG = function(str, attrs) {