2011-07-01 06:17:45 -04:00
|
|
|
/*
|
|
|
|
* Paper.js
|
|
|
|
*
|
|
|
|
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
|
|
|
|
* based on Scriptographer.org and designed to be largely API compatible.
|
|
|
|
* http://paperjs.org/
|
|
|
|
* http://scriptographer.org/
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
|
|
|
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2011-05-21 14:33:08 -04:00
|
|
|
module('Symbol & Placed Symbol');
|
2011-02-26 07:48:31 -05:00
|
|
|
|
|
|
|
test('placedSymbol bounds', function() {
|
|
|
|
var path = new Path.Circle([50, 50], 50);
|
2011-05-18 14:08:52 -04:00
|
|
|
path.strokeColor = 'black';
|
2011-03-06 05:58:05 -05:00
|
|
|
path.strokeWidth = 1;
|
|
|
|
path.strokeCap = 'round';
|
|
|
|
path.strokeJoin = 'round';
|
|
|
|
compareRectangles(path.strokeBounds,
|
2011-03-06 10:11:18 -05:00
|
|
|
{ x: -0.5, y: -0.5, width: 101, height: 101 },
|
2011-12-20 16:04:55 -05:00
|
|
|
'Path initial bounds');
|
2011-02-26 07:48:31 -05:00
|
|
|
var symbol = new Symbol(path);
|
|
|
|
var placedSymbol = new PlacedSymbol(symbol);
|
2011-03-06 19:01:26 -05:00
|
|
|
|
2011-03-03 12:23:27 -05:00
|
|
|
compareRectangles(placedSymbol.bounds,
|
2011-02-26 07:48:31 -05:00
|
|
|
new Rectangle(-50.5, -50.5, 101, 101),
|
2011-12-20 16:04:55 -05:00
|
|
|
'PlacedSymbol initial bounds');
|
2011-03-06 19:01:26 -05:00
|
|
|
|
2011-03-06 16:26:38 -05:00
|
|
|
placedSymbol.scale(1, 0.5);
|
2011-03-03 12:23:27 -05:00
|
|
|
compareRectangles(placedSymbol.bounds,
|
2011-03-06 16:26:38 -05:00
|
|
|
{ x: -50.5, y: -25.25, width: 101, height: 50.5 },
|
2011-12-20 16:04:55 -05:00
|
|
|
'Bounds after scale');
|
2011-03-06 16:26:38 -05:00
|
|
|
|
2011-02-26 07:48:31 -05:00
|
|
|
placedSymbol.rotate(40);
|
2011-03-03 12:23:27 -05:00
|
|
|
compareRectangles(placedSymbol.bounds,
|
2011-12-20 16:04:55 -05:00
|
|
|
{ x: -41.96283, y: -37.79252, width: 83.92567, height: 75.58503 },
|
|
|
|
'Bounds after rotation');
|
2011-03-06 10:14:57 -05:00
|
|
|
});
|
2011-05-21 14:32:41 -04:00
|
|
|
|
2011-07-04 09:09:17 -04:00
|
|
|
test('bounds of group of symbol instances', function() {
|
|
|
|
var path = new Path.Circle(new Point(), 10);
|
|
|
|
var symbol = new Symbol(path);
|
|
|
|
var instances = [];
|
|
|
|
for (var i = 0; i < 10; i++) {
|
|
|
|
var instance = symbol.place(new Point(i * 20, 20));
|
|
|
|
instances.push(instance);
|
|
|
|
}
|
|
|
|
var group = new Group(instances);
|
|
|
|
compareRectangles(group.bounds,
|
|
|
|
{ x: -10, y: 10, width: 200, height: 20 },
|
|
|
|
'Group bounds');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('bounds of a symbol that contains a group of items', function() {
|
|
|
|
var path = new Path.Circle(new Point(), 10);
|
|
|
|
var path2 = path.clone();
|
2011-07-04 14:13:33 -04:00
|
|
|
path2.position.x += 20;
|
|
|
|
compareRectangles(path.bounds,
|
|
|
|
{ x: -10, y: -10, width: 20, height: 20 },
|
|
|
|
'path bounds');
|
|
|
|
compareRectangles(path2.bounds,
|
|
|
|
{ x: 10, y: -10, width: 20, height: 20 },
|
|
|
|
'path2 bounds');
|
2011-07-04 09:09:17 -04:00
|
|
|
var group = new Group(path, path2);
|
2011-07-04 14:13:33 -04:00
|
|
|
compareRectangles(group.bounds,
|
|
|
|
{ x: -10, y: -10, width: 40, height: 20 },
|
|
|
|
'Group bounds');
|
2011-07-04 09:09:17 -04:00
|
|
|
var symbol = new Symbol(group);
|
2011-07-04 14:13:33 -04:00
|
|
|
var instance = symbol.place(new Point(50, 50));
|
2011-07-04 09:09:17 -04:00
|
|
|
compareRectangles(instance.bounds,
|
2011-07-04 14:13:33 -04:00
|
|
|
{ x: 30, y: 40, width: 40, height: 20 },
|
2011-07-04 09:09:17 -04:00
|
|
|
'Instance bounds');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Changing the definition of a symbol should change the bounds of all instances of it.', function() {
|
|
|
|
var path = new Path.Circle(new Point(), 10);
|
|
|
|
var path2 = new Path.Circle(new Point(), 20);
|
|
|
|
var symbol = new Symbol(path);
|
|
|
|
var instance = symbol.place(new Point(0, 0));
|
|
|
|
compareRectangles(instance.bounds,
|
|
|
|
{ x: -10, y: -10, width: 20, height: 20 },
|
|
|
|
'Initial bounds');
|
|
|
|
symbol.definition = path2;
|
|
|
|
compareRectangles(instance.bounds,
|
|
|
|
{ x: -20, y: -20, width: 40, height: 40 },
|
|
|
|
'Bounds after changing symbol definition');
|
2011-07-04 15:23:40 -04:00
|
|
|
symbol.definition.scale(0.5, 0.5);
|
|
|
|
compareRectangles(instance.bounds,
|
|
|
|
{ x: -10, y: -10, width: 20, height: 20 },
|
|
|
|
'Bounds after modifying symbol definition');
|
2011-07-04 09:09:17 -04:00
|
|
|
});
|
|
|
|
|
2011-05-21 14:32:41 -04:00
|
|
|
test('Symbol definition selection', function() {
|
|
|
|
var path = new Path.Circle([50, 50], 50);
|
|
|
|
path.selected = true;
|
|
|
|
var symbol = new Symbol(path);
|
|
|
|
equals(function() {
|
2011-05-21 15:28:30 -04:00
|
|
|
return symbol.definition.selected == false;
|
2011-05-21 14:32:41 -04:00
|
|
|
}, true);
|
2011-05-21 15:31:41 -04:00
|
|
|
equals(function() {
|
|
|
|
return paper.project.selectedItems.length == 0;
|
|
|
|
}, true);
|
2011-06-03 16:27:18 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Symbol#place()', function() {
|
|
|
|
var path = new Path.Circle([50, 50], 50);
|
|
|
|
var symbol = new Symbol(path);
|
|
|
|
var placedSymbol = symbol.place();
|
|
|
|
equals(function() {
|
|
|
|
return placedSymbol.parent == paper.project.activeLayer;
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
equals(function() {
|
|
|
|
return placedSymbol.symbol == symbol;
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
equals(function() {
|
|
|
|
return placedSymbol.position.toString();
|
|
|
|
}, '{ x: 0, y: 0 }');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Symbol#place(position)', function() {
|
|
|
|
var path = new Path.Circle([50, 50], 50);
|
|
|
|
var symbol = new Symbol(path);
|
|
|
|
var placedSymbol = symbol.place(new Point(100, 100));
|
|
|
|
equals(function() {
|
|
|
|
return placedSymbol.position.toString();
|
|
|
|
}, '{ x: 100, y: 100 }');
|
|
|
|
});
|