When a path is transformed, the _length cache of its Curves should be invalidated

This commit is contained in:
Oliver Beattie 2012-03-17 17:08:06 +00:00
parent c2ac3cc158
commit 3c7563a3bf
2 changed files with 11 additions and 1 deletions

View file

@ -68,6 +68,11 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
delete this._length;
// Clockwise state becomes undefined as soon as geometry changes.
delete this._clockwise;
// Curves are no longer valid
if (this._curves != null) {
for (var i = 0; i < this._curves.length; i++)
this._curves[i]._changed(Change.GEOMETRY)
}
} else if (flags & ChangeFlag.STROKE) {
// TODO: We could preserve the purely geometric bounds that are not
// affected by stroke: _bounds.bounds and _bounds.handleBounds

View file

@ -38,6 +38,11 @@ test('path.curves Synchronisation', function() {
path.removeSegments(1, 2);
equals(path.segments.toString(), "{ point: { x: 0, y: 100 } },{ point: { x: 100, y: 100 } }", "path.segments: path.add(new Point(100, 100));\npath.removeSegments(1, 2);");
equals(path.curves.toString(), "{ point1: { x: 0, y: 100 }, point2: { x: 100, y: 100 } },{ point1: { x: 100, y: 100 }, point2: { x: 0, y: 100 } }", "path.curves: path.add(new Point(100, 100));\npath.removeSegments(1, 2);");
// Transform the path, and the curves length should be invalidated (first, force-cache the first segment's length by accessing it
path.curves[0].length;
path.scale(2, [0, 0]);
equals(path.curves[0].length, 200, 'Curve length should be updated when path is transformed')
});
test('path.flatten(maxDistance)', function() {
@ -53,4 +58,4 @@ test('path.flatten(maxDistance)', function() {
equals(function() {
return path.lastSegment.point.toString() != path.segments[path.segments.length - 2].point.toString();
}, true, 'The points of the last and before last segments should not be so close, that calling toString on them returns the same string value.');
});
});