mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 09:22:22 -05:00
Fix handling of negative Shape sizes (#1733)
This commit is contained in:
parent
43bbb249ab
commit
7dad1a495d
2 changed files with 24 additions and 1 deletions
|
@ -90,7 +90,7 @@ var Shape = Item.extend(/** @lends Shape# */{
|
||||||
height = size.height;
|
height = size.height;
|
||||||
if (type === 'rectangle') {
|
if (type === 'rectangle') {
|
||||||
// Shrink radius accordingly
|
// 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') {
|
} else if (type === 'circle') {
|
||||||
// Use average of width and height as new size, then calculate
|
// Use average of width and height as new size, then calculate
|
||||||
// radius as a number from that:
|
// radius as a number from that:
|
||||||
|
|
|
@ -53,3 +53,26 @@ test('shape.toPath().toShape()', function() {
|
||||||
equals(shape.toPath().toShape(), shape, name + '.toPath().toShape()');
|
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);
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in a new issue