From 81a4d142f0689046aa3b0d01a57d4c0f6b63aa7a Mon Sep 17 00:00:00 2001 From: sapics Date: Thu, 17 Dec 2015 09:30:26 +0900 Subject: [PATCH] Fix shape.strokeBounds with strokeScaling is false --- src/item/Shape.js | 14 ++++++++++---- test/tests/Item_Bounds.js | 13 +++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/item/Shape.js b/src/item/Shape.js index a9c2c75d..fd01c523 100644 --- a/src/item/Shape.js +++ b/src/item/Shape.js @@ -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. diff --git a/test/tests/Item_Bounds.js b/test/tests/Item_Bounds.js index 223190b4..c18c604c 100644 --- a/test/tests/Item_Bounds.js +++ b/test/tests/Item_Bounds.js @@ -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';