Current Dev State

This commit is contained in:
Tim Lorsbach
2025-06-23 20:13:54 +02:00
parent b4f9bb277d
commit ded50edaa2
22617 changed files with 4345095 additions and 174 deletions

View File

@ -0,0 +1,267 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("Parsing eliptical arc commands", function() {
beforeEach(function() {
});
afterEach(function() {
});
it("should not work when badly declarated", function() {
assert.throw(function() {
new SVGPathData('A');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('A 30');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('A 30 50');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('A 30 50 0');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('A 30 50 0 0');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('A 30 50 0 0 1');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('A 30 50 0 0 1 162.55');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('A 30 50 0 0 1 A 30 50 0 0 1 162.55 162.45');
}, SyntaxError, 'Unterminated command at index 14.');
});
it("should not work with bad rX value", function() {
assert.throw(function() {
new SVGPathData('A,-30,50,0,0,1,162.55,162.45');
}, SyntaxError, 'Expected positive number, got "-30" at index "5"');
});
it("should not work with bad rY value", function() {
assert.throw(function() {
new SVGPathData('A,30,-50,0,0,1,162.55,162.45');
}, SyntaxError, 'Expected positive number, got "-50" at index "8"');
});
it("should not work with bad lArcFlag value", function() {
assert.throw(function() {
new SVGPathData('A,30,50,0,15,1,162.55,162.45');
}, SyntaxError, 'Expected a flag, got "15" at index "12"');
});
it("should not work with bad sweepFlag value", function() {
assert.throw(function() {
new SVGPathData('A,30,50,0,0,15,162.55,162.45');
}, SyntaxError, 'Expected a flag, got "15" at index "14"');
});
it("should work with comma separated coordinates", function() {
var commands = new SVGPathData('A,30,50,0,0,1,162.55,162.45').commands;
assert.equal(commands[0].type, SVGPathData.ARC);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].rX, '30');
assert.equal(commands[0].rY, '50');
assert.equal(commands[0].xRot, '0');
assert.equal(commands[0].lArcFlag, '0');
assert.equal(commands[0].sweepFlag, '1');
assert.equal(commands[0].x, '162.55');
assert.equal(commands[0].y, '162.45');
});
it("should work with space separated coordinates", function() {
var commands = new SVGPathData('A 30 50 0 0 1 162.55 162.45').commands;
assert.equal(commands[0].type, SVGPathData.ARC);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].rX, '30');
assert.equal(commands[0].rY, '50');
assert.equal(commands[0].xRot, '0');
assert.equal(commands[0].lArcFlag, '0');
assert.equal(commands[0].sweepFlag, '1');
assert.equal(commands[0].x, '162.55');
assert.equal(commands[0].y, '162.45');
});
it("should work with nested separated complexer coordinate pairs", function() {
var commands = new SVGPathData('A 30,50 0 0 1 162.55,162.45').commands;
assert.equal(commands[0].type, SVGPathData.ARC);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].rX, '30');
assert.equal(commands[0].rY, '50');
assert.equal(commands[0].xRot, '0');
assert.equal(commands[0].lArcFlag, '0');
assert.equal(commands[0].sweepFlag, '1');
assert.equal(commands[0].x, '162.55');
assert.equal(commands[0].y, '162.45');
});
it("should work with multiple pairs of coordinates", function() {
var commands = new SVGPathData(
'A 10.0032e-5,20.0032e-5 0 0 1 -30.0032e-5,-40.0032e-5\
50.0032e-5,60.0032e-5 0 1 0 -70.0032e-5,-80.0032e-5\
90.0032e-5,90.0032e-5 0 0 1 -80.0032e-5,-70.0032e-5').commands;
assert.equal(commands[0].type, SVGPathData.ARC);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].rX, '10.0032e-5');
assert.equal(commands[0].rY, '20.0032e-5');
assert.equal(commands[0].xRot, '0');
assert.equal(commands[0].lArcFlag, '0');
assert.equal(commands[0].sweepFlag, '1');
assert.equal(commands[0].x, '-30.0032e-5');
assert.equal(commands[0].y, '-40.0032e-5');
assert.equal(commands[1].type, SVGPathData.ARC);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].rX, '50.0032e-5');
assert.equal(commands[1].rY, '60.0032e-5');
assert.equal(commands[1].xRot, '0');
assert.equal(commands[1].lArcFlag, '1');
assert.equal(commands[1].sweepFlag, '0');
assert.equal(commands[1].x, '-70.0032e-5');
assert.equal(commands[1].y, '-80.0032e-5');
assert.equal(commands[2].type, SVGPathData.ARC);
assert.equal(commands[2].relative, false);
assert.equal(commands[2].rX, '90.0032e-5');
assert.equal(commands[2].rY, '90.0032e-5');
assert.equal(commands[2].xRot, '0');
assert.equal(commands[2].lArcFlag, '0');
assert.equal(commands[2].sweepFlag, '1');
assert.equal(commands[2].x, '-80.0032e-5');
assert.equal(commands[2].y, '-70.0032e-5');
});
it("should work with multiple declarated pairs of coordinates", function() {
var commands = new SVGPathData(
'A 10.0032e-5,20.0032e-5 0 0 1 -30.0032e-5,-40.0032e-5\
a50.0032e-5,60.0032e-5 0 1 0 -70.0032e-5,-80.0032e-5\
A90.0032e-5,90.0032e-5 0 0 1 -80.0032e-5,-70.0032e-5').commands;
assert.equal(commands[0].type, SVGPathData.ARC);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].rX, '10.0032e-5');
assert.equal(commands[0].rY, '20.0032e-5');
assert.equal(commands[0].xRot, '0');
assert.equal(commands[0].lArcFlag, '0');
assert.equal(commands[0].sweepFlag, '1');
assert.equal(commands[0].x, '-30.0032e-5');
assert.equal(commands[0].y, '-40.0032e-5');
assert.equal(commands[1].type, SVGPathData.ARC);
assert.equal(commands[1].relative, true);
assert.equal(commands[1].rX, '50.0032e-5');
assert.equal(commands[1].rY, '60.0032e-5');
assert.equal(commands[1].xRot, '0');
assert.equal(commands[1].lArcFlag, '1');
assert.equal(commands[1].sweepFlag, '0');
assert.equal(commands[1].x, '-70.0032e-5');
assert.equal(commands[1].y, '-80.0032e-5');
assert.equal(commands[2].type, SVGPathData.ARC);
assert.equal(commands[2].relative, false);
assert.equal(commands[2].rX, '90.0032e-5');
assert.equal(commands[2].rY, '90.0032e-5');
assert.equal(commands[2].xRot, '0');
assert.equal(commands[2].lArcFlag, '0');
assert.equal(commands[2].sweepFlag, '1');
assert.equal(commands[2].x, '-80.0032e-5');
assert.equal(commands[2].y, '-70.0032e-5');
});
});
describe("Encoding eliptical arc commands", function() {
it("should work with one command", function() {
assert.equal(
new SVGPathData('A30 50 0 0 1 162.55 162.45').encode(),
'A30 50 0 0 1 162.55 162.45'
);
});
it("should work with several commands", function() {
assert.equal(
new SVGPathData('A30 50 0 0 1 162.55 162.45A30 50 0 0 1 162.55 162.45A30 50 0 0 1 162.55 162.45').encode(),
'A30 50 0 0 1 162.55 162.45A30 50 0 0 1 162.55 162.45A30 50 0 0 1 162.55 162.45'
);
});
});
describe("Transforming elliptical arc commands", function() {
function assertDeepCloseTo(x, y, delta) {
if(typeof x === 'number' && typeof y === 'number') {
assert.closeTo(x, y, delta);
} else if(typeof x === 'object' && typeof y === 'object') {
var keys = Object.getOwnPropertyNames(x);
assert.sameMembers(keys, Object.getOwnPropertyNames(y));
for(var i = 0; i < keys.length; i++) {
assertDeepCloseTo(x[keys[i]], y[keys[i]], delta);
}
} else if(typeof x === 'array' && typeof y === 'array') {
assert.equal(x.length, y.length, 'arrays have different lengths');
for(var i = 0; i < x.length; i++) {
assertDeepCloseTo(x[i], y[i], delta);
}
} else {
assert.equal(x, y);
}
}
it("should rotate an axis-aligned arc", function() {
assertDeepCloseTo(
new SVGPathData('M 0,0 A 100,50 0 0 1 100,50z').rotate(Math.PI/6).commands,
new SVGPathData('M 0,0 A 100,50 30 0 1 61.6,93.3z').commands,
0.1
);
});
it("should rotate an arbitrary arc", function() {
assertDeepCloseTo(
new SVGPathData('M 0,0 A 100,50 -15 0 1 100,0z').rotate(Math.PI/4).commands,
new SVGPathData('M 0,0 A 100,50 30 0 1 70.7,70.7z').commands,
0.1
);
});
it("should skew", function() {
assertDeepCloseTo(
new SVGPathData('M 0,0 A 50,100 0 0 1 50,100z').skewX(Math.tan(-1)).commands,
new SVGPathData('M 0,0 A 34.2,146.0 48.6 0 1 -50,100 Z').commands,
0.1
);
});
it("should tolerate singular matrices", function() {
assertDeepCloseTo(
new SVGPathData('M 0,0 A 80,80 0 0 1 50,100z').matrix(0.8,2,0.5,1.25,0,0).commands,
new SVGPathData('M 0,0 L 90,225 Z').commands,
0.1
);
});
it("should match what Inkscape does on this random case", function() {
assertDeepCloseTo(
new SVGPathData('M 170.19275,911.55263 A 61.42857,154.28572 21.033507 0 1 57.481868,1033.5109 61.42857,154.28572 21.033507 0 1 55.521508,867.4575 61.42857,154.28572 21.033507 0 1 168.2324,745.4993 A 61.42857,154.28572 21.033507 0 1 170.19275,911.55263 z').matrix(-0.10825745,-0.37157241,0.77029181,0.3345653,-560.10375,633.84215).commands,
new SVGPathData('M 123.63314,875.5771 A 135.65735,17.465974 30.334289 0 1 229.77839,958.26036 135.65735,17.465974 30.334289 0 1 102.08104,903.43307 135.65735,17.465974 30.334289 0 1 -4.0641555,820.74983 135.65735,17.465974 30.334289 0 1 123.63314,875.5771 z').commands,
0.0001
);
});
it("should reflect the sweep flag any time the determinant is negative", function() {
assertDeepCloseTo(
new SVGPathData('M 0,0 A 50,100 -30 1 1 80,80 Z').matrix(-1,0,0,1,0,0).commands,
new SVGPathData('M 0,0 A 50,100 30 1 0 -80,80 Z').commands,
0.1
);
});
});

View File

@ -0,0 +1,53 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
// Sample pathes from MDN
// https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths
// Here we have to round output before testing since there is some lil
// differences across browsers.
describe("Converting eliptical arc commands to curves", function() {
it("should work sweepFlag on 0 and largeArcFlag on 0", function() {
assert.equal(
new SVGPathData('M80 80 A 45 45, 0, 0, 0, 125 125 L 125 80 Z').aToC()
.round().encode(),
'M80 80C80 104.8528137423857 100.1471862576143 125 125 125L125 80z'
);
});
it("should work sweepFlag on 1 and largeArcFlag on 0", function() {
assert.equal(
new SVGPathData('M230 80 A 45 45, 0, 1, 0, 275 125 L 275 80 Z').aToC()
.round().encode(),
'M230 80C195.3589838486225 80 173.7083487540115 117.5 191.0288568297003 147.5C208.349364905389 177.5 251.650635094611 177.5 268.9711431702998 147.5C272.9207180979216 140.6591355570587 275 132.8991498552438 275 125L275 80z'
);
});
it("should work sweepFlag on 0 and largeArcFlag on 1", function() {
assert.equal(
new SVGPathData('M80 230 A 45 45, 0, 0, 1, 125 275 L 125 230 Z').aToC()
.round().encode(),
'M80 230C104.8528137423857 230 125 250.1471862576143 125 275L125 230z'
);
});
it("should work sweepFlag on 1 and largeArcFlag on 1", function() {
assert.equal(
new SVGPathData('M230 230 A 45 45, 0, 1, 1, 275 275 L 275 230 Z').aToC()
.round().encode(),
'M230 230C230 195.3589838486225 267.5 173.7083487540115 297.5 191.0288568297003C327.5 208.349364905389 327.5 251.650635094611 297.5 268.9711431702998C290.6591355570588 272.9207180979216 282.8991498552438 275 275 275L275 230z'
);
});
});

View File

@ -0,0 +1,63 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("Parsing close path commands", function() {
it("should work", function() {
var commands = new SVGPathData('Z').commands;
assert.equal(commands[0].type, SVGPathData.CLOSE_PATH);
});
it("should work with spaces before", function() {
var commands = new SVGPathData(' Z').commands;
assert.equal(commands[0].type, SVGPathData.CLOSE_PATH);
});
it("should work with spaces after", function() {
var commands = new SVGPathData('Z ').commands;
assert.equal(commands[0].type, SVGPathData.CLOSE_PATH);
});
it("should work before a command sequence", function() {
var commands = new SVGPathData(' Z M10,10 L10,10, H10, V10').commands;
assert.equal(commands[0].type, SVGPathData.CLOSE_PATH);
});
it("should work after a command sequence", function() {
var commands = new SVGPathData('M10,10 L10,10, H10, V10 Z').commands;
assert.equal(commands[4].type, SVGPathData.CLOSE_PATH);
});
it("should work in a command sequence", function() {
var commands = new SVGPathData('M10,10 L10,10, H10, V10 Z M10,10 L10,10, H10, V10').commands;
assert.equal(commands[4].type, SVGPathData.CLOSE_PATH);
});
});
describe("Encoding close path commands", function() {
it("should work with one command", function() {
assert.equal(
new SVGPathData('z').encode(),
'z'
);
});
it("should work with several commands", function() {
assert.equal(
new SVGPathData('zzzz').encode(),
'zzzz'
);
});
});

View File

@ -0,0 +1,168 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("Parsing curve to commands", function() {
beforeEach(function() {
});
afterEach(function() {
});
it("should not work when badly declarated", function() {
assert.throw(function() {
new SVGPathData('C');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('C10');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('C10 10');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('C10 10 10');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('C10 10 10 10');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('C10 10 10 10 10');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('C10 10 10 10 10 10 10 10');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('C10 10 10C10 10 10 10 10 10');
}, SyntaxError, 'Unterminated command at index 9.');
});
it("should work with comma separated coordinates", function() {
var commands = new SVGPathData('C123,456 789,987 654,321').commands;
assert.equal(commands[0].type, SVGPathData.CURVE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x2, '123');
assert.equal(commands[0].y2, '456');
assert.equal(commands[0].x1, '789');
assert.equal(commands[0].y1, '987');
assert.equal(commands[0].x, '654');
assert.equal(commands[0].y, '321');
});
it("should work with space separated coordinates", function() {
var commands = new SVGPathData('C123 456 789 987 654 321').commands;
assert.equal(commands[0].type, SVGPathData.CURVE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x2, '123');
assert.equal(commands[0].y2, '456');
assert.equal(commands[0].x1, '789');
assert.equal(commands[0].y1, '987');
assert.equal(commands[0].x, '654');
assert.equal(commands[0].y, '321');
});
it("should work with nested separated complexer coordinate pairs", function() {
var commands = new SVGPathData(
'C-10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5 -50.0032e-5,-60.0032e-5'
).commands;
assert.equal(commands[0].type, SVGPathData.CURVE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x2, '-10.0032e-5');
assert.equal(commands[0].y2, '-20.0032e-5');
assert.equal(commands[0].x1, '-30.0032e-5');
assert.equal(commands[0].y1, '-40.0032e-5');
assert.equal(commands[0].x, '-50.0032e-5');
assert.equal(commands[0].y, '-60.0032e-5');
});
it("should work with multiple pairs of coordinates", function() {
var commands = new SVGPathData('\
C-10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5 -50.0032e-5,-60.0032e-5\
-10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5 -50.0032e-5,-60.0032e-5\
-10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5 -50.0032e-5,-60.0032e-5'
).commands;
assert.equal(commands[0].type, SVGPathData.CURVE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x2, '-10.0032e-5');
assert.equal(commands[0].y2, '-20.0032e-5');
assert.equal(commands[0].x1, '-30.0032e-5');
assert.equal(commands[0].y1, '-40.0032e-5');
assert.equal(commands[0].x, '-50.0032e-5');
assert.equal(commands[0].y, '-60.0032e-5');
assert.equal(commands[1].type, SVGPathData.CURVE_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x2, '-10.0032e-5');
assert.equal(commands[1].y2, '-20.0032e-5');
assert.equal(commands[1].x1, '-30.0032e-5');
assert.equal(commands[1].y1, '-40.0032e-5');
assert.equal(commands[1].x, '-50.0032e-5');
assert.equal(commands[1].y, '-60.0032e-5');
assert.equal(commands[2].type, SVGPathData.CURVE_TO);
assert.equal(commands[2].relative, false);
assert.equal(commands[2].x2, '-10.0032e-5');
assert.equal(commands[2].y2, '-20.0032e-5');
assert.equal(commands[2].x1, '-30.0032e-5');
assert.equal(commands[2].y1, '-40.0032e-5');
assert.equal(commands[2].x, '-50.0032e-5');
assert.equal(commands[2].y, '-60.0032e-5');
});
it("should work with multiple declarated pairs of coordinates", function() {
var commands = new SVGPathData('\
C-10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5 -50.0032e-5,-60.0032e-5\
c-10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5 -50.0032e-5,-60.0032e-5\
C-10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5 -50.0032e-5,-60.0032e-5'
).commands;
assert.equal(commands[0].type, SVGPathData.CURVE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x2, '-10.0032e-5');
assert.equal(commands[0].y2, '-20.0032e-5');
assert.equal(commands[0].x1, '-30.0032e-5');
assert.equal(commands[0].y1, '-40.0032e-5');
assert.equal(commands[0].x, '-50.0032e-5');
assert.equal(commands[0].y, '-60.0032e-5');
assert.equal(commands[1].type, SVGPathData.CURVE_TO);
assert.equal(commands[1].relative, true);
assert.equal(commands[1].x2, '-10.0032e-5');
assert.equal(commands[1].y2, '-20.0032e-5');
assert.equal(commands[1].x1, '-30.0032e-5');
assert.equal(commands[1].y1, '-40.0032e-5');
assert.equal(commands[1].x, '-50.0032e-5');
assert.equal(commands[1].y, '-60.0032e-5');
assert.equal(commands[2].type, SVGPathData.CURVE_TO);
assert.equal(commands[2].relative, false);
assert.equal(commands[2].x2, '-10.0032e-5');
assert.equal(commands[2].y2, '-20.0032e-5');
assert.equal(commands[2].x1, '-30.0032e-5');
assert.equal(commands[2].y1, '-40.0032e-5');
assert.equal(commands[2].x, '-50.0032e-5');
assert.equal(commands[2].y, '-60.0032e-5');
});
});
describe("Encoding curve to commands", function() {
it("should work with one command", function() {
assert.equal(
new SVGPathData('C-10.0032e-5 -20.0032e-5 -30.0032e-5 -40.0032e-5 -50.0032e-5 -60.0032e-5').encode(),
'C-0.000100032 -0.000200032 -0.000300032 -0.000400032 -0.000500032 -0.000600032'
);
});
it("should work with several commands", function() {
assert.equal(
new SVGPathData('C-10.0032e-5 -20.0032e-5 -30.0032e-5 -40.0032e-5 -50.0032e-5 -60.0032e-5C-10.0032e-5 -20.0032e-5 -30.0032e-5 -40.0032e-5 -50.0032e-5 -60.0032e-5C-10.0032e-5 -20.0032e-5 -30.0032e-5 -40.0032e-5 -50.0032e-5 -60.0032e-5').encode(),
'C-0.000100032 -0.000200032 -0.000300032 -0.000400032 -0.000500032 -0.000600032C-0.000100032 -0.000200032 -0.000300032 -0.000400032 -0.000500032 -0.000600032C-0.000100032 -0.000200032 -0.000300032 -0.000400032 -0.000500032 -0.000600032'
);
});
});

View File

@ -0,0 +1,33 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("SVGPathDataEncoder", function() {
it("should still work when the new operator is forgotten", function() {
assert.doesNotThrow(function() {
SVGPathData.Encoder();
});
});
it("should fail when a bad command is given", function() {
assert.throws(function() {
var encoder = new SVGPathData.Encoder();
encoder.write({
type: 'plop',
x: 0,
y: 0
});
}, 'Unexpected command type "plop" at index 0.');
});
});

View File

@ -0,0 +1,258 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("Parsing horizontal commands", function() {
beforeEach(function() {
});
afterEach(function() {
});
it("should work with single coordinate", function() {
var commands = new SVGPathData('H100').commands;
assert.equal(commands[0].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, '100');
});
it("should work with single complexer coordinate", function() {
var commands = new SVGPathData('H-10e-5').commands;
assert.equal(commands[0].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, '-10e-5');
});
it("should work with single even more complexer coordinate", function() {
var commands = new SVGPathData('H-10.0032e-5').commands;
assert.equal(commands[0].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, '-10.0032e-5');
});
it("should work with single relative coordinate", function() {
var commands = new SVGPathData('h100').commands;
assert.equal(commands[0].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].x, '100');
});
it("should work with comma separated coordinates", function() {
var commands = new SVGPathData('H123,456,7890,9876').commands;
assert.equal(commands[0].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[0].x, '123');
assert.equal(commands[1].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[1].x, '456');
assert.equal(commands[2].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[2].x, '7890');
assert.equal(commands[3].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[3].x, '9876');
});
it("should work with space separated coordinates", function() {
var commands = new SVGPathData('H123 456 7890 9876').commands;
assert.equal(commands[0].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[0].x, '123');
assert.equal(commands[1].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[1].x, '456');
assert.equal(commands[2].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[2].x, '7890');
assert.equal(commands[3].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[3].x, '9876');
});
it("should work with nested separated coordinates", function() {
var commands = new SVGPathData('H123 , 456 \t,\n7890 \r\n 9876').commands;
assert.equal(commands[0].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[0].x, '123');
assert.equal(commands[1].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[1].x, '456');
assert.equal(commands[2].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[2].x, '7890');
assert.equal(commands[3].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[3].x, '9876');
});
it("should work with multiple command declarations", function() {
var commands = new SVGPathData('H123 , 456 \t,\n7890 \r\n 9876H123 , \
456 \t,\n7890 \r\n 9876').commands;
assert.equal(commands[0].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[0].x, '123');
assert.equal(commands[1].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[1].x, '456');
assert.equal(commands[2].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[2].x, '7890');
assert.equal(commands[3].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[3].x, '9876');
assert.equal(commands[4].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[4].x, '123');
assert.equal(commands[5].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[5].x, '456');
assert.equal(commands[6].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[6].x, '7890');
assert.equal(commands[7].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[7].x, '9876');
});
});
describe("Parsing vertical commands", function() {
beforeEach(function() {
});
afterEach(function() {
});
it("should work with single coordinate", function() {
var commands = new SVGPathData('V100').commands;
assert.equal(commands[0].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].y, '100');
});
it("should work with single complexer coordinate", function() {
var commands = new SVGPathData('V-10e-5').commands;
assert.equal(commands[0].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].y, '-10e-5');
});
it("should work with single even more complexer coordinate", function() {
var commands = new SVGPathData('V-10.0032e-5').commands;
assert.equal(commands[0].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].y, '-10.0032e-5');
});
it("should work with single relative coordinate", function() {
var commands = new SVGPathData('v100').commands;
assert.equal(commands[0].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].y, '100');
});
it("should work with comma separated coordinates", function() {
var commands = new SVGPathData('V123,456,7890,9876').commands;
assert.equal(commands[0].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[0].y, '123');
assert.equal(commands[1].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[1].y, '456');
assert.equal(commands[2].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[2].y, '7890');
assert.equal(commands[3].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[3].y, '9876');
});
it("should work with space separated coordinates", function() {
var commands = new SVGPathData('V123 456 7890 9876').commands;
assert.equal(commands[0].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[0].y, '123');
assert.equal(commands[1].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[1].y, '456');
assert.equal(commands[2].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[2].y, '7890');
assert.equal(commands[3].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[3].y, '9876');
});
it("should work with nested separated coordinates", function() {
var commands = new SVGPathData('V123 , 456 \t,\n7890 \r\n 9876').commands;
assert.equal(commands[0].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[0].y, '123');
assert.equal(commands[1].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[1].y, '456');
assert.equal(commands[2].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[2].y, '7890');
assert.equal(commands[3].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[3].y, '9876');
});
it("should work with multiple command declarations", function() {
var commands = new SVGPathData('V123 , 456 \t,\n7890 \r\n\
9876V123 , 456 \t,\n7890 \r\n 9876').commands;
assert.equal(commands[0].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[0].y, '123');
assert.equal(commands[1].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[1].y, '456');
assert.equal(commands[2].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[2].y, '7890');
assert.equal(commands[3].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[3].y, '9876');
assert.equal(commands[4].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[4].y, '123');
assert.equal(commands[5].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[5].y, '456');
assert.equal(commands[6].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[6].y, '7890');
assert.equal(commands[7].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[7].y, '9876');
});
});
describe("Parsing nested vertical/horizontal commands", function() {
beforeEach(function() {
});
afterEach(function() {
});
it("should work", function() {
var commands = new SVGPathData(
'V100H100v0.12h0.12,V100,h100v-10e-5 H-10e-5').commands;
assert.equal(commands[0].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].y, '100');
assert.equal(commands[1].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x, '100');
assert.equal(commands[2].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[2].relative, true);
assert.equal(commands[2].y, '0.12');
assert.equal(commands[3].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[3].relative, true);
assert.equal(commands[3].x, '0.12');
assert.equal(commands[4].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[4].relative, false);
assert.equal(commands[4].y, '100');
assert.equal(commands[5].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[5].relative, true);
assert.equal(commands[5].x, '100');
assert.equal(commands[6].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[6].relative, true);
assert.equal(commands[6].y, '-10e-5');
assert.equal(commands[7].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[7].relative, false);
assert.equal(commands[7].x, '-10e-5');
});
});
describe("Encoding nested vertical/horizontal commands", function() {
beforeEach(function() {
});
afterEach(function() {
});
it("should work", function() {
assert.equal(
new SVGPathData('V100H100v0.12h0.12V100h100v-10e-5H-10e-5').encode(),
'V100H100v0.12h0.12V100h100v-0.0001H-0.0001'
);
});
});

View File

@ -0,0 +1,146 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("Parsing line to commands", function() {
beforeEach(function() {
});
afterEach(function() {
});
it("should not work with single coordinate", function() {
assert.throw(function() {
new SVGPathData('L100');
}, SyntaxError, 'Unterminated command at the path end.');
});
it("should not work with single complexer coordinate", function() {
assert.throw(function() {
new SVGPathData('l-10e-5');
}, SyntaxError, 'Unterminated command at the path end.');
});
it("should work with single coordinate followed by another", function() {
assert.throw(function() {
new SVGPathData('l-10l10 10');
}, SyntaxError, 'Unterminated command at index 4.');
});
it("should work with comma separated coordinates", function() {
var commands = new SVGPathData('L100,100').commands;
assert.equal(commands[0].type, SVGPathData.LINE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, '100');
assert.equal(commands[0].y, '100');
});
it("should work with space separated coordinates", function() {
var commands = new SVGPathData('l100 \t 100').commands;
assert.equal(commands[0].type, SVGPathData.LINE_TO);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].x, '100');
assert.equal(commands[0].y, '100');
});
it("should work with complexer coordinates", function() {
var commands = new SVGPathData('l-10e-5 -10e-5').commands;
assert.equal(commands[0].type, SVGPathData.LINE_TO);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].x, '-10e-5');
assert.equal(commands[0].y, '-10e-5');
});
it("should work with single even more complexer coordinates", function() {
var commands = new SVGPathData('L-10.0032e-5 -10.0032e-5').commands;
assert.equal(commands[0].type, SVGPathData.LINE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, '-10.0032e-5');
assert.equal(commands[0].y, '-10.0032e-5');
});
it("should work with comma separated coordinate pairs", function() {
var commands = new SVGPathData('L123,456 7890,9876').commands;
assert.equal(commands[0].type, SVGPathData.LINE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, '123');
assert.equal(commands[0].y, '456');
assert.equal(commands[1].type, SVGPathData.LINE_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x, '7890');
assert.equal(commands[1].y, '9876');
});
it("should work with space separated coordinate pairs", function() {
var commands = new SVGPathData('l123 \t 456 \n 7890 \r 9876').commands;
assert.equal(commands[0].type, SVGPathData.LINE_TO);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].x, '123');
assert.equal(commands[0].y, '456');
assert.equal(commands[1].type, SVGPathData.LINE_TO);
assert.equal(commands[1].relative, true);
assert.equal(commands[1].x, '7890');
assert.equal(commands[1].y, '9876');
});
it("should work with nested separated coordinates", function() {
var commands = new SVGPathData('L123 , 456 \t,\n7890 \r\n 9876').commands;
assert.equal(commands[0].type, SVGPathData.LINE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, '123');
assert.equal(commands[0].y, '456');
assert.equal(commands[1].type, SVGPathData.LINE_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x, '7890');
assert.equal(commands[1].y, '9876');
});
it("should work with multiple command declarations", function() {
var commands = new SVGPathData('L123 , 456 \t,\n7890 \r\n 9876l123 , \
456 \t,\n7890 \r\n 9876').commands;
assert.equal(commands[0].type, SVGPathData.LINE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, '123');
assert.equal(commands[0].y, '456');
assert.equal(commands[1].type, SVGPathData.LINE_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x, '7890');
assert.equal(commands[1].y, '9876');
assert.equal(commands[2].type, SVGPathData.LINE_TO);
assert.equal(commands[2].relative, true);
assert.equal(commands[2].x, '123');
assert.equal(commands[2].y, '456');
assert.equal(commands[3].type, SVGPathData.LINE_TO);
assert.equal(commands[3].relative, true);
assert.equal(commands[3].x, '7890');
assert.equal(commands[3].y, '9876');
});
});
describe("Encoding line to commands", function() {
it("should work with one command", function() {
assert.equal(
new SVGPathData('L-0.000500032 -0.000600032').encode(),
'L-0.000500032 -0.000600032'
);
});
it("should work with several commands", function() {
assert.equal(
new SVGPathData('L-50.0032e-5 -60.0032e-5L-50.0032e-5 -60.0032e-5L-50.0032e-5 -60.0032e-5').encode(),
'L-0.000500032 -0.000600032L-0.000500032 -0.000600032L-0.000500032 -0.000600032'
);
});
});

View File

@ -0,0 +1,62 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("Matrix transformation should be the same than it's equivalent transformation", function() {
it("should fail with bad args", function() {
assert.throws(function() {
new SVGPathData(
'm20,30l10,10z'
).matrix().encode();
}, 'A matrix transformation requires parameters [a,b,c,d,e,f]'
+' to be set and to be numbers.');
assert.throws(function() {
new SVGPathData(
'm20,30l10,10z'
).matrix(1).encode();
}, 'A matrix transformation requires parameters [a,b,c,d,e,f]'
+' to be set and to be numbers.');
assert.throws(function() {
new SVGPathData(
'm20,30l10,10z'
).matrix(1, 1).encode();
}, 'A matrix transformation requires parameters [a,b,c,d,e,f]'
+' to be set and to be numbers.');
assert.throws(function() {
new SVGPathData(
'm20,30l10,10z'
).matrix(1, 1, 1).encode();
}, 'A matrix transformation requires parameters [a,b,c,d,e,f]'
+' to be set and to be numbers.');
assert.throws(function() {
new SVGPathData(
'm20,30l10,10z'
).matrix(1, 1, 1, 1).encode();
}, 'A matrix transformation requires parameters [a,b,c,d,e,f]'
+' to be set and to be numbers.');
assert.throws(function() {
new SVGPathData(
'm20,30l10,10z'
).matrix(1, 1, 1, 1, 1).encode();
}, 'A matrix transformation requires parameters [a,b,c,d,e,f]'
+' to be set and to be numbers.');
});
it("for scale", function() {
assert.equal(
new SVGPathData('m20 30c0 0 10 20 15 30z').scale(10, 10).encode(),
new SVGPathData('m20 30c0 0 10 20 15 30z').matrix(10, 0, 0, 10, 0, 0).encode()
);
});
});

View File

@ -0,0 +1,146 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("Parsing move to commands", function() {
beforeEach(function() {
});
afterEach(function() {
});
it("should not work with single coordinate", function() {
assert.throw(function() {
new SVGPathData('M100');
}, SyntaxError, 'Unterminated command at the path end.');
});
it("should work with single complexer coordinate", function() {
assert.throw(function() {
new SVGPathData('m-10e-5');
}, SyntaxError, 'Unterminated command at the path end.');
});
it("should work with single coordinate followed by another", function() {
assert.throw(function() {
new SVGPathData('m-10m10 10');
}, SyntaxError, 'Unterminated command at index 4.');
});
it("should work with comma separated coordinates", function() {
var commands = new SVGPathData('M100,100').commands;
assert.equal(commands[0].type, SVGPathData.MOVE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, '100');
assert.equal(commands[0].y, '100');
});
it("should work with space separated coordinates", function() {
var commands = new SVGPathData('m100 \t 100').commands;
assert.equal(commands[0].type, SVGPathData.MOVE_TO);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].x, '100');
assert.equal(commands[0].y, '100');
});
it("should work with complexer coordinates", function() {
var commands = new SVGPathData('m-10e-5 -10e-5').commands;
assert.equal(commands[0].type, SVGPathData.MOVE_TO);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].x, '-10e-5');
assert.equal(commands[0].y, '-10e-5');
});
it("should work with even more complexer coordinates", function() {
var commands = new SVGPathData('M-10.0032e-5 -10.0032e-5').commands;
assert.equal(commands[0].type, SVGPathData.MOVE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, '-10.0032e-5');
assert.equal(commands[0].y, '-10.0032e-5');
});
it("should work with comma separated coordinate pairs", function() {
var commands = new SVGPathData('M123,456 7890,9876').commands;
assert.equal(commands[0].type, SVGPathData.MOVE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, '123');
assert.equal(commands[0].y, '456');
assert.equal(commands[1].type, SVGPathData.LINE_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x, '7890');
assert.equal(commands[1].y, '9876');
});
it("should work with space separated coordinate pairs", function() {
var commands = new SVGPathData('m123 \t 456 \n 7890 \r 9876').commands;
assert.equal(commands[0].type, SVGPathData.MOVE_TO);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].x, '123');
assert.equal(commands[0].y, '456');
assert.equal(commands[1].type, SVGPathData.LINE_TO);
assert.equal(commands[1].relative, true);
assert.equal(commands[1].x, '7890');
assert.equal(commands[1].y, '9876');
});
it("should work with nested separated coordinates", function() {
var commands = new SVGPathData('M123 , 456 \t,\n7890 \r\n 9876').commands;
assert.equal(commands[0].type, SVGPathData.MOVE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, '123');
assert.equal(commands[0].y, '456');
assert.equal(commands[1].type, SVGPathData.LINE_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x, '7890');
assert.equal(commands[1].y, '9876');
});
it("should work with multiple command declarations", function() {
var commands = new SVGPathData('M123 , 456 \t,\n7890 \r\n 9876m123 \
, 456 \t,\n7890 \r\n 9876').commands;
assert.equal(commands[0].type, SVGPathData.MOVE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, '123');
assert.equal(commands[0].y, '456');
assert.equal(commands[1].type, SVGPathData.LINE_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x, '7890');
assert.equal(commands[1].y, '9876');
assert.equal(commands[2].type, SVGPathData.MOVE_TO);
assert.equal(commands[2].relative, true);
assert.equal(commands[2].x, '123');
assert.equal(commands[2].y, '456');
assert.equal(commands[3].type, SVGPathData.LINE_TO);
assert.equal(commands[3].relative, true);
assert.equal(commands[3].x, '7890');
assert.equal(commands[3].y, '9876');
});
});
describe("Encoding move to commands", function() {
it("should work with one command", function() {
assert.equal(
new SVGPathData('M-50.0032e-5 -60.0032e-5').encode(),
'M-0.000500032 -0.000600032'
);
});
it("should work with several commands", function() {
assert.equal(
new SVGPathData('M-50.0032e-5 -60.0032e-5M-50.0032e-5 -60.0032e-5M-50.0032e-5 -60.0032e-5').encode(),
'M-0.000500032 -0.000600032M-0.000500032 -0.000600032M-0.000500032 -0.000600032'
);
});
});

View File

@ -0,0 +1,96 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("Parsing commands with different numbers", function() {
it("should work with a 1 char integer", function() {
assert.equal(new SVGPathData('H0').commands[0].x, 0);
});
it("should work with a big integer", function() {
assert.equal(new SVGPathData('H1234567890').commands[0].x, 1234567890);
});
it("should work with a explicitly positive integer", function() {
assert.equal(new SVGPathData('H+1254664').commands[0].x, +1254664);
});
it("should work with a negative integer", function() {
assert.equal(new SVGPathData('H-1254664').commands[0].x, -1254664);
});
it("should work with a float with left side digits", function() {
assert.equal(new SVGPathData('H123.456').commands[0].x, 123.456);
});
it("should work with a float without left side digits", function() {
assert.equal(new SVGPathData('H.456').commands[0].x, .456);
});
it("should work with a float without right side digits", function() {
assert.equal(new SVGPathData('H123.').commands[0].x, 123.);
});
it("should work with a number with a positive exponent", function() {
assert.equal(new SVGPathData('H123.456e125').commands[0].x, 123.456e125);
});
it("should work with a number with an explicitly positive exponent", function() {
assert.equal(new SVGPathData('H123.456e+125').commands[0].x, 123.456e+125);
});
it("should work with a number with a negative exponent", function() {
assert.equal(new SVGPathData('H123.456e-125').commands[0].x, 123.456e-125);
});
it("should work with a negative number with a positive exponent", function() {
assert.equal(new SVGPathData('H-123.456e125').commands[0].x, -123.456e125);
});
it("should work with a negative number with an explicitly positive exponent", function() {
assert.equal(new SVGPathData('H-123.456e+125').commands[0].x, -123.456e+125);
});
it("should work with a negative number with a negative exponent", function() {
assert.equal(new SVGPathData('H-123.456e-125').commands[0].x, -123.456e-125);
});
it("should work with sign separated numbers", function() {
var commands = new SVGPathData('M-123.456e-125-1234.456e-125').commands;
assert.equal(commands[0].x, -123.456e-125);
assert.equal(commands[0].y, -1234.456e-125);
});
it("should work with sign separated numbers", function() {
var commands = new SVGPathData('M-1.456e-125-12.456e-125-123.456e-125-1234.456e-125').commands;
assert.equal(commands[0].x, -1.456e-125);
assert.equal(commands[0].y, -12.456e-125);
assert.equal(commands[1].x, -123.456e-125);
assert.equal(commands[1].y, -1234.456e-125);
});
it("should work with decpoint separated numbers", function() {
var commands = new SVGPathData('M-123.123e-123.456e-456').commands;
assert.equal(commands[0].x, -123.123e-123);
assert.equal(commands[0].y, .456e-456);
});
it("should work with decpoint separated numbers", function() {
var commands = new SVGPathData('M-123.123e-123.456e-456.789e-789.123e-123').commands;
assert.equal(commands[0].x, -123.123e-123);
assert.equal(commands[0].y, .456e-456);
assert.equal(commands[1].x, .789e-789);
assert.equal(commands[1].y, .123e-123);
});
});

View File

@ -0,0 +1,30 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("SVGPathDataParser", function() {
it("should still work when the new operator is forgotten", function() {
assert.doesNotThrow(function() {
SVGPathData.Parser();
});
});
it("should fail when a bad command is given", function() {
assert.throws(function() {
var parser = new SVGPathData.Parser();
parser.write('b80,20');
parser.end();
}, 'Unexpected character "b" at index 0.');
});
});

View File

@ -0,0 +1,138 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("Parsing quadratic bezier curve to commands", function() {
beforeEach(function() {
});
afterEach(function() {
});
it("should not work when badly declarated", function() {
assert.throw(function() {
new SVGPathData('Q');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('Q10');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('Q10 10');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('Q10 10 10');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('Q10 10 10 10 10 10');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('Q10 10 10Q10 10 10 10');
}, SyntaxError, 'Unterminated command at index 9.');
});
it("should work with comma separated coordinates", function() {
var commands = new SVGPathData('Q123,456 789,987').commands;
assert.equal(commands[0].type, SVGPathData.QUAD_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x1, '123');
assert.equal(commands[0].y1, '456');
assert.equal(commands[0].x, '789');
assert.equal(commands[0].y, '987');
});
it("should work with space separated coordinates", function() {
var commands = new SVGPathData('Q123 456 789 987').commands;
assert.equal(commands[0].type, SVGPathData.QUAD_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x1, '123');
assert.equal(commands[0].y1, '456');
assert.equal(commands[0].x, '789');
assert.equal(commands[0].y, '987');
});
it("should work with nested separated complexer coordinate pairs", function() {
var commands = new SVGPathData('Q-10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5').commands;
assert.equal(commands[0].type, SVGPathData.QUAD_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x1, '-10.0032e-5');
assert.equal(commands[0].y1, '-20.0032e-5');
assert.equal(commands[0].x, '-30.0032e-5');
assert.equal(commands[0].y, '-40.0032e-5');
});
it("should work with multiple pairs of coordinates", function() {
var commands = new SVGPathData('Q-10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5\
-10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5\
-10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5').commands;
assert.equal(commands[0].type, SVGPathData.QUAD_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x1, '-10.0032e-5');
assert.equal(commands[0].y1, '-20.0032e-5');
assert.equal(commands[0].x, '-30.0032e-5');
assert.equal(commands[0].y, '-40.0032e-5');
assert.equal(commands[1].type, SVGPathData.QUAD_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x1, '-10.0032e-5');
assert.equal(commands[1].y1, '-20.0032e-5');
assert.equal(commands[1].x, '-30.0032e-5');
assert.equal(commands[1].y, '-40.0032e-5');
assert.equal(commands[2].type, SVGPathData.QUAD_TO);
assert.equal(commands[2].relative, false);
assert.equal(commands[2].x1, '-10.0032e-5');
assert.equal(commands[2].y1, '-20.0032e-5');
assert.equal(commands[2].x, '-30.0032e-5');
assert.equal(commands[2].y, '-40.0032e-5');
});
it("should work with multiple declarated pairs of coordinates", function() {
var commands = new SVGPathData('Q-10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5\
q-10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5\
Q-10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5').commands;
assert.equal(commands[0].type, SVGPathData.QUAD_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x1, '-10.0032e-5');
assert.equal(commands[0].y1, '-20.0032e-5');
assert.equal(commands[0].x, '-30.0032e-5');
assert.equal(commands[0].y, '-40.0032e-5');
assert.equal(commands[1].type, SVGPathData.QUAD_TO);
assert.equal(commands[1].relative, true);
assert.equal(commands[1].x1, '-10.0032e-5');
assert.equal(commands[1].y1, '-20.0032e-5');
assert.equal(commands[1].x, '-30.0032e-5');
assert.equal(commands[1].y, '-40.0032e-5');
assert.equal(commands[2].type, SVGPathData.QUAD_TO);
assert.equal(commands[2].relative, false);
assert.equal(commands[2].x1, '-10.0032e-5');
assert.equal(commands[2].y1, '-20.0032e-5');
assert.equal(commands[2].x, '-30.0032e-5');
assert.equal(commands[2].y, '-40.0032e-5');
});
});
describe("Encoding line to commands", function() {
it("should work with one command", function() {
assert.equal(
new SVGPathData('Q-10.0032e-5 -20.0032e-5 -30.0032e-5 -40.0032e-5').encode(),
'Q-0.000100032 -0.000200032 -0.000300032 -0.000400032'
);
});
it("should work with several commands", function() {
assert.equal(
new SVGPathData('Q-10.0032e-5 -20.0032e-5 -30.0032e-5 -40.0032e-5q-10.0032e-5 -20.0032e-5 -30.0032e-5 -40.0032e-5Q-10.0032e-5 -20.0032e-5 -30.0032e-5 -40.0032e-5').encode(),
'Q-0.000100032 -0.000200032 -0.000300032 -0.000400032q-0.000100032 -0.000200032 -0.000300032 -0.000400032Q-0.000100032 -0.000200032 -0.000300032 -0.000400032'
);
});
});

View File

@ -0,0 +1,40 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("Dealing with real world commands", function() {
it("and Y axis symetry with y coords equal to 0", function() {
assert.equal(new SVGPathData('M250,381 C199.119048,381 151.285714,361.164188 115.333333,325.159688 L165.857143,274.653375 C188.333333,297.156188 218.238095,309.5625 250,309.5625 C298.214286,309.5625 341.333333,280.797 359.904762,236.291438 L369.071429,214.3125 L500,214.3125 L500,285.75 L415,285.75 C381.285714,344.304937 318.880952,381 250,381 L250,381 L250,381 L250,381 Z M130.952381,166.6875 L0,166.6875 L0,95.25 L85.047619,95.25 C118.738095,36.6950625 181.142857,0 250,0 C300.880952,0 348.714286,19.8358125 384.690476,55.8403125 L334.166667,106.346625 C311.690476,83.8438125 281.809524,71.4375 250,71.4375 C201.833333,71.4375 158.666667,100.203 140.119048,144.708563 L130.952381,166.6875 L130.952381,166.6875 L130.952381,166.6875 L130.952381,166.6875 Z M130.952381,166.6875').ySymetry(381).ySymetry(381).encode()
, 'M250 381C199.119048 381 151.285714 361.164188 115.333333 325.159688L165.857143 274.653375C188.333333 297.156188 218.238095 309.5625 250 309.5625C298.214286 309.5625 341.333333 280.797 359.904762 236.291438L369.071429 214.3125L500 214.3125L500 285.75L415 285.75C381.285714 344.304937 318.880952 381 250 381L250 381L250 381L250 381zM130.952381 166.6875L0 166.6875L0 95.25L85.047619 95.25C118.738095 36.695062500000006 181.142857 0 250 0C300.880952 0 348.714286 19.835812499999975 384.690476 55.84031249999998L334.166667 106.34662500000002C311.690476 83.84381250000001 281.809524 71.4375 250 71.4375C201.833333 71.4375 158.666667 100.20299999999997 140.119048 144.708563L130.952381 166.6875L130.952381 166.6875L130.952381 166.6875L130.952381 166.6875zM130.952381 166.6875');
});
it("of sapegin", function() {
assert.equal(new SVGPathData('M77.225 66.837l-18.895-18.895c2.85-4.681 4.49-10.177 4.49-16.058 0-17.081-14.802-31.884-31.888-31.884-17.082 0-30.932 13.85-30.932 30.934s14.803 31.885 31.885 31.885c5.68 0 11-1.538 15.575-4.21l18.996 18.997c1.859 1.859 4.873 1.859 6.73 0l4.713-4.711c1.859-1.86 1.185-4.2-.674-6.058m-67.705-35.903c0-11.828 9.588-21.416 21.412-21.416 11.83 0 22.369 10.539 22.369 22.367s-9.588 21.416-21.417 21.416c-11.825 0-22.364-10.539-22.364-22.367').ySymetry(79).encode(), 'M77.225 12.162999999999997L58.33 31.057999999999993C61.18 35.73899999999999 62.82 41.23499999999999 62.82 47.11599999999999C62.82 64.19699999999999 48.018 79 30.932 79C13.849999999999998 79 0 65.14999999999999 0 48.06599999999999S14.803 16.18099999999999 31.885 16.18099999999999C37.565 16.18099999999999 42.885000000000005 17.718999999999987 47.46 20.39099999999999L66.456 1.3939999999999912C68.315 -0.4650000000000034 71.32900000000001 -0.4650000000000034 73.186 1.3939999999999912L77.899 6.10499999999999C79.758 7.964999999999989 79.084 10.304999999999993 77.225 12.162999999999982M9.519999999999996 48.06599999999998C9.519999999999996 59.89399999999998 19.107999999999997 69.48199999999999 30.931999999999995 69.48199999999999C42.76199999999999 69.48199999999999 53.300999999999995 58.942999999999984 53.300999999999995 47.11499999999998S43.712999999999994 25.698999999999984 31.883999999999993 25.698999999999984C20.058999999999994 25.698999999999984 9.519999999999992 36.237999999999985 9.519999999999992 48.06599999999999');
});
it("of hannesjohansson", function() {
assert.equal(new SVGPathData('M2.25 12.751C2.25 18.265 6.736 22.751 12.25 22.751C14.361 22.751 16.318 22.09 17.933 20.969L25.482 28.518C25.97 29.006 26.61 29.25 27.25 29.25S28.53 29.006 29.018 28.518C29.995 27.542 29.995 25.96 29.018 24.983L21.207 17.172C21.869 15.837 22.251 14.339 22.251 12.751C22.251 7.237 17.765 2.751 12.251 2.751S2.251 7.236 2.25 12.751zM6.251 12.751C6.251 9.442 8.942 6.751 12.251 6.751S18.251 9.442 18.251 12.751S15.56 18.751 12.251 18.751S6.251 16.06 6.251 12.751z').ySymetry(32).ySymetry(32).round(10e10).encode(), 'M2.25 12.751C2.25 18.265 6.736 22.751 12.25 22.751C14.361 22.751 16.318 22.09 17.933 20.969L25.482 28.518C25.97 29.006 26.61 29.25 27.25 29.25S28.53 29.006 29.018 28.518C29.995 27.542 29.995 25.96 29.018 24.983L21.207 17.172C21.869 15.837 22.251 14.339 22.251 12.751C22.251 7.237 17.765 2.751 12.251 2.751S2.251 7.236 2.25 12.751zM6.251 12.751C6.251 9.442 8.942 6.751 12.251 6.751S18.251 9.442 18.251 12.751S15.56 18.751 12.251 18.751S6.251 16.06 6.251 12.751z');
});
it("of my blog", function() {
assert.equal(new SVGPathData('m 0,100 0,10 5,0 0,-5 15,0 0,15 -20,0 0,30 25,0 0,-50 z m 5,25 15,0 0,20 -15,0 z').toAbs().encode(), 'M0 100L0 110L5 110L5 105L20 105L20 120L0 120L0 150L25 150L25 100zM5 125L20 125L20 145L5 145z');
});
it("of tremby bug report", function() {
assert.equal(new SVGPathData('M0,250 l20,0 a40,20 0 0,0 40,20 l80,-20 a40,20 0 0,1 40,20 l80,-20 a40,20 0 1,0 40,20 l80,-20 a40,20 0 1,1 40,20 l80,-20 l0,-120 H0 Z').scale(1, -1).encode(), 'M0 -250l20 0a40 20 0 0 1 40 -20l80 20a40 20 0 0 0 40 -20l80 20a40 20 0 1 1 40 -20l80 20a40 20 0 1 0 40 -20l80 20l0 120H0z');
});
it("of fh1ch bug report", function() {
assert.equal(new SVGPathData('M382.658 327.99c16.71-17.204 26.987-40.676 26.987-66.542 0-52.782-42.792-95.575-95.574-95.575-29.894 0-56.583 13.74-74.104 35.24-17.47-7.164-37.11-9.877-57.725-7.596-44.774 4.964-82.87 38.712-94.42 84.393-2.14 8.447-5.14 13.34-14.276 16.473-26.103 8.952-42.988 35.322-41.446 61.6 1.696 28.703 21.253 52.36 48.917 59.185 1.942.48 3.813.668 5.61 1.048.063 0 .114-.216.166-.216h224.753c.154 0 .31.235.463.216 39.072-1.706 70.56-33.144 71.865-71.815.197-5.66-.225-11.13-1.21-16.472m-63.554 62.75c-2.312.503-4.697.847-7.1 1.166-6.095.83-3.763.156-18.232.156H103.716c-3.113 0-6.207.11-9.29-.044-21.283-1.038-36.646-16.796-37.243-37.185-.617-20.696 13.596-37.283 34.52-39.833 5.365-.646 10.873-.082 16.217-.082 6.186-58.885 31.18-90.46 76.418-96.802 19.834-2.785 38.66.794 56.06 10.825 25.434 14.654 38.69 37.81 44.127 66.47 4.748-1.108 8.355-1.973 11.962-2.796 27.85-6.33 54.868 10.033 61.034 36.958 6.516 28.426-9.844 55.01-38.414 61.168zm8.86-121.502c-4.225-1.07-8.613-1.778-13.125-2.097-1.756-.124-3.35-.34-4.788-.668-6.207-1.4-9.794-4.8-13.124-11.49-.185-.37-.37-.73-.555-1.1-5.333-10.44-11.92-19.68-19.537-27.604l-17.82-14.973-.42-.35c13.616-13.822 34.58-24.47 55.473-24.47 41.363 0 75.02 33.657 75.02 75.022 0 16.452-5.334 31.683-14.357 44.056-9.68-17.788-26.348-31.2-46.768-36.327z').toAbs().round(1000).encode(), 'M382.658 327.99C399.368 310.786 409.645 287.314 409.645 261.448C409.645 208.666 366.853 165.873 314.071 165.873C284.177 165.873 257.488 179.613 239.967 201.113C222.497 193.949 202.857 191.236 182.242 193.517C137.468 198.481 99.372 232.229 87.822 277.91C85.682 286.357 82.682 291.25 73.546 294.383C47.443 303.335 30.558 329.705 32.1 355.983C33.796 384.686 53.353 408.343 81.017 415.168C82.959 415.648 84.83 415.836 86.627 416.216C86.69 416.216 86.741 416 86.793 416H311.546C311.7 416 311.856 416.235 312.009 416.216C351.081 414.51 382.569 383.072 383.874 344.401C384.071 338.741 383.649 333.271 382.664 327.929M319.11 390.679C316.798 391.182 314.413 391.526 312.01 391.845C305.915 392.675 308.247 392.001 293.778 392.001H103.716C100.603 392.001 97.509 392.111 94.426 391.957C73.143 390.919 57.78 375.161 57.183 354.772C56.566 334.076 70.779 317.489 91.703 314.939C97.068 314.293 102.576 314.857 107.92 314.857C114.106 255.972 139.1 224.397 184.338 218.055C204.172 215.27 222.998 218.849 240.398 228.88C265.832 243.534 279.088 266.69 284.525 295.35C289.273 294.242 292.88 293.377 296.487 292.554C324.337 286.224 351.355 302.587 357.521 329.512C364.037 357.938 347.677 384.522 319.107 390.68zM327.97 269.177C323.745 268.107 319.357 267.399 314.845 267.08C313.089 266.956 311.495 266.74 310.057 266.412C303.85 265.012 300.263 261.612 296.933 254.922C296.748 254.552 296.563 254.192 296.378 253.822C291.045 243.382 284.458 234.142 276.841 226.218L259.021 211.245L258.601 210.895C272.217 197.073 293.181 186.425 314.074 186.425C355.437 186.425 389.094 220.082 389.094 261.447C389.094 277.899 383.76 293.13 374.737 305.503C365.057 287.715 348.389 274.303 327.969 269.176z');
});
});

View File

@ -0,0 +1,565 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("Converting relative commands to absolute ones", function() {
it("should work with m commands", function() {
var commands = new SVGPathData('m-100,100M10,10m10,10m-1,-1').toAbs().commands;
assert.equal(commands[0].type, SVGPathData.MOVE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, -100);
assert.equal(commands[0].y, 100);
assert.equal(commands[1].type, SVGPathData.MOVE_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x, 10);
assert.equal(commands[1].y, 10);
assert.equal(commands[2].type, SVGPathData.MOVE_TO);
assert.equal(commands[2].relative, false);
assert.equal(commands[2].x, 20);
assert.equal(commands[2].y, 20);
assert.equal(commands[3].type, SVGPathData.MOVE_TO);
assert.equal(commands[3].relative, false);
assert.equal(commands[3].x, 19);
assert.equal(commands[3].y, 19);
});
it("should work with h commands", function() {
var commands = new SVGPathData('h100H10h10h-5').toAbs().commands;
assert.equal(commands[0].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, 100);
assert.equal(commands[1].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x, 10);
assert.equal(commands[2].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[2].relative, false);
assert.equal(commands[2].x, 20);
assert.equal(commands[3].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[3].relative, false);
assert.equal(commands[3].x, 15);
});
it("should work with v commands", function() {
var commands = new SVGPathData('v100V10v5v5').toAbs().commands;
assert.equal(commands[0].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].y, 100);
assert.equal(commands[1].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].y, 10);
assert.equal(commands[2].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[2].relative, false);
assert.equal(commands[2].y, 15);
assert.equal(commands[3].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[3].relative, false);
assert.equal(commands[3].y, 20);
});
it("should work with l commands", function() {
var commands = new SVGPathData('l100,-100L1,0l2,2l-1,-1').toAbs().commands;
assert.equal(commands[0].type, SVGPathData.LINE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, 100);
assert.equal(commands[0].y, -100);
assert.equal(commands[1].type, SVGPathData.LINE_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x, 1);
assert.equal(commands[1].y, 0);
assert.equal(commands[2].type, SVGPathData.LINE_TO);
assert.equal(commands[2].relative, false);
assert.equal(commands[2].x, 3);
assert.equal(commands[2].y, 2);
assert.equal(commands[3].type, SVGPathData.LINE_TO);
assert.equal(commands[3].relative, false);
assert.equal(commands[3].x, 2);
assert.equal(commands[3].y, 1);
});
it("should work with c commands", function() {
var commands = new SVGPathData('c100,100 100,100 100,100\
c100,100 100,100 100,100\
c100,100 100,100 100,100\
c100,100 100,100 100,100').toAbs().commands;
assert.equal(commands[0].type, SVGPathData.CURVE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, 100);
assert.equal(commands[0].y, 100);
assert.equal(commands[0].x1, 100);
assert.equal(commands[0].y1, 100);
assert.equal(commands[0].x2, 100);
assert.equal(commands[0].y2, 100);
assert.equal(commands[1].type, SVGPathData.CURVE_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x, 200);
assert.equal(commands[1].y, 200);
assert.equal(commands[1].x1, 200);
assert.equal(commands[1].y1, 200);
assert.equal(commands[1].x2, 200);
assert.equal(commands[1].y2, 200);
assert.equal(commands[2].type, SVGPathData.CURVE_TO);
assert.equal(commands[2].relative, false);
assert.equal(commands[2].x, 300);
assert.equal(commands[2].y, 300);
assert.equal(commands[2].x1, 300);
assert.equal(commands[2].y1, 300);
assert.equal(commands[2].x2, 300);
assert.equal(commands[2].y2, 300);
assert.equal(commands[3].type, SVGPathData.CURVE_TO);
assert.equal(commands[3].relative, false);
assert.equal(commands[3].x, 400);
assert.equal(commands[3].y, 400);
assert.equal(commands[3].x1, 400);
assert.equal(commands[3].y1, 400);
assert.equal(commands[3].x2, 400);
assert.equal(commands[3].y2, 400);
});
it("should work with s commands", function() {
var commands = new SVGPathData('s100,100 100,100\
s100,100 100,100s100,100 100,100s100,100 100,100').toAbs().commands;
assert.equal(commands[0].type, SVGPathData.SMOOTH_CURVE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, 100);
assert.equal(commands[0].y, 100);
assert.equal(commands[0].x2, 100);
assert.equal(commands[0].y2, 100);
assert.equal(commands[1].type, SVGPathData.SMOOTH_CURVE_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x, 200);
assert.equal(commands[1].y, 200);
assert.equal(commands[1].x2, 200);
assert.equal(commands[1].y2, 200);
assert.equal(commands[2].type, SVGPathData.SMOOTH_CURVE_TO);
assert.equal(commands[2].relative, false);
assert.equal(commands[2].x, 300);
assert.equal(commands[2].y, 300);
assert.equal(commands[2].x2, 300);
assert.equal(commands[2].y2, 300);
assert.equal(commands[3].type, SVGPathData.SMOOTH_CURVE_TO);
assert.equal(commands[3].relative, false);
assert.equal(commands[3].x, 400);
assert.equal(commands[3].y, 400);
assert.equal(commands[3].x2, 400);
assert.equal(commands[3].y2, 400);
});
it("should work with q commands", function() {
var commands = new SVGPathData('q-100,100 -100,100q-100,100 -100,100\
q-100,100 -100,100q-100,100 -100,100').toAbs().commands;
assert.equal(commands[0].type, SVGPathData.QUAD_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, -100);
assert.equal(commands[0].y, 100);
assert.equal(commands[0].x1, -100);
assert.equal(commands[0].y1, 100);
assert.equal(commands[1].type, SVGPathData.QUAD_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x, -200);
assert.equal(commands[1].y, 200);
assert.equal(commands[1].x1, -200);
assert.equal(commands[1].y1, 200);
assert.equal(commands[2].type, SVGPathData.QUAD_TO);
assert.equal(commands[2].relative, false);
assert.equal(commands[2].x, -300);
assert.equal(commands[2].y, 300);
assert.equal(commands[2].x1, -300);
assert.equal(commands[2].y1, 300);
assert.equal(commands[3].type, SVGPathData.QUAD_TO);
assert.equal(commands[3].relative, false);
assert.equal(commands[3].x, -400);
assert.equal(commands[3].y, 400);
assert.equal(commands[3].x1, -400);
assert.equal(commands[3].y1, 400);
});
it("should work with t commands", function() {
var commands = new SVGPathData('t-100,100t-100,100t10,10t10,10').toAbs().commands;
assert.equal(commands[0].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, -100);
assert.equal(commands[0].y, 100);
assert.equal(commands[1].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x, -200);
assert.equal(commands[1].y, 200);
assert.equal(commands[2].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[2].relative, false);
assert.equal(commands[2].x, -190);
assert.equal(commands[2].y, 210);
assert.equal(commands[3].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[3].relative, false);
assert.equal(commands[3].x, -180);
assert.equal(commands[3].y, 220);
});
it("should work with a commands", function() {
var commands = new SVGPathData('a20,20 180 1 0 -100,100\
a20,20 180 1 0 -100,100a20,20 180 1 0 -100,100\
a20,20 180 1 0 -100,100').toAbs().commands;
assert.equal(commands[0].type, SVGPathData.ARC);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].rX, 20);
assert.equal(commands[0].rY, 20);
assert.equal(commands[0].xRot, 180);
assert.equal(commands[0].lArcFlag, 1);
assert.equal(commands[0].sweepFlag, 0);
assert.equal(commands[0].x, -100);
assert.equal(commands[0].y, 100);
assert.equal(commands[1].type, SVGPathData.ARC);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].rX, 20);
assert.equal(commands[1].rY, 20);
assert.equal(commands[1].xRot, 180);
assert.equal(commands[1].lArcFlag, 1);
assert.equal(commands[1].sweepFlag, 0);
assert.equal(commands[1].x, -200);
assert.equal(commands[1].y, 200);
assert.equal(commands[2].type, SVGPathData.ARC);
assert.equal(commands[2].relative, false);
assert.equal(commands[2].rX, 20);
assert.equal(commands[2].rY, 20);
assert.equal(commands[2].xRot, 180);
assert.equal(commands[2].lArcFlag, 1);
assert.equal(commands[2].sweepFlag, 0);
assert.equal(commands[2].x, -300);
assert.equal(commands[2].y, 300);
assert.equal(commands[3].type, SVGPathData.ARC);
assert.equal(commands[3].relative, false);
assert.equal(commands[3].rX, 20);
assert.equal(commands[3].rY, 20);
assert.equal(commands[3].xRot, 180);
assert.equal(commands[3].lArcFlag, 1);
assert.equal(commands[3].sweepFlag, 0);
assert.equal(commands[3].x, -400);
assert.equal(commands[3].y, 400);
});
it("should work with nested commands", function() {
var commands = new SVGPathData('a20,20 180 1 0 -100,100h10v10l10,10\
c10,10 20,20 100,100').toAbs().commands;
assert.equal(commands[0].type, SVGPathData.ARC);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].rX, 20);
assert.equal(commands[0].rY, 20);
assert.equal(commands[0].xRot, 180);
assert.equal(commands[0].lArcFlag, 1);
assert.equal(commands[0].sweepFlag, 0);
assert.equal(commands[0].x, -100);
assert.equal(commands[0].y, 100);
assert.equal(commands[1].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x, -90);
assert.equal(commands[2].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[2].relative, false);
assert.equal(commands[2].y, 110);
assert.equal(commands[3].type, SVGPathData.LINE_TO);
assert.equal(commands[3].relative, false);
assert.equal(commands[3].x, -80);
assert.equal(commands[3].y, 120);
assert.equal(commands[4].type, SVGPathData.CURVE_TO);
assert.equal(commands[4].relative, false);
assert.equal(commands[4].x, 20);
assert.equal(commands[4].y, 220);
assert.equal(commands[4].x1, -60);
assert.equal(commands[4].y1, 140);
assert.equal(commands[4].x2, -70);
assert.equal(commands[4].y2, 130);
});
});
describe("Converting absolute commands to relative ones", function() {
it("should work with M commands", function() {
var commands = new SVGPathData('M100,100M110,90M120,80M130,70').toRel().commands;
assert.equal(commands[0].type, SVGPathData.MOVE_TO);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].x, 100);
assert.equal(commands[0].y, 100);
assert.equal(commands[1].type, SVGPathData.MOVE_TO);
assert.equal(commands[1].relative, true);
assert.equal(commands[1].x, 10);
assert.equal(commands[1].y, -10);
assert.equal(commands[2].type, SVGPathData.MOVE_TO);
assert.equal(commands[2].relative, true);
assert.equal(commands[2].x, 10);
assert.equal(commands[2].y, -10);
assert.equal(commands[3].type, SVGPathData.MOVE_TO);
assert.equal(commands[3].relative, true);
assert.equal(commands[3].x, 10);
assert.equal(commands[3].y, -10);
});
it("should work with M commands", function() {
var commands = new SVGPathData('M-100,100m90,-90M20,20M19,19').toRel().commands;
assert.equal(commands[0].type, SVGPathData.MOVE_TO);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].x, -100);
assert.equal(commands[0].y, 100);
assert.equal(commands[1].type, SVGPathData.MOVE_TO);
assert.equal(commands[1].relative, true);
assert.equal(commands[1].x, 90);
assert.equal(commands[1].y, -90);
assert.equal(commands[2].type, SVGPathData.MOVE_TO);
assert.equal(commands[2].relative, true);
assert.equal(commands[2].x, 30);
assert.equal(commands[2].y, 10);
assert.equal(commands[3].type, SVGPathData.MOVE_TO);
assert.equal(commands[3].relative, true);
assert.equal(commands[3].x, -1);
assert.equal(commands[3].y, -1);
});
it("should work with H commands", function() {
var commands = new SVGPathData('H100H10H20H15').toRel().commands;
assert.equal(commands[0].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].x, 100);
assert.equal(commands[1].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[1].relative, true);
assert.equal(commands[1].x, -90);
assert.equal(commands[2].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[2].relative, true);
assert.equal(commands[2].x, 10);
assert.equal(commands[3].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[3].relative, true);
assert.equal(commands[3].x, -5);
});
it("should work with V commands", function() {
var commands = new SVGPathData('V100V10V15V20').toRel().commands;
assert.equal(commands[0].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].y, 100);
assert.equal(commands[1].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[1].relative, true);
assert.equal(commands[1].y, -90);
assert.equal(commands[2].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[2].relative, true);
assert.equal(commands[2].y, 5);
assert.equal(commands[3].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[3].relative, true);
assert.equal(commands[3].y, 5);
});
it("should work with L commands", function() {
var commands = new SVGPathData('L100,-100L1,0L3,2L2,1').toRel().commands;
assert.equal(commands[0].type, SVGPathData.LINE_TO);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].x, 100);
assert.equal(commands[0].y, -100);
assert.equal(commands[1].type, SVGPathData.LINE_TO);
assert.equal(commands[1].relative, true);
assert.equal(commands[1].x, -99);
assert.equal(commands[1].y, 100);
assert.equal(commands[2].type, SVGPathData.LINE_TO);
assert.equal(commands[2].relative, true);
assert.equal(commands[2].x, 2);
assert.equal(commands[2].y, 2);
assert.equal(commands[3].type, SVGPathData.LINE_TO);
assert.equal(commands[3].relative, true);
assert.equal(commands[3].x, -1);
assert.equal(commands[3].y, -1);
});
it("should work with C commands", function() {
var commands = new SVGPathData('C100,100 100,100 100,100\
C200,200 200,200 200,200\
C300,300 300,300 300,300\
C400,400 400,400 400,400').toRel().commands;
assert.equal(commands[0].type, SVGPathData.CURVE_TO);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].x, 100);
assert.equal(commands[0].y, 100);
assert.equal(commands[0].x1, 100);
assert.equal(commands[0].y1, 100);
assert.equal(commands[0].x2, 100);
assert.equal(commands[0].y2, 100);
assert.equal(commands[1].type, SVGPathData.CURVE_TO);
assert.equal(commands[1].relative, true);
assert.equal(commands[1].x, 100);
assert.equal(commands[1].y, 100);
assert.equal(commands[1].x1, 100);
assert.equal(commands[1].y1, 100);
assert.equal(commands[1].x2, 100);
assert.equal(commands[1].y2, 100);
assert.equal(commands[2].type, SVGPathData.CURVE_TO);
assert.equal(commands[2].relative, true);
assert.equal(commands[2].x, 100);
assert.equal(commands[2].y, 100);
assert.equal(commands[2].x1, 100);
assert.equal(commands[2].y1, 100);
assert.equal(commands[2].x2, 100);
assert.equal(commands[2].y2, 100);
assert.equal(commands[3].type, SVGPathData.CURVE_TO);
assert.equal(commands[3].relative, true);
assert.equal(commands[3].x, 100);
assert.equal(commands[3].y, 100);
assert.equal(commands[3].x1, 100);
assert.equal(commands[3].y1, 100);
assert.equal(commands[3].x2, 100);
assert.equal(commands[3].y2, 100);
});
it("should work with S commands", function() {
var commands = new SVGPathData('S100,100 100,100\
S200,200 200,200S300,300 300,300S400,400 400,400').toRel().commands;
assert.equal(commands[0].type, SVGPathData.SMOOTH_CURVE_TO);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].x, 100);
assert.equal(commands[0].y, 100);
assert.equal(commands[0].x2, 100);
assert.equal(commands[0].y2, 100);
assert.equal(commands[1].type, SVGPathData.SMOOTH_CURVE_TO);
assert.equal(commands[1].relative, true);
assert.equal(commands[1].x, 100);
assert.equal(commands[1].y, 100);
assert.equal(commands[1].x2, 100);
assert.equal(commands[1].y2, 100);
assert.equal(commands[2].type, SVGPathData.SMOOTH_CURVE_TO);
assert.equal(commands[2].relative, true);
assert.equal(commands[2].x, 100);
assert.equal(commands[2].y, 100);
assert.equal(commands[2].x2, 100);
assert.equal(commands[2].y2, 100);
assert.equal(commands[3].type, SVGPathData.SMOOTH_CURVE_TO);
assert.equal(commands[3].relative, true);
assert.equal(commands[3].x, 100);
assert.equal(commands[3].y, 100);
assert.equal(commands[3].x2, 100);
assert.equal(commands[3].y2, 100);
});
it("should work with Q commands", function() {
var commands = new SVGPathData('Q-100,100 -100,100Q-200,200 -200,200\
Q-300,300 -300,300Q-400,400 -400,400').toRel().commands;
assert.equal(commands[0].type, SVGPathData.QUAD_TO);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].x, -100);
assert.equal(commands[0].y, 100);
assert.equal(commands[0].x1, -100);
assert.equal(commands[0].y1, 100);
assert.equal(commands[1].type, SVGPathData.QUAD_TO);
assert.equal(commands[1].relative, true);
assert.equal(commands[1].x, -100);
assert.equal(commands[1].y, 100);
assert.equal(commands[1].x1, -100);
assert.equal(commands[1].y1, 100);
assert.equal(commands[2].type, SVGPathData.QUAD_TO);
assert.equal(commands[2].relative, true);
assert.equal(commands[2].x, -100);
assert.equal(commands[2].y, 100);
assert.equal(commands[2].x1, -100);
assert.equal(commands[2].y1, 100);
assert.equal(commands[3].type, SVGPathData.QUAD_TO);
assert.equal(commands[3].relative, true);
assert.equal(commands[3].x, -100);
assert.equal(commands[3].y, 100);
assert.equal(commands[3].x1, -100);
assert.equal(commands[3].y1, 100);
});
it("should work with T commands", function() {
var commands = new SVGPathData('T-100,100T-200,200T-190,210T-180,220').toRel().commands;
assert.equal(commands[0].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].x, -100);
assert.equal(commands[0].y, 100);
assert.equal(commands[1].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[1].relative, true);
assert.equal(commands[1].x, -100);
assert.equal(commands[1].y, 100);
assert.equal(commands[2].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[2].relative, true);
assert.equal(commands[2].x, 10);
assert.equal(commands[2].y, 10);
assert.equal(commands[3].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[3].relative, true);
assert.equal(commands[3].x, 10);
assert.equal(commands[3].y, 10);
});
it("should work with A commands", function() {
var commands = new SVGPathData('A20,20 180 1 0 -100,100\
A20,20 180 1 0 -200,200A20,20 180 1 0 -300,300\
A20,20 180 1 0 -400,400').toRel().commands;
assert.equal(commands[0].type, SVGPathData.ARC);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].rX, 20);
assert.equal(commands[0].rY, 20);
assert.equal(commands[0].xRot, 180);
assert.equal(commands[0].lArcFlag, 1);
assert.equal(commands[0].sweepFlag, 0);
assert.equal(commands[0].x, -100);
assert.equal(commands[0].y, 100);
assert.equal(commands[1].type, SVGPathData.ARC);
assert.equal(commands[1].relative, true);
assert.equal(commands[1].rX, 20);
assert.equal(commands[1].rY, 20);
assert.equal(commands[1].xRot, 180);
assert.equal(commands[1].lArcFlag, 1);
assert.equal(commands[1].sweepFlag, 0);
assert.equal(commands[1].x, -100);
assert.equal(commands[1].y, 100);
assert.equal(commands[2].type, SVGPathData.ARC);
assert.equal(commands[2].relative, true);
assert.equal(commands[2].rX, 20);
assert.equal(commands[2].rY, 20);
assert.equal(commands[2].xRot, 180);
assert.equal(commands[2].lArcFlag, 1);
assert.equal(commands[2].sweepFlag, 0);
assert.equal(commands[2].x, -100);
assert.equal(commands[2].y, 100);
assert.equal(commands[3].type, SVGPathData.ARC);
assert.equal(commands[3].relative, true);
assert.equal(commands[3].rX, 20);
assert.equal(commands[3].rY, 20);
assert.equal(commands[3].xRot, 180);
assert.equal(commands[3].lArcFlag, 1);
assert.equal(commands[3].sweepFlag, 0);
assert.equal(commands[3].x, -100);
assert.equal(commands[3].y, 100);
});
it("should work with nested commands", function() {
var commands = new SVGPathData('A20,20 180 1 0 -100,100H-90V110L20,220\
C10,10 20,20 20,220').toRel().commands;
assert.equal(commands[0].type, SVGPathData.ARC);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].rX, 20);
assert.equal(commands[0].rY, 20);
assert.equal(commands[0].xRot, 180);
assert.equal(commands[0].lArcFlag, 1);
assert.equal(commands[0].sweepFlag, 0);
assert.equal(commands[0].x, -100);
assert.equal(commands[0].y, 100);
assert.equal(commands[1].type, SVGPathData.HORIZ_LINE_TO);
assert.equal(commands[1].relative, true);
assert.equal(commands[1].x, 10);
assert.equal(commands[2].type, SVGPathData.VERT_LINE_TO);
assert.equal(commands[2].relative, true);
assert.equal(commands[2].y, 10);
assert.equal(commands[3].type, SVGPathData.LINE_TO);
assert.equal(commands[3].relative, true);
assert.equal(commands[3].x, 110);
assert.equal(commands[3].y, 110);
assert.equal(commands[4].type, SVGPathData.CURVE_TO);
assert.equal(commands[4].relative, true);
assert.equal(commands[4].x, 0);
assert.equal(commands[4].y, 0);
assert.equal(commands[4].x1, 0);
assert.equal(commands[4].y1, -200);
assert.equal(commands[4].x2, -10);
assert.equal(commands[4].y2, -210);
});
});

View File

@ -0,0 +1,102 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("Positive rotate from the origin", function() {
it("should fail with no args", function() {
assert.throws(function() {
new SVGPathData(
'm20,30l10,10z'
).rotate().encode();
}, 'A rotate transformation requires the parameter a'
+' to be set and to be a number.');
});
it("should work with relative horinzontal path", function() {
assert.equal(new SVGPathData(
'm10 0l60 0z'
).rotate(Math.PI).round(6).encode(),
'm-10 0l-60 0z');
});
it("should work with relative vertical path", function() {
assert.equal(new SVGPathData(
'm0 10l0 60z'
).rotate(Math.PI).round(6).encode(),
'm0 -10l0 -60z');
});
it("should work with relative path", function() {
assert.equal(new SVGPathData(
'm75 100l0 -50z'
).rotate(Math.PI).round(6).encode(),
'm-75 -100l0 50z');
});
it("should work with absolute path", function() {
assert.equal(new SVGPathData(
'M75,100L75,50z'
).rotate(Math.PI).round(6).encode(),
'M-75 -100L-75 -50z');
});
});
describe("Positive rotate", function() {
it("should work with relative path (Math.PI)", function() {
assert.equal(new SVGPathData(
'm100 100l100 100z'
).rotate(Math.PI, 150, 150).round(6).encode(),
'm200 200l-100 -100z');
});
it("should work with relative path (Math.PI/2)", function() {
assert.equal(new SVGPathData(
'm100 100l100 100z'
).rotate(Math.PI/2, 150, 150).round(6).encode(),
'm200 100l-100 100z');
});
it("should work with relative path", function() {
assert.equal(new SVGPathData(
'm75 100l0 -50z'
).rotate(Math.PI, 75, 75).round(6).encode(),
'm75 50l0 50z');
});
it("should work with absolute path", function() {
assert.equal(new SVGPathData(
'M75,100L75,50z'
).rotate(Math.PI, 75, 75).round(6).encode(),
'M75 50L75 100z');
});
});
describe("360° Positive rotate", function() {
it("should work with relative path", function() {
assert.equal(new SVGPathData(
'm100 75l-50 -45l0 90z'
).rotate(2*Math.PI, 75, 75).round(6).encode(),
'm100 75l-50 -45l0 90z');
});
it("should work with absolute path", function() {
assert.equal(new SVGPathData(
'M 100,75L50,30L50,120 z'
).rotate(2*Math.PI, 75, 75).round(6).encode(),
'M100 75L50 30L50 120z');
});
});

View File

@ -0,0 +1,23 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("Path rounding", function() {
it("should work", function() {
assert.equal(new SVGPathData(
'M137.5 140C137.5 140 129.86983 107.04527999999999 120.28202 94.914299C120.28202 94.914299 111.67409 87.871064 107.37013999999999 87.284128C103.06618 86.69719099999999 76.261082 86.11025599999999 76.261082 86.11025599999999L68.239383 76.289234H64.522357L63.348485 60.47904L66.870103 56.762015999999996L68.434791 46.979513L67.847854 42.479433H66.087046C66.087046 42.479433 64.948119 29.761523 65.109294 28.391533000000003C65.269757 27.022253000000003 60.197715 12.206213000000002 47.48052000000001 10.215053000000001C34.76333000000001 8.223173000000001 12.446920000000006 20.723563 12.446920000000006 20.723563L13.652170000000012 42.282593L15.999920000000003 48.935013L14.63064 49.326543C14.63064 49.326543 14.826040000000006 53.043563 16.391449999999992 55.586716C16.391449999999992 55.586716 18.543779999999998 66.34769 24.021619999999984 66.543098L28.326289999999986 79.064881L32.04331999999998 83.174148L34.97799999999998 91.78207L20.30458999999999 109.587L19.130719999999997 119.95644C19.130719999999997 119.95644 10.603379999999987 127.56165 12.812780000000004 139.99858H137.5z'
).round(10e12).encode(),
'M137.5 140C137.5 140 129.86983 107.04528 120.28202 94.914299C120.28202 94.914299 111.67409 87.871064 107.37014 87.284128C103.06618 86.697191 76.261082 86.110256 76.261082 86.110256L68.239383 76.289234H64.522357L63.348485 60.47904L66.870103 56.762016L68.434791 46.979513L67.847854 42.479433H66.087046C66.087046 42.479433 64.948119 29.761523 65.109294 28.391533C65.269757 27.022253 60.197715 12.206213 47.48052 10.215053C34.76333 8.223173 12.44692 20.723563 12.44692 20.723563L13.65217 42.282593L15.99992 48.935013L14.63064 49.326543C14.63064 49.326543 14.82604 53.043563 16.39145 55.586716C16.39145 55.586716 18.54378 66.34769 24.02162 66.543098L28.32629 79.064881L32.04332 83.174148L34.978 91.78207L20.30459 109.587L19.13072 119.95644C19.13072 119.95644 10.60338 127.56165 12.81278 139.99858H137.5z');
});
});

View File

@ -0,0 +1,38 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("Positive scale", function() {
it("should fail with no args", function() {
assert.throws(function() {
new SVGPathData(
'm20,30l10,10z'
).scale().encode();
}, 'A scale transformation requires the parameter dX'
+' to be set and to be a number.');
});
it("should work with relative path", function() {
assert.equal(new SVGPathData(
'm20 30c0 0 10 20 15 30z'
).scale(10, 10).encode(),
'm200 300c0 0 100 200 150 300z');
});
it("should work with absolute path", function() {
assert.equal(new SVGPathData(
'M20 30C0 0 10 20 15 30z'
).scale(10, 10).encode(),
'M200 300C0 0 100 200 150 300z');
});
});

View File

@ -0,0 +1,63 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("X axis skew", function() {
it("should fail with bad args", function() {
assert.throws(function() {
new SVGPathData(
'm20,30l10,10z'
).skewX().encode();
}, 'A skewX transformation requires the parameter x'
+' to be set and to be a number.');
});
it("should work with relative path", function() {
assert.equal(new SVGPathData(
'm100 75l-50 -45l0 90z'
).skewX(Math.PI/2).encode(),
'm175.29136163904155 75l-95.17481698342493 -45l90.34963396684985 90z');
});
it("should work with absolute path", function() {
assert.equal(new SVGPathData(
'M 100,75 50,30 50,120 z'
).skewX(Math.PI/2).encode(),
'M175.29136163904155 75L80.11654465561662 30L170.46617862246646 120z');
});
});
describe("Y axis skew", function() {
it("should fail with bad args", function() {
assert.throws(function() {
new SVGPathData(
'm20,30l10,10z'
).skewY().encode();
}, 'A skewY transformation requires the parameter y'
+' to be set and to be a number.');
});
it("should work with relative path", function() {
assert.equal(new SVGPathData(
'm100 75l-50 -45l0 90z'
).skewY(Math.PI/2).encode(),
'm100 175.3884821853887l-50 -95.19424109269436l0 90z');
});
it("should work with absolute path", function() {
assert.equal(new SVGPathData(
'M 100,75 50,30 50,120 z'
).skewY(Math.PI/2).encode(),
'M100 175.3884821853887L50 80.19424109269436L50 170.19424109269437z');
});
});

View File

@ -0,0 +1,116 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("Parsing smooth curve to commands", function() {
beforeEach(function() {
});
afterEach(function() {
});
it("should not work when badly declarated", function() {
assert.throw(function() {
new SVGPathData('S');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('S10');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('S10 10');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('S10 10 10');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('S10 10 10 10 10 10');
}, SyntaxError, 'Unterminated command at the path end.');
assert.throw(function() {
new SVGPathData('S10 10 10S10 10 10 10');
}, SyntaxError, 'Unterminated command at index 9.');
});
it("should work with comma separated coordinates", function() {
var commands = new SVGPathData('S123,456 789,987').commands;
assert.equal(commands[0].type, SVGPathData.SMOOTH_CURVE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x2, '123');
assert.equal(commands[0].y2, '456');
assert.equal(commands[0].x, '789');
assert.equal(commands[0].y, '987');
});
it("should work with space separated coordinates", function() {
var commands = new SVGPathData('S123 456 789 987').commands;
assert.equal(commands[0].type, SVGPathData.SMOOTH_CURVE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x2, '123');
assert.equal(commands[0].y2, '456');
assert.equal(commands[0].x, '789');
assert.equal(commands[0].y, '987');
});
it("should work with nested separated complexer coordinate pairs", function() {
var commands = new SVGPathData('S-10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5').commands;
assert.equal(commands[0].type, SVGPathData.SMOOTH_CURVE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x2, '-10.0032e-5');
assert.equal(commands[0].y2, '-20.0032e-5');
assert.equal(commands[0].x, '-30.0032e-5');
assert.equal(commands[0].y, '-40.0032e-5');
});
it("should work with multiple pairs of coordinates", function() {
var commands = new SVGPathData('S-10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5 -10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5 -10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5').commands;
assert.equal(commands[0].type, SVGPathData.SMOOTH_CURVE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x2, '-10.0032e-5');
assert.equal(commands[0].y2, '-20.0032e-5');
assert.equal(commands[0].x, '-30.0032e-5');
assert.equal(commands[0].y, '-40.0032e-5');
assert.equal(commands[1].type, SVGPathData.SMOOTH_CURVE_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x2, '-10.0032e-5');
assert.equal(commands[1].y2, '-20.0032e-5');
assert.equal(commands[1].x, '-30.0032e-5');
assert.equal(commands[1].y, '-40.0032e-5');
assert.equal(commands[2].type, SVGPathData.SMOOTH_CURVE_TO);
assert.equal(commands[2].relative, false);
assert.equal(commands[2].x2, '-10.0032e-5');
assert.equal(commands[2].y2, '-20.0032e-5');
assert.equal(commands[2].x, '-30.0032e-5');
assert.equal(commands[2].y, '-40.0032e-5');
});
it("should work with multiple declarated pairs of coordinates", function() {
var commands = new SVGPathData('S-10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5 s-10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5 S-10.0032e-5,-20.0032e-5 -30.0032e-5,-40.0032e-5').commands;
assert.equal(commands[0].type, SVGPathData.SMOOTH_CURVE_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x2, '-10.0032e-5');
assert.equal(commands[0].y2, '-20.0032e-5');
assert.equal(commands[0].x, '-30.0032e-5');
assert.equal(commands[0].y, '-40.0032e-5');
assert.equal(commands[1].type, SVGPathData.SMOOTH_CURVE_TO);
assert.equal(commands[1].relative, true);
assert.equal(commands[1].x2, '-10.0032e-5');
assert.equal(commands[1].y2, '-20.0032e-5');
assert.equal(commands[1].x, '-30.0032e-5');
assert.equal(commands[1].y, '-40.0032e-5');
assert.equal(commands[2].type, SVGPathData.SMOOTH_CURVE_TO);
assert.equal(commands[2].relative, false);
assert.equal(commands[2].x2, '-10.0032e-5');
assert.equal(commands[2].y2, '-20.0032e-5');
assert.equal(commands[2].x, '-30.0032e-5');
assert.equal(commands[2].y, '-40.0032e-5');
});
});

View File

@ -0,0 +1,140 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("Parsing smooth quadratic curve to commands", function() {
beforeEach(function() {
});
afterEach(function() {
});
it("should fail with a with single coordinate", function() {
assert.throw(function() {
new SVGPathData('T100');
}, SyntaxError, 'Unterminated command at the path end.');
});
it("should fail with a single complexer coordinate", function() {
assert.throw(function() {
new SVGPathData('t-10e-5');
}, SyntaxError, 'Unterminated command at the path end.');
});
it("should work with comma separated coordinates", function() {
var commands = new SVGPathData('T100,100').commands;
assert.equal(commands[0].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, '100');
assert.equal(commands[0].y, '100');
});
it("should work with space separated coordinates", function() {
var commands = new SVGPathData('t100 \t 100').commands;
assert.equal(commands[0].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].x, '100');
assert.equal(commands[0].y, '100');
});
it("should work with complexer coordinates", function() {
var commands = new SVGPathData('t-10e-5 -10e-5').commands;
assert.equal(commands[0].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].x, '-10e-5');
assert.equal(commands[0].y, '-10e-5');
});
it("should work with even more complexer coordinates", function() {
var commands = new SVGPathData('T-10.0032e-5 -10.0032e-5').commands;
assert.equal(commands[0].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, '-10.0032e-5');
assert.equal(commands[0].y, '-10.0032e-5');
});
it("should work with comma separated coordinate pairs", function() {
var commands = new SVGPathData('T123,456 7890,9876').commands;
assert.equal(commands[0].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, '123');
assert.equal(commands[0].y, '456');
assert.equal(commands[1].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x, '7890');
assert.equal(commands[1].y, '9876');
});
it("should work with space separated coordinate pairs", function() {
var commands = new SVGPathData('t123 \t 456 \n 7890 \r 9876').commands;
assert.equal(commands[0].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[0].relative, true);
assert.equal(commands[0].x, '123');
assert.equal(commands[0].y, '456');
assert.equal(commands[1].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[1].relative, true);
assert.equal(commands[1].x, '7890');
assert.equal(commands[1].y, '9876');
});
it("should work with nested separated coordinates", function() {
var commands = new SVGPathData('T123 , 456 \t,\n7890 \r\n 9876').commands;
assert.equal(commands[0].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, '123');
assert.equal(commands[0].y, '456');
assert.equal(commands[1].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x, '7890');
assert.equal(commands[1].y, '9876');
});
it("should work with multiple command declarations", function() {
var commands = new SVGPathData('T123 , 456 \t,\n7890 \r\n\
9876t123 , 456 \t,\n7890 \r\n 9876').commands;
assert.equal(commands[0].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[0].relative, false);
assert.equal(commands[0].x, '123');
assert.equal(commands[0].y, '456');
assert.equal(commands[1].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[1].relative, false);
assert.equal(commands[1].x, '7890');
assert.equal(commands[1].y, '9876');
assert.equal(commands[2].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[2].relative, true);
assert.equal(commands[2].x, '123');
assert.equal(commands[2].y, '456');
assert.equal(commands[3].type, SVGPathData.SMOOTH_QUAD_TO);
assert.equal(commands[3].relative, true);
assert.equal(commands[3].x, '7890');
assert.equal(commands[3].y, '9876');
});
});
describe("Encoding smooth quadratic bezier curve to commands", function() {
it("should work with one command", function() {
assert.equal(
new SVGPathData('T-50.0032e-5 -60.0032e-5').encode(),
'T-0.000500032 -0.000600032'
);
});
it("should work with several commands", function() {
assert.equal(
new SVGPathData('T-50.0032e-5 -60.0032e-5t-50.0032e-5 -60.0032e-5T-50.0032e-5 -60.0032e-5 -50.0032e-5 -60.0032e-5').encode(),
'T-0.000500032 -0.000600032t-0.000500032 -0.000600032T-0.000500032 -0.000600032T-0.000500032 -0.000600032'
);
});
});

View File

@ -0,0 +1,48 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("X axis symetry", function() {
it("should work with an arbitrary path", function() {
assert.equal(new SVGPathData(
'm12.5 140c0 0 7.63017 -32.95472 17.21798 -45.085701c0 0 8.60793 -7.043235 12.91188 -7.630171c4.30396 -0.586937 31.109058 -1.173872 31.109058 -1.173872l8.021699 -9.821022h3.717026l1.173872 -15.810194l-3.521618 -3.717024l-1.564688 -9.782503l0.586937 -4.50008h1.760808c0 0 1.138927 -12.71791 0.977752 -14.0879c-0.160463 -1.36928 4.911579 -16.18532 17.628774 -18.17648c12.71719 -1.99188 35.0336 10.50851 35.0336 10.50851l-1.20525 21.55903l-2.34775 6.65242l1.36928 0.39153c0 0 -0.1954 3.71702 -1.76081 6.260173c0 0 -2.15233 10.760974 -7.63017 10.956382l-4.30467 12.521783l-3.71703 4.109267l-2.93468 8.607922l14.67341 17.80493l1.17387 10.36944c0 0 8.52734 7.60521 6.31794 20.04214h-124.68722z'
).xSymetry(150).encode(),
'M137.5 140C137.5 140 129.86983 107.04527999999999 120.28202 94.914299C120.28202 94.914299 111.67409 87.871064 107.37013999999999 87.284128C103.06618 86.69719099999999 76.261082 86.11025599999999 76.261082 86.11025599999999L68.239383 76.289234H64.522357L63.348485 60.47904L66.870103 56.762015999999996L68.434791 46.979513L67.847854 42.479433H66.087046C66.087046 42.479433 64.948119 29.761523 65.109294 28.391533000000003C65.269757 27.022253000000003 60.197715 12.206213000000002 47.48052000000001 10.215053000000001C34.76333000000001 8.223173000000001 12.446920000000006 20.723563 12.446920000000006 20.723563L13.652170000000012 42.282593L15.999920000000003 48.935013L14.63064 49.326543C14.63064 49.326543 14.826040000000006 53.043563 16.391449999999992 55.586716C16.391449999999992 55.586716 18.543779999999998 66.34769 24.021619999999984 66.543098L28.326289999999986 79.064881L32.04331999999998 83.174148L34.97799999999998 91.78207L20.30458999999999 109.587L19.130719999999997 119.95644C19.130719999999997 119.95644 10.603379999999987 127.56165 12.812780000000004 139.99858H137.5z');
});
it("should work when reversed", function() {
assert.equal(new SVGPathData(
'm12.5 140c0 0 7.63017 -32.95472 17.21798 -45.085701c0 0 8.60793 -7.043235 12.91188 -7.630171c4.30396 -0.586937 31.109058 -1.173872 31.109058 -1.173872l8.021699 -9.821022h3.717026l1.173872 -15.810194l-3.521618 -3.717024l-1.564688 -9.782503l0.586937 -4.50008h1.760808c0 0 1.138927 -12.71791 0.977752 -14.0879c-0.160463 -1.36928 4.911579 -16.18532 17.628774 -18.17648c12.71719 -1.99188 35.0336 10.50851 35.0336 10.50851l-1.20525 21.55903l-2.34775 6.65242l1.36928 0.39153c0 0 -0.1954 3.71702 -1.76081 6.260173c0 0 -2.15233 10.760974 -7.63017 10.956382l-4.30467 12.521783l-3.71703 4.109267l-2.93468 8.607922l14.67341 17.80493l1.17387 10.36944c0 0 8.52734 7.60521 6.31794 20.04214h-124.68722z'
).xSymetry(150).xSymetry(150).encode(),
'M12.5 140C12.5 140 20.130169999999993 107.04527999999999 29.717979999999997 94.914299C29.717979999999997 94.914299 38.32590999999999 87.871064 42.62986000000001 87.284128C46.93382 86.69719099999999 73.738918 86.11025599999999 73.738918 86.11025599999999L81.760617 76.289234H85.477643L86.651515 60.47904L83.129897 56.762015999999996L81.565209 46.979513L82.152146 42.479433H83.912954C83.912954 42.479433 85.051881 29.761523 84.890706 28.391533000000003C84.730243 27.022253000000003 89.802285 12.206213000000002 102.51947999999999 10.215053000000001C115.23666999999999 8.223173000000001 137.55308 20.723563 137.55308 20.723563L136.34783 42.282593L134.00008 48.935013L135.36936 49.326543C135.36936 49.326543 135.17396 53.043563 133.60855 55.586716C133.60855 55.586716 131.45622 66.34769 125.97838000000002 66.543098L121.67371000000001 79.064881L117.95668000000002 83.174148L115.02200000000002 91.78207L129.69541 109.587L130.86928 119.95644C130.86928 119.95644 139.39662 127.56165 137.18722 139.99858H12.5z');
});
});
describe("Y axis symetry", function() {
it("should work with an arbitrary path", function() {
assert.equal(new SVGPathData(
'm12.5 140c0 0 7.63017 -32.95472 17.21798 -45.085701c0 0 8.60793 -7.043235 12.91188 -7.630171c4.30396 -0.586937 31.109058 -1.173872 31.109058 -1.173872l8.021699 -9.821022h3.717026l1.173872 -15.810194l-3.521618 -3.717024l-1.564688 -9.782503l0.586937 -4.50008h1.760808c0 0 1.138927 -12.71791 0.977752 -14.0879c-0.160463 -1.36928 4.911579 -16.18532 17.628774 -18.17648c12.71719 -1.99188 35.0336 10.50851 35.0336 10.50851l-1.20525 21.55903l-2.34775 6.65242l1.36928 0.39153c0 0 -0.1954 3.71702 -1.76081 6.260173c0 0 -2.15233 10.760974 -7.63017 10.956382l-4.30467 12.521783l-3.71703 4.109267l-2.93468 8.607922l14.67341 17.80493l1.17387 10.36944c0 0 8.52734 7.60521 6.31794 20.04214h-124.68722z'
).ySymetry(150).encode(),
'M12.5 10C12.5 10 20.13017 42.95472000000001 29.71798 55.085701C29.71798 55.085701 38.32591 62.128935999999996 42.62986 62.715872000000005C46.93382 63.30280900000001 73.738918 63.88974400000001 73.738918 63.88974400000001L81.760617 73.710766H85.477643L86.651515 89.52096L83.129897 93.23798400000001L81.565209 103.020487L82.152146 107.520567H83.912954C83.912954 107.520567 85.051881 120.238477 84.890706 121.60846699999999C84.730243 122.977747 89.802285 137.793787 102.51947999999999 139.784947C115.23666999999999 141.776827 137.55308 129.276437 137.55308 129.276437L136.34783 107.71740700000001L134.00008 101.064987L135.36936 100.673457C135.36936 100.673457 135.17396 96.956437 133.60855 94.413284C133.60855 94.413284 131.45622 83.65231 125.97838000000002 83.456902L121.67371000000001 70.935119L117.95668000000002 66.825852L115.02200000000002 58.217929999999996L129.69541 40.413L130.86928 30.04356C130.86928 30.04356 139.39662 22.43835 137.18722 10.001419999999996H12.5z');
});
it("should work when reversed", function() {
assert.equal(new SVGPathData(
'm12.5 140c0 0 7.63017 -32.95472 17.21798 -45.085701c0 0 8.60793 -7.043235 12.91188 -7.630171c4.30396 -0.586937 31.109058 -1.173872 31.109058 -1.173872l8.021699 -9.821022h3.717026l1.173872 -15.810194l-3.521618 -3.717024l-1.564688 -9.782503l0.586937 -4.50008h1.760808c0 0 1.138927 -12.71791 0.977752 -14.0879c-0.160463 -1.36928 4.911579 -16.18532 17.628774 -18.17648c12.71719 -1.99188 35.0336 10.50851 35.0336 10.50851l-1.20525 21.55903l-2.34775 6.65242l1.36928 0.39153c0 0 -0.1954 3.71702 -1.76081 6.260173c0 0 -2.15233 10.760974 -7.63017 10.956382l-4.30467 12.521783l-3.71703 4.109267l-2.93468 8.607922l14.67341 17.80493l1.17387 10.36944c0 0 8.52734 7.60521 6.31794 20.04214h-124.68722z'
).ySymetry(150).ySymetry(150).encode(),
'M12.5 140C12.5 140 20.13017 107.04527999999999 29.71798 94.914299C29.71798 94.914299 38.32591 87.871064 42.62986 87.284128C46.93382 86.69719099999999 73.738918 86.11025599999999 73.738918 86.11025599999999L81.760617 76.289234H85.477643L86.651515 60.47904L83.129897 56.76201599999999L81.565209 46.979513L82.152146 42.479433H83.912954C83.912954 42.479433 85.051881 29.761522999999997 84.890706 28.39153300000001C84.730243 27.022253000000006 89.802285 12.206212999999991 102.51947999999999 10.215053000000012C115.23666999999999 8.223173000000003 137.55308 20.723563000000013 137.55308 20.723563000000013L136.34783 42.28259299999999L134.00008 48.935013L135.36936 49.326543C135.36936 49.326543 135.17396 53.043563000000006 133.60855 55.586715999999996C133.60855 55.586715999999996 131.45622 66.34769 125.97838000000002 66.543098L121.67371000000001 79.064881L117.95668000000002 83.174148L115.02200000000002 91.78207L129.69541 109.587L130.86928 119.95644C130.86928 119.95644 139.39662 127.56165 137.18722 139.99858H12.5z');
});
});

View File

@ -0,0 +1,44 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("SVGPathDataTransformer", function() {
it("should fail with bad args", function() {
assert.throws(function() {
new SVGPathData.Transformer();
}, 'Please provide a transform callback to receive commands.');
});
it("should fail with bad transform function", function() {
assert.throws(function() {
new SVGPathData.Transformer(function() {});
}, 'Please provide a valid transform (returning a function).');
});
it("should still work when the new operator is forgotten", function() {
assert.doesNotThrow(function() {
SVGPathData.Transformer(SVGPathData.Transformer.SCALE, 1, 1);
});
});
it("should work in streaming mode", function() {
var encoder = new SVGPathData.Transformer(SVGPathData.Transformer.SCALE, 1, 1);
encoder.write({
type: SVGPathData.Parser.LINE_TO,
relative: true,
x: 10,
y: 10
});
encoder.end();
});
});

View File

@ -0,0 +1,38 @@
var assert = (
global && global.chai
? global.chai.assert
: require('chai').assert
)
, SVGPathData = (
global && global.SVGPathData
? global.SVGPathData
: require(__dirname + '/../src/SVGPathData.js')
)
;
describe("Possitive translation", function() {
it("should fail with no args", function() {
assert.throws(function() {
new SVGPathData(
'm20,30l10,10z'
).translate().encode();
}, 'A translate transformation requires the parameter dX'
+' to be set and to be a number.');
});
it("should work with relative path", function() {
assert.equal(new SVGPathData(
'm20,30c0 0 10 20 15 30s10 20 15 30q10 20 15 30t10 10l10 10h10v10a10 10 5 1 0 10 10z'
).translate(10, 10).encode(),
'm30 40c0 0 10 20 15 30s10 20 15 30q10 20 15 30t10 10l10 10h10v10a10 10 5 1 0 10 10z');
});
it("should work with absolute path", function() {
assert.equal(new SVGPathData(
'M20,30C0 0 10 20 15 30S10 20 15 30Q10 20 15 30T10 10L10 10H10V10A10 10 5 1 0 10 10z'
).translate(10, 10).encode(),
'M30 40C10 10 20 30 25 40S20 30 25 40Q20 30 25 40T20 20L20 20H20V20A10 10 5 1 0 20 20z');
});
});