<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="../../resources/js-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script>
description("This test exercises the SVGMatrix interface");
debug("");
debug("SVGMatrix constructors");
var svgroot = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
var m = null;
m = svgroot.createSVGMatrix();
if (m)
testPassed("default constructor");
else
testFailed("default constructor");
debug("");
debug("Test attributes on default matrix");
shouldBe('m.a', '1');
shouldBe('m.b', '0');
shouldBe('m.c', '0');
shouldBe('m.d', '1');
shouldBe('m.e', '0');
shouldBe('m.f', '0');
debug("");
debug("Test attributes on translate() and accumulation");
var m2 = m.translate(50,0);
m2 = m2.translate(50,50);
shouldBe('m2.a', '1');
shouldBe('m2.b', '0');
shouldBe('m2.c', '0');
shouldBe('m2.d', '1');
shouldBe('m2.e', '100');
shouldBe('m2.f', '50');
debug("");
debug("Test immutability of translate()");
shouldBe('parseFloat(m.a)', '1');
shouldBe('parseFloat(m.b)', '0');
shouldBe('parseFloat(m.c)', '0');
shouldBe('parseFloat(m.d)', '1');
shouldBe('parseFloat(m.e)', '0');
shouldBe('parseFloat(m.f)', '0');
debug("");
debug("Test attributes on scale()");
var m3 = m2.scale(5);
shouldBe('m3.a', '5');
shouldBe('m3.b', '0');
shouldBe('m3.c', '0');
shouldBe('m3.d', '5');
shouldBe('m3.e', '100');
shouldBe('m3.f', '50');
debug("");
debug("Test immutability of scale()");
shouldBe('parseFloat(m2.a)', '1');
shouldBe('parseFloat(m2.b)', '0');
shouldBe('parseFloat(m2.c)', '0');
shouldBe('parseFloat(m2.d)', '1');
shouldBe('parseFloat(m2.e)', '100');
shouldBe('parseFloat(m2.f)', '50');
debug("");
debug("Test attributes on scaleNonUniform()");
var m4 = m3.scaleNonUniform(2,1);
shouldBe('m4.a', '10');
shouldBe('m4.b', '0');
shouldBe('m4.c', '0');
shouldBe('m4.d', '5');
shouldBe('m4.e', '100');
shouldBe('m4.f', '50');
debug("");
debug("Test immutability of scaleNonUniform()");
shouldBe('parseFloat(m3.a)', '5');
shouldBe('parseFloat(m3.b)', '0');
shouldBe('parseFloat(m3.c)', '0');
shouldBe('parseFloat(m3.d)', '5');
shouldBe('parseFloat(m3.e)', '100');
shouldBe('parseFloat(m3.f)', '50');
debug("");
debug("Test rotate()");
m = svgroot.createSVGMatrix();
m2 = m.rotate(10);
shouldBe('parseFloat(m2.a.toPrecision(6))', '0.984808');
shouldBe('parseFloat(m2.b.toPrecision(6))', '0.173648');
shouldBe('parseFloat(m2.c.toPrecision(6))', '-0.173648');
shouldBe('parseFloat(m2.d.toPrecision(6))', '0.984808');
shouldBe('m.e', '0');
shouldBe('m.f', '0');
debug("");
debug("Test immutability of rotate()");
shouldBe('parseFloat(m.a)', '1');
shouldBe('parseFloat(m.b)', '0');
shouldBe('parseFloat(m.c)', '0');
shouldBe('parseFloat(m.d)', '1');
shouldBe('parseFloat(m.e)', '0');
shouldBe('parseFloat(m.f)', '0');
// TODO: write tests for rotateFromVector() and immutability
debug("");
debug("Test flipX()");
m4 = m3.flipX();
shouldBe('m4.a', '-5');
shouldBe('Math.abs(m4.b)', '0');
shouldBe('m4.c', '0');
shouldBe('m4.d', '5');
shouldBe('m4.e', '100');
shouldBe('m4.f', '50');
debug("");
debug("Test immutability of flipX()");
shouldBe('parseFloat(m3.a)', '5');
shouldBe('parseFloat(m3.b)', '0');
shouldBe('parseFloat(m3.c)', '0');
shouldBe('parseFloat(m3.d)', '5');
shouldBe('parseFloat(m3.e)', '100');
shouldBe('parseFloat(m3.f)', '50');
debug("");
debug("Test flipY()");
m4 = m3.flipY();
shouldBe('m4.a', '5');
shouldBe('m4.b', '0');
shouldBe('Math.abs(m4.c)', '0');
shouldBe('m4.d', '-5');
shouldBe('m4.e', '100');
shouldBe('m4.f', '50');
debug("");
debug("Test immutability of flipY()");
shouldBe('parseFloat(m3.a)', '5');
shouldBe('parseFloat(m3.b)', '0');
shouldBe('parseFloat(m3.c)', '0');
shouldBe('parseFloat(m3.d)', '5');
shouldBe('parseFloat(m3.e)', '100');
shouldBe('parseFloat(m3.f)', '50');
debug("");
debug("Test skewX()");
m = svgroot.createSVGMatrix();
m2 = m.skewX(30);
shouldBe('m2.a', '1');
shouldBe('m2.b', '0');
shouldBe('parseFloat(m2.c.toPrecision(6))', '0.577350');
shouldBe('m2.d', '1');
shouldBe('m2.e', '0');
shouldBe('m2.f', '0');
debug("");
debug("Test immutability of skewX()");
shouldBe('parseFloat(m.a)', '1');
shouldBe('parseFloat(m.b)', '0');
shouldBe('parseFloat(m.c)', '0');
shouldBe('parseFloat(m.d)', '1');
shouldBe('parseFloat(m.e)', '0');
shouldBe('parseFloat(m.f)', '0');
debug("");
debug("Test skewY()");
m = svgroot.createSVGMatrix();
m2 = m.skewY(30);
shouldBe('m2.a', '1');
shouldBe('parseFloat(m2.b.toPrecision(6))', '0.577350');
shouldBe('m2.c', '0');
shouldBe('m2.d', '1');
shouldBe('m2.e', '0');
shouldBe('m2.f', '0');
debug("");
debug("Test immutability of skewY()");
shouldBe('parseFloat(m.a)', '1');
shouldBe('parseFloat(m.b)', '0');
shouldBe('parseFloat(m.c)', '0');
shouldBe('parseFloat(m.d)', '1');
shouldBe('parseFloat(m.e)', '0');
shouldBe('parseFloat(m.f)', '0');
debug("");
debug("Test multiply");
m = svgroot.createSVGMatrix();
m.a = 1;
m.b = 2;
m.c = 3;
m.d = 4;
m.e = 5;
m.f = 6;
m2 = svgroot.createSVGMatrix();
m2.a = 7;
m2.b = 8;
m2.c = 9;
m2.d = 10;
m2.e = 11;
m2.f = 12;
var m3 = m.multiply(m2);
shouldBe('parseFloat(m3.a)', '31');
shouldBe('parseFloat(m3.b)', '46');
shouldBe('parseFloat(m3.c)', '39');
shouldBe('parseFloat(m3.d)', '58');
shouldBe('parseFloat(m3.e)', '52');
shouldBe('parseFloat(m3.f)', '76');
debug("");
debug("Test that multiply works in the right direction");
var tx = svgroot.createSVGMatrix();
var sx = svgroot.createSVGMatrix();
tx = tx.translate(100,0);
sx = sx.scaleNonUniform(2,1);
m = tx.multiply(sx);
shouldBe('m.a', '2');
shouldBe('m.b', '0');
shouldBe('m.c', '0');
shouldBe('m.d', '1');
shouldBe('m.e', '100');
shouldBe('m.f', '0');
debug("")
debug("Test immutability of multiply");
shouldBe('tx.a', '1');
shouldBe('tx.b', '0');
shouldBe('tx.c', '0');
shouldBe('tx.d', '1');
shouldBe('tx.e', '100');
shouldBe('tx.f', '0');
shouldBe('sx.a', '2');
shouldBe('sx.b', '0');
shouldBe('sx.c', '0');
shouldBe('sx.d', '1');
shouldBe('sx.e', '0');
shouldBe('sx.f', '0');
debug("");
debug("Test multiply with missing argument");
m = null;
try {
m = tx.multiply();
} catch(e) {}
shouldBe('m', 'null');
debug("");
debug("Test inverse");
m = svgroot.createSVGMatrix();
m = m.translate(10,20);
m = m.scale(2);
m2 = m.inverse();
shouldBe('parseFloat(m2.a)', '0.5');
shouldBe('parseFloat(m2.b)', '0');
shouldBe('parseFloat(m2.c)', '0');
shouldBe('parseFloat(m2.d)', '0.5');
shouldBe('parseFloat(m2.e)', '-5');
shouldBe('parseFloat(m2.f)', '-10');
debug("");
debug("Test immutability of inverse");
shouldBe('parseFloat(m.a)', '2');
shouldBe('parseFloat(m.b)', '0');
shouldBe('parseFloat(m.c)', '0');
shouldBe('parseFloat(m.d)', '2');
shouldBe('parseFloat(m.e)', '10');
shouldBe('parseFloat(m.f)', '20');
debug("");
debug("Test throwing exception from inverse");
m = svgroot.createSVGMatrix();
m.a = 0;
m.c = 0;
shouldThrow('m.inverse()');
debug("");
</script>
<script>
</script>
</body>
</html>