2015-06-16 12:38:57 -04:00
|
|
|
/*
|
|
|
|
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
|
|
|
* http://paperjs.org/
|
|
|
|
*
|
2020-05-23 16:24:42 -04:00
|
|
|
* Copyright (c) 2011 - 2020, Jürg Lehni & Jonathan Puckey
|
|
|
|
* http://juerglehni.com/ & https://puckey.studio/
|
2015-06-16 12:38:57 -04:00
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2016-01-27 13:57:07 -05:00
|
|
|
QUnit.module('Shape');
|
2015-06-16 12:38:57 -04:00
|
|
|
|
|
|
|
test('shape.toPath().toShape()', function() {
|
|
|
|
var shapes = {
|
|
|
|
circle: new Shape.Circle({
|
|
|
|
center: [100, 100],
|
|
|
|
radius: 50,
|
|
|
|
fillColor: 'red'
|
|
|
|
}),
|
|
|
|
|
|
|
|
ellipse: new Shape.Ellipse({
|
|
|
|
center: [100, 200],
|
|
|
|
radius: [50, 25],
|
|
|
|
fillColor: 'blue',
|
|
|
|
strokeColor: 'black',
|
|
|
|
strokeWidth: 4,
|
|
|
|
rotation: 20
|
|
|
|
}),
|
|
|
|
|
|
|
|
rect: new Shape.Rectangle({
|
|
|
|
center: [100, 300],
|
|
|
|
size: [100, 50],
|
|
|
|
fillColor: 'green',
|
|
|
|
strokeColor: 'black',
|
|
|
|
strokeWidth: 4,
|
|
|
|
rotation: -20
|
|
|
|
}),
|
|
|
|
|
|
|
|
roundRect: new Shape.Rectangle({
|
|
|
|
center: [100, 400],
|
|
|
|
size: [50, 100],
|
|
|
|
radius: [15, 20],
|
|
|
|
fillColor: 'orange',
|
|
|
|
strokeColor: 'black',
|
|
|
|
strokeWidth: 4,
|
|
|
|
rotation: 20
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
Base.each(shapes, function(shape, name) {
|
2015-12-26 15:46:36 -05:00
|
|
|
equals(shape.toPath().toShape(), shape, name + '.toPath().toShape()');
|
2015-06-16 12:38:57 -04:00
|
|
|
});
|
|
|
|
});
|
2019-11-09 12:17:26 -05:00
|
|
|
|
2019-12-15 08:31:31 -05:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2019-11-09 12:17:26 -05:00
|
|
|
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);
|
|
|
|
});
|