Fix handling of negative Shape sizes (#1733)

This commit is contained in:
adroitwhiz 2019-11-09 12:17:26 -05:00 committed by Jürg Lehni
parent 43bbb249ab
commit 7dad1a495d
2 changed files with 24 additions and 1 deletions

View file

@ -90,7 +90,7 @@ var Shape = Item.extend(/** @lends Shape# */{
height = size.height;
if (type === 'rectangle') {
// Shrink radius accordingly
this._radius.set(Size.min(this._radius, size.divide(2)));
this._radius.set(Size.min(this._radius, size.divide(2).abs()));
} else if (type === 'circle') {
// Use average of width and height as new size, then calculate
// radius as a number from that:

View file

@ -53,3 +53,26 @@ test('shape.toPath().toShape()', function() {
equals(shape.toPath().toShape(), shape, name + '.toPath().toShape()');
});
});
test('Shape.Rectangle radius works with negative size', function() {
var shape = new Shape.Rectangle({
center: [50, 50],
size: 50,
fillColor: 'black'
});
shape.size = [-25, -25];
equals(shape.radius.width, 0);
equals(shape.radius.height, 0);
shape.radius = [10, 50];
shape.size = [50, -25];
equals(shape.radius.width, 10);
equals(shape.radius.height, 12.5);
shape.size = [50, 75];
equals(shape.radius.height, 12.5);
});