Improve CompoundPath#reduce() to properly reduce suppaths.

Relates to #779
This commit is contained in:
Jürg Lehni 2015-09-12 11:43:41 +02:00
parent fb5f8c0115
commit 3da921a0b0
3 changed files with 13 additions and 7 deletions

View file

@ -131,16 +131,23 @@ var CompoundPath = PathItem.extend(/** @lends CompoundPath# */{
this._children[i].smooth();
},
// DOCS: reduce()
// TEST: reduce()
reduce: function reduce() {
if (this._children.length === 0) { // Replace with a simple empty Path
var children = this._children;
for (var i = children.length - 1; i >= 0; i--) {
var path = children[i].reduce();
if (path.isEmpty())
children.splice(i, 1);
}
if (children.length === 0) { // Replace with a simple empty Path
var path = new Path(Item.NO_INSERT);
path.insertAbove(this);
path.setStyle(this._style);
this.remove();
return path;
} else {
return reduce.base.call(this);
}
return reduce.base.call(this);
},
/**

View file

@ -885,7 +885,7 @@ statics: {
* @return {Boolean} {@true if the two lines are collinear}
*/
isCollinear: function(curve) {
return this.isStraight() && curve.isStraight()
return curve && this.isStraight() && curve.isStraight()
&& this.getVector().isCollinear(curve.getVector());
}
}), /** @lends Curve# */{

View file

@ -1001,10 +1001,9 @@ var Path = PathItem.extend(/** @lends Path# */{
reduce: function() {
var curves = this.getCurves();
for (var i = curves.length - 1; i >= 0; i--) {
var curve = curves[i],
next;
var curve = curves[i];
if (!curve.hasHandles() && (curve.getLength() === 0
|| (next = curve.getNext()) && curve.isCollinear(next)))
|| curve.isCollinear(curve.getNext())))
curve.remove();
}
return this;