mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 10:48:38 -05:00
Fix shape.strokeBounds with strokeScaling is false
This commit is contained in:
parent
0e3ac9d7f4
commit
81a4d142f0
2 changed files with 23 additions and 4 deletions
|
@ -270,10 +270,16 @@ var Shape = Item.extend(/** @lends Shape# */{
|
||||||
},
|
},
|
||||||
|
|
||||||
_getBounds: function(getter, matrix) {
|
_getBounds: function(getter, matrix) {
|
||||||
var rect = new Rectangle(this._size).setCenter(0, 0);
|
var rect = new Rectangle(this._size).setCenter(0, 0),
|
||||||
if (getter !== 'getBounds' && this.hasStroke())
|
expandStrokeWidth = getter !== 'getBounds' && this.hasStroke()
|
||||||
rect = rect.expand(this.getStrokeWidth());
|
&& this.getStrokeWidth();
|
||||||
return matrix ? matrix._transformBounds(rect) : rect;
|
if (expandStrokeWidth && this.getStrokeScaling(true))
|
||||||
|
rect = rect.expand(expandStrokeWidth);
|
||||||
|
if (matrix)
|
||||||
|
rect = matrix._transformBounds(rect);
|
||||||
|
if (expandStrokeWidth && !this.getStrokeScaling(true))
|
||||||
|
rect = rect.expand(expandStrokeWidth);
|
||||||
|
return rect;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
new function() { // Scope for _contains() and _hitTestSelf() code.
|
new function() { // Scope for _contains() and _hitTestSelf() code.
|
||||||
|
|
|
@ -77,6 +77,19 @@ test('path.bounds when contained in a transformed group', function() {
|
||||||
equals(path.bounds, new Rectangle(110, 110, 50, 50), 'path.bounds after group translation');
|
equals(path.bounds, new Rectangle(110, 110, 50, 50), 'path.bounds after group translation');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('shape.strokeBounds when scale with strokeScaling is false', function(){
|
||||||
|
var shape = new Shape.Rectangle({
|
||||||
|
point: [5, 5],
|
||||||
|
size: [20, 20],
|
||||||
|
strokeScaling: false,
|
||||||
|
strokeColor: 'black',
|
||||||
|
strokeWidth: 10
|
||||||
|
});
|
||||||
|
equals(shape.getStrokeBounds(), new Rectangle(0, 0, 30, 30), 'shape.strokeBounds before scaling');
|
||||||
|
shape.scale(2, 2, [5, 5]);
|
||||||
|
equals(shape.getStrokeBounds(), new Rectangle(0, 0, 50, 50), 'shape.strokeBounds after scaling');
|
||||||
|
});
|
||||||
|
|
||||||
test('text.bounds', function() {
|
test('text.bounds', function() {
|
||||||
var text = new PointText(new Point(50, 100));
|
var text = new PointText(new Point(50, 100));
|
||||||
text.fillColor = 'black';
|
text.fillColor = 'black';
|
||||||
|
|
Loading…
Reference in a new issue