Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/dom/svg/test/   (Browser von der Mozilla Stiftung Version 136.0.1©)  Datei vom 10.2.2025 mit Größe 5 kB image not shown  

Quelle  test_SVGMatrix.xhtml   Sprache: unbekannt

 
Spracherkennung für: .xhtml vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>Test SVGMatrix behavior</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="matrixUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content">
  <svg xmlns="http://www.w3.org/2000/svg" width="100%" height="1" id="svg">
    <g id="g" transform="translate(1020)"/>
  </svg>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
<![CDATA[

SimpleTest.waitForExplicitFinish();

function main() {
  var tests =
    [ testCreateMatrix,
      testMultiply,
      testInverse,
      testTranslate,
      testScale,
      testScaleNonUniform,
      testRotate,
      testRotateFromVector,
      testFlipX,
      testFlipY,
      testSkewX,
      testSkewY,
    ];
  for (var i = 0; i < tests.length; i++) {
    tests[i]();
  }
  SimpleTest.finish();
}

function testCreateMatrix() {
  var svg = $("svg");
  var m = svg.createSVGMatrix();

  // Should be initialised to identity
  cmpMatrix(m, [100100],
            "createMatrix should produce identity matrix");

  // Should return a new object each time;
  ok(m != svg.createSVGMatrix(),
     "Got identical objects when creating new matrix");
}

// SVGMatrix multiply(in SVGMatrix secondMatrix);
function testMultiply() {
  // This is the example from SVG 1.1 section 7.5
  var m1 = createMatrix(10015090);
  var m2 = createMatrix(0.707, -0.7070.7070.70700);
  var m3 = createMatrix(1001130160);
  var result = m1.multiply(m2).multiply(m3);
  roughCmpMatrix(result, [0.707, -0.7070.7070.707255.03111.21],
    "Unexpected result after multiplying matrices");

  // Check orig matrices are unchanged
  cmpMatrix(m1, [10015090], "Matrix changed after multiplication");
  roughCmpMatrix(m2, [0.707, -0.7070.7070.70700],
                 "Matrix changed after multiplication");
  cmpMatrix(m3, [1001130160], "Matrix changed after multiplication");
}

// SVGMatrix inverse() raises(SVGException);
function testInverse() {
  // Test inversion
  var m = createMatrix(2004110, -50);
  roughCmpMatrix(m.inverse(), [0.5000.25, -5512.5],
    "Unexpected result after inverting matrix");

  // Test non-invertable
  m = createMatrix(001000);
  try {
    m.inverse();
    ok(false, "Failed to throw exception when inverting singular matrix");
  } catch (e) {
    is(e.name, "InvalidStateError",
      "Got unexpected exception " + e + ", expected InvalidStateError");
  }
}

// SVGMatrix translate(in float x, in float y);
function testTranslate() {
  var m = createMatrix(2001120100);
  roughCmpMatrix(m.translate(100, -50), [200132050],
    "Unexpected result after translate");
}

// SVGMatrix scale(in float scaleFactor);
function testScale() {
  var m = createMatrix(2001120100);
  roughCmpMatrix(m.scale(0.5), [1000.5120100],
    "Unexpected result after scale");
}

// SVGMatrix scaleNonUniform(in float scaleFactorX, in float scaleFactorY);
function testScaleNonUniform() {
  var m = createMatrix(2001120100);
  roughCmpMatrix(m.scaleNonUniform(0.5, -3), [100, -3120100],
    "Unexpected result after scaleNonUniform");
}

// SVGMatrix rotate(in float angle);
function testRotate() {
  var m = createMatrix(2001120100);
  roughCmpMatrix(m.rotate(45),
                 [2 * Math.cos(Math.PI / 4), Math.sin(Math.PI / 4),
                  2 * -Math.sin(Math.PI / 4), Math.cos(Math.PI / 4),
                  120100],
                 "Unexpected result after rotate");
}

// SVGMatrix rotateFromVector(in float x, in float y) raises(SVGException);
function testRotateFromVector() {
  var m = createMatrix(2001120100);
  // Make a 150 degree angle
  var result = m.rotateFromVector(-21.1547);
  roughCmpMatrix(result,
                 [2 * Math.cos(5 * Math.PI / 6), Math.sin(5 * Math.PI / 6),
                  2 * -Math.sin(5 * Math.PI / 6), Math.cos(5 * Math.PI / 6),
                  120100],
                 "Unexpected result after rotateFromVector");

  // Test bad input (1)
  try {
    m.rotateFromVector(10);
    ok(false, "Failed to throw exception with zero coord for rotateFromVector");
  } catch (e) {
    is(e.name, "InvalidAccessError",
      "Got unexpected exception " + e + ", expected TypeError");
  }

  // Test bad input (2)
  try {
    m.rotateFromVector(01);
    ok(false, "Failed to throw exception with zero coord for rotateFromVector");
  } catch (e) { }
}

// SVGMatrix flipX();
function testFlipX() {
  var m = createMatrix(123456);
  cmpMatrix(m.flipX(), [-1, -23456], "Unexpected result after flipX");
}

// SVGMatrix flipY();
function testFlipY() {
  var m = createMatrix(123456);
  cmpMatrix(m.flipY(), [12, -3, -456], "Unexpected result after flipY");
}

// SVGMatrix skewX(in float angle);
function testSkewX() {
  var m = createMatrix(2001120100);
  roughCmpMatrix(m.skewX(30), [202 * Math.tan(Math.PI / 6), 1120100],
                 "Unexpected result after skewX");
}

// SVGMatrix skewY(in float angle);
function testSkewY() {
  var m = createMatrix(2001120100);
  roughCmpMatrix(m.skewY(30), [2, Math.tan(Math.PI / 6), 01120100],
                 "Unexpected result after skewY");
}

window.addEventListener("load", main);

]]>
</script>
</pre>
</body>
</html>

[Dauer der Verarbeitung: 0.35 Sekunden]