From 2b62eb5cfa4f3db712d34c04a4e3f6e7bbed4f33 Mon Sep 17 00:00:00 2001 From: Samuel Asensi Date: Sun, 15 Dec 2019 14:31:31 +0100 Subject: [PATCH] Fix shape bounds when passing position in constructor (#1708) In some special circumstances, when position was passed in constructor and when position key was before size key, bounds were wrongly calculated. This ensure that when size is set, even the first time, bounds are properly recalculated. Closes #1686 --- src/item/Shape.js | 2 +- test/tests/Shape.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/item/Shape.js b/src/item/Shape.js index 594ceddb..63bf40e2 100644 --- a/src/item/Shape.js +++ b/src/item/Shape.js @@ -101,8 +101,8 @@ var Shape = Item.extend(/** @lends Shape# */{ this._radius._set(width / 2, height / 2); } this._size._set(width, height); - this._changed(/*#=*/Change.GEOMETRY); } + this._changed(/*#=*/Change.GEOMETRY); }, /** diff --git a/test/tests/Shape.js b/test/tests/Shape.js index 83c30bf7..a5f770d4 100644 --- a/test/tests/Shape.js +++ b/test/tests/Shape.js @@ -54,6 +54,14 @@ test('shape.toPath().toShape()', function() { }); }); +test('new Shape.Rectangle() with position set before size', function() { + var shape1 = new Shape.Rectangle({ + position: [0, 0], + size: new Size(100, 100) + }); + equals(shape1.bounds.width, 100); +}); + test('Shape.Rectangle radius works with negative size', function() { var shape = new Shape.Rectangle({ center: [50, 50],