mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Merge pull request #84 from luckyvoice/merge
_length cache in Curve is not updated when the Path is transformed
This commit is contained in:
commit
10ae88e90c
3 changed files with 12 additions and 2 deletions
|
@ -1961,7 +1961,6 @@ function(name) {
|
|||
scale = (fill ? itemRatio > rectRatio : itemRatio < rectRatio)
|
||||
? rectangle.width / bounds.width
|
||||
: rectangle.height / bounds.height,
|
||||
delta = rectangle.getCenter().subtract(bounds.getCenter()),
|
||||
newBounds = new Rectangle(new Point(),
|
||||
Size.create(bounds.width * scale, bounds.height * scale));
|
||||
newBounds.setCenter(rectangle.getCenter());
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -38,6 +38,12 @@ 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;
|
||||
ok(path.curves[0]._length, 'Curve length does not appear to be cached');
|
||||
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 +59,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.');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue