Fix multiple issues with boolean operations on open paths.

This commit is contained in:
Jürg Lehni 2016-01-08 15:17:58 +01:00
parent 9eb3e8777e
commit 66ff8d3a51
2 changed files with 13 additions and 14 deletions

View file

@ -68,6 +68,7 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
_setCurve: function(curve) {
var path = curve._path;
this._version = path ? path._version : 0;
this._path = path;
this._curve = curve;
this._segment = null; // To be determined, see #getSegment()
// Also store references to segment1 and segment2, in case path
@ -120,14 +121,13 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
* @bean
*/
getCurve: function() {
var curve = this._curve,
path = curve && curve._path,
path = this._path,
that = this;
if (path && path._version !== this._version) {
// If the path's segments have changed in the meantime, clear the
// internal _parameter value and force refetching of the correct
// curve again here.
curve = this._parameter = this._curve = this._offset = null;
this._parameter = this._curve = this._offset = null;
}
// If path is out of sync, access current curve objects through segment1
@ -145,21 +145,20 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
}
}
return curve
return this._curve
|| trySegment(this._segment)
|| trySegment(this._segment1)
|| trySegment(this._segment2.getPrevious());
},
/**
* The path this curve belongs to, if any.
* The path that this locations is situated on.
*
* @type Item
* @bean
*/
getPath: function() {
var curve = this.getCurve();
return curve && curve._path;
return this._path;
},
/**

View file

@ -73,20 +73,20 @@ PathItem.inject(new function() {
}
function computeBoolean(path1, path2, operation) {
// Retrieve the operator lookup table for winding numbers.
var operator = operators[operation];
// Add a simple boolean property to check for a given operation,
// e.g. `if (operator.unite)`
operator[operation] = true;
// If path1 is open, delegate to computeOpenBoolean()
if (!path1._children && !path1._closed)
return computeOpenBoolean(path1, path2, operation);
return computeOpenBoolean(path1, path2, operator);
// We do not modify the operands themselves, but create copies instead,
// fas produced by the calls to preparePath().
// Note that the result paths might not belong to the same type
// i.e. subtraction(A:Path, B:Path):CompoundPath etc.
var _path1 = preparePath(path1, true),
_path2 = path2 && path1 !== path2 && preparePath(path2, true),
// Retrieve the operator lookup table for winding numbers.
operator = operators[operation];
// Add a simple boolean property to check for a given operation,
// e.g. `if (operator.unite)`
operator[operation] = true;
_path2 = path2 && path1 !== path2 && preparePath(path2, true);
// Give both paths the same orientation except for subtraction
// and exclusion, where we need them at opposite orientation.
if (_path2 && (operator.subtract || operator.exclude)