2016-07-19 04:09:55 -04:00
|
|
|
/*
|
|
|
|
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
|
|
|
* http://paperjs.org/
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011 - 2016, Juerg Lehni & Jonathan Puckey
|
|
|
|
* http://scratchdisk.com/ & http://jonathanpuckey.com/
|
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
QUnit.module('PathItem');
|
|
|
|
|
|
|
|
test('PathItem#create() with SVG path-data (#1101)', function() {
|
|
|
|
var data = [
|
|
|
|
'M11 18V6l-8.5 6 8.5 6zm.5-6l8.5 6V6l-8.5 6z',
|
|
|
|
'M20 20l20 20v-20zm20 20l-20 20h20z',
|
|
|
|
'M11 18V6l-8.5 6 8.5 6zm.5-6l8.5 6V6l-8.5 6z',
|
|
|
|
'M11,18l0,-12l-8.5,6z M11.5,12l8.5,6l0,-12z',
|
|
|
|
'M10,10 L20,20 L10,30 M30,10 L30,30',
|
|
|
|
'M 0 1.5 l 1e1 0 m -10 2 l 1e+1 0 m -10 2 l 100e-1 0',
|
|
|
|
'M372 130Q272 50 422 10zm70 0q50-150-80-90z'
|
|
|
|
];
|
2016-07-19 04:24:37 -04:00
|
|
|
|
2016-07-19 04:09:55 -04:00
|
|
|
var expected = [
|
|
|
|
[[[11,18],[11,6],[2.5,12],true], [[11.5,12],[20,18],[20,6],true]],
|
|
|
|
[[[20,20],[40,40],[40,20],true], [[40,40],[20,60],[40,60],true]],
|
|
|
|
[[[11,18],[11,6],[2.5,12],true],[[11.5,12],[20,18],[20,6],true]],
|
|
|
|
[[[11,18],[11,6],[2.5,12],true],[[11.5,12],[20,18],[20,6],true]],
|
|
|
|
[[[10,10],[20,20],[10,30]],[[30,10],[30,30]]],
|
|
|
|
[[[0,1.5],[10,1.5]],[[0,3.5],[10,3.5]],[[0,5.5],[10,5.5]]],
|
|
|
|
[[[372,130,0,0,-66.66667,-53.33333],[422,10,-100,26.66667,0,0],true],
|
|
|
|
[[442,130,0,0,33.33333,-100],[362,40,86.66667,-40,0,0],true]]
|
|
|
|
];
|
|
|
|
|
|
|
|
function describe(path) {
|
|
|
|
var res;
|
|
|
|
if (path.children) {
|
|
|
|
res = path.children.map(function(child) {
|
|
|
|
return describe(child);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
res = path.segments.map(function(segment) {
|
|
|
|
var pt = segment.point,
|
|
|
|
hi = segment.handleIn,
|
2016-07-19 04:24:37 -04:00
|
|
|
ho = segment.handleOut,
|
|
|
|
multiplier = Math.pow(10, 5);
|
2016-07-19 04:09:55 -04:00
|
|
|
return (hi.isZero() && ho.isZero()
|
|
|
|
? [pt.x, pt.y]
|
|
|
|
: [pt.x, pt.y, hi.x, hi.y, ho.x, ho.y])
|
2016-07-19 04:24:37 -04:00
|
|
|
.map(function(x) {
|
|
|
|
return Math.round(x * multiplier) / multiplier;
|
|
|
|
});
|
2016-07-19 04:09:55 -04:00
|
|
|
});
|
|
|
|
if (path.closed)
|
|
|
|
res.push(true);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
data.forEach(function(entry, i) {
|
2016-07-19 04:24:37 -04:00
|
|
|
var path = PathItem.create(entry);
|
|
|
|
// console.log(JSON.stringify(describe(path)));
|
2016-07-19 07:08:21 -04:00
|
|
|
equals(path, PathItem.create(expected[i]), 'data[' + i + ']');
|
2016-07-19 04:09:55 -04:00
|
|
|
});
|
|
|
|
});
|