Skip to content

Commit

Permalink
When a path is transformed, the _length cache of its Curves should be…
Browse files Browse the repository at this point in the history
… invalidated
  • Loading branch information
obeattie committed Mar 17, 2012
1 parent dcb141e commit b811420
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/path/Path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion test/tests/Path_Curves.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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.');
});
});

0 comments on commit b811420

Please sign in to comment.