mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Fix failing unit test, and some code cleanup.
This commit is contained in:
parent
288c3d4012
commit
13a68cec46
1 changed files with 14 additions and 14 deletions
|
@ -22,6 +22,7 @@ test('PathItem#create() with SVG path-data (#1101)', function() {
|
||||||
'M 0 1.5 l 1e1 0 m -10 2 l 1e+1 0 m -10 2 l 100e-1 0',
|
'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'
|
'M372 130Q272 50 422 10zm70 0q50-150-80-90z'
|
||||||
];
|
];
|
||||||
|
|
||||||
var expected = [
|
var expected = [
|
||||||
[[[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]],
|
||||||
[[[20,20],[40,40],[40,20],true], [[40,40],[20,60],[40,60],true]],
|
[[[20,20],[40,40],[40,20],true], [[40,40],[20,60],[40,60],true]],
|
||||||
|
@ -33,8 +34,6 @@ test('PathItem#create() with SVG path-data (#1101)', function() {
|
||||||
[[442,130,0,0,33.33333,-100],[362,40,86.66667,-40,0,0],true]]
|
[[442,130,0,0,33.33333,-100],[362,40,86.66667,-40,0,0],true]]
|
||||||
];
|
];
|
||||||
|
|
||||||
var formatter = new Formatter(5);
|
|
||||||
|
|
||||||
function describe(path) {
|
function describe(path) {
|
||||||
var res;
|
var res;
|
||||||
if (path.children) {
|
if (path.children) {
|
||||||
|
@ -45,11 +44,14 @@ test('PathItem#create() with SVG path-data (#1101)', function() {
|
||||||
res = path.segments.map(function(segment) {
|
res = path.segments.map(function(segment) {
|
||||||
var pt = segment.point,
|
var pt = segment.point,
|
||||||
hi = segment.handleIn,
|
hi = segment.handleIn,
|
||||||
ho = segment.handleOut;
|
ho = segment.handleOut,
|
||||||
|
multiplier = Math.pow(10, 5);
|
||||||
return (hi.isZero() && ho.isZero()
|
return (hi.isZero() && ho.isZero()
|
||||||
? [pt.x, pt.y]
|
? [pt.x, pt.y]
|
||||||
: [pt.x, pt.y, hi.x, hi.y, ho.x, ho.y])
|
: [pt.x, pt.y, hi.x, hi.y, ho.x, ho.y])
|
||||||
.map(function(x) { return formatter.number(x); });
|
.map(function(x) {
|
||||||
|
return Math.round(x * multiplier) / multiplier;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
if (path.closed)
|
if (path.closed)
|
||||||
res.push(true);
|
res.push(true);
|
||||||
|
@ -58,11 +60,12 @@ test('PathItem#create() with SVG path-data (#1101)', function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function create(data) {
|
function create(data) {
|
||||||
if (!data)
|
var first = data && data[0];
|
||||||
|
if (first == null)
|
||||||
return null;
|
return null;
|
||||||
var first = data[0],
|
if (Array.isArray(first[0])) {
|
||||||
peek = first && first[0];
|
return new CompoundPath(data.map(create));
|
||||||
if (typeof peek === 'number') {
|
} else {
|
||||||
var closed = data[data.length - 1];
|
var closed = data[data.length - 1];
|
||||||
if (typeof closed === 'boolean') {
|
if (typeof closed === 'boolean') {
|
||||||
data.length--;
|
data.length--;
|
||||||
|
@ -74,15 +77,12 @@ test('PathItem#create() with SVG path-data (#1101)', function() {
|
||||||
// when inserted into the compound-path.
|
// when inserted into the compound-path.
|
||||||
path.clockwise = path.clockwise;
|
path.clockwise = path.clockwise;
|
||||||
return path;
|
return path;
|
||||||
} else {
|
|
||||||
return new CompoundPath(data.map(create));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data.forEach(function(entry, i) {
|
data.forEach(function(entry, i) {
|
||||||
var item = PathItem.create(entry);
|
var path = PathItem.create(entry);
|
||||||
// console.log(JSON.stringify(describe(item)));
|
// console.log(JSON.stringify(describe(path)));
|
||||||
var compare = create(expected[i]);
|
equals(path, create(expected[i]), 'data[' + i + ']');
|
||||||
equals(item, compare, 'data[' + i + ']');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue