OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>SVGGeometryElement.getPointAtLength method (element attached)</title> |
| 3 <script src="../../resources/testharness.js"></script> |
| 4 <script src="../../resources/testharnessreport.js"></script> |
| 5 <svg></svg> |
| 6 <script> |
| 7 setup(function() { |
| 8 window.svgElement = document.querySelector("svg"); |
| 9 }); |
| 10 |
| 11 test(function() { |
| 12 var pathElement = document.createElementNS("http://www.w3.org/2000/svg", "path
"); |
| 13 svgElement.appendChild(pathElement); |
| 14 |
| 15 function pointAtLength(string) { |
| 16 pathElement.setAttribute("d", string); |
| 17 |
| 18 var point = pathElement.getPointAtLength(700); |
| 19 return [Math.round(point.x), Math.round(point.y)]; |
| 20 } |
| 21 |
| 22 assert_array_equals(pointAtLength('M0,20 L400,20 L640,20'), [640, 20]); |
| 23 assert_array_equals(pointAtLength('M0,20 L400,20 L640,20 z'), [580, 20]); |
| 24 assert_array_equals(pointAtLength('M0,20 L400,20 z M 320,20 L640,20'), [100, 2
0]); |
| 25 assert_array_equals(pointAtLength('M0,20 L20,40'), [20, 40]); |
| 26 }, document.title + " with SVGPathElement"); |
| 27 |
| 28 test(function() { |
| 29 var rectElement = document.createElementNS("http://www.w3.org/2000/svg", "rect
"); |
| 30 svgElement.appendChild(rectElement); |
| 31 |
| 32 function pointAtLength(rx, ry, width, height) { |
| 33 rectElement.setAttribute("rx", rx); |
| 34 rectElement.setAttribute("ry", ry); |
| 35 rectElement.setAttribute("width", width); |
| 36 rectElement.setAttribute("height", height); |
| 37 |
| 38 var point = rectElement.getPointAtLength(300); |
| 39 return [Math.round(point.x), Math.round(point.y)]; |
| 40 } |
| 41 |
| 42 assert_array_equals(pointAtLength(0, 0, 200, 300), [200, 100]); |
| 43 assert_array_equals(pointAtLength(50, 50, 200, 300), [200, 172]); |
| 44 }, document.title + " with SVGRectElement"); |
| 45 |
| 46 test(function() { |
| 47 var circleElement = document.createElementNS("http://www.w3.org/2000/svg", "ci
rcle"); |
| 48 svgElement.appendChild(circleElement); |
| 49 |
| 50 function pointAtLength(radius) { |
| 51 circleElement.setAttribute("r", radius); |
| 52 |
| 53 var point = circleElement.getPointAtLength(100); |
| 54 return [Math.round(point.x), Math.round(point.y)]; |
| 55 } |
| 56 |
| 57 assert_array_equals(pointAtLength(10), [10, 0]); |
| 58 assert_array_equals(pointAtLength(100), [54, 84]); |
| 59 }, document.title + " with SVGCircleElement"); |
| 60 </script> |
OLD | NEW |