Fix shape.strokeBounds with strokeScaling is false

This commit is contained in:
sapics 2015-12-17 09:30:26 +09:00 committed by Jürg Lehni
parent 0e3ac9d7f4
commit 81a4d142f0
2 changed files with 23 additions and 4 deletions

View file

@ -270,10 +270,16 @@ var Shape = Item.extend(/** @lends Shape# */{
},
_getBounds: function(getter, matrix) {
var rect = new Rectangle(this._size).setCenter(0, 0);
if (getter !== 'getBounds' && this.hasStroke())
rect = rect.expand(this.getStrokeWidth());
return matrix ? matrix._transformBounds(rect) : rect;
var rect = new Rectangle(this._size).setCenter(0, 0),
expandStrokeWidth = getter !== 'getBounds' && this.hasStroke()
&& this.getStrokeWidth();
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.

View file

@ -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');
});
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() {
var text = new PointText(new Point(50, 100));
text.fillColor = 'black';