Go back to using Group for divide() results.

As they may contain multiple CompoundPaths.
This commit is contained in:
Jürg Lehni 2015-10-07 10:57:09 +02:00
parent 1103c7036f
commit bfa0459c52

View file

@ -53,10 +53,10 @@ PathItem.inject(new function() {
.transform(null, true, true); .transform(null, true, true);
} }
function finishBoolean(paths, path1, path2, reduce) { function finishBoolean(ctor, paths, path1, path2, reduce) {
var result = new CompoundPath(Item.NO_INSERT); var result = new ctor(Item.NO_INSERT);
result.addChildren(paths, true); result.addChildren(paths, true);
// See if the CompoundPath can be reduced to just a simple Path. // See if the item can be reduced to just a simple Path.
if (reduce) if (reduce)
result = result.reduce(); result = result.reduce();
// Insert the resulting path above whichever of the two paths appear // Insert the resulting path above whichever of the two paths appear
@ -143,8 +143,8 @@ PathItem.inject(new function() {
operation); operation);
} }
} }
return finishBoolean(tracePaths(segments, operation), path1, path2, return finishBoolean(CompoundPath, tracePaths(segments, operation),
true); path1, path2, true);
} }
function logIntersection(title, inter) { function logIntersection(title, inter) {
@ -855,7 +855,8 @@ PathItem.inject(new function() {
*/ */
exclude: function(path) { exclude: function(path) {
return computeBoolean(this, path, 'exclude'); return computeBoolean(this, path, 'exclude');
// return finishBoolean([this.subtract(path), path.subtract(this)], // return finishBoolean(CompoundPath,
// [this.subtract(path), path.subtract(this)],
// this, path, true); // this, path, true);
}, },
@ -867,7 +868,8 @@ PathItem.inject(new function() {
* @return {Group} the resulting group item * @return {Group} the resulting group item
*/ */
divide: function(path) { divide: function(path) {
return finishBoolean([this.subtract(path), this.intersect(path)], return finishBoolean(Group,
[this.subtract(path), this.intersect(path)],
this, path, true); this, path, true);
}, },
@ -891,8 +893,8 @@ PathItem.inject(new function() {
for (var i = 0, l = paths.length; i < l; i++) { for (var i = 0, l = paths.length; i < l; i++) {
segments.push.apply(segments, paths[i]._segments); segments.push.apply(segments, paths[i]._segments);
} }
var res = finishBoolean(tracePaths(segments), this, null, false) var res = finishBoolean(CompoundPath, tracePaths(segments),
.reorient(); this, null, false).reorient();
window.reportSegments = reportSegments; window.reportSegments = reportSegments;
window.reportWindings = reportWindings; window.reportWindings = reportWindings;
window.reportIntersections = reportIntersections; window.reportIntersections = reportIntersections;