OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <title>SVGGeometryElement.getPointAtLength method</title> | |
fs
2016/10/24 10:48:52
Maybe name the file ...-getPointAtLength too for c
Shanmuga Pandi
2016/10/26 09:52:12
Done.
| |
3 <script src="../../resources/testharness.js"></script> | |
4 <script src="../../resources/testharnessreport.js"></script> | |
5 <p></p> | |
6 <script> | |
7 test(function() { | |
8 var pathElement = document.createElementNS("http://www.w3.org/2000/svg", "path "); | |
fs
2016/10/24 10:48:52
Please apply the (relevant) feedback on the getTot
| |
9 | |
10 function pointAtLength(string) { | |
11 pathElement.setAttributeNS(null, "d", string); | |
12 | |
13 var point = pathElement.getPointAtLength(700); | |
14 return "(" + Math.round(point.x) + ", " + Math.round(point.y) + ")"; | |
fs
2016/10/24 10:48:52
Maybe return an array instead and use assert_array
| |
15 } | |
16 | |
17 assert_equals(pointAtLength('M0,20 L400,20 L640,20'), "(640, 20)"); | |
18 assert_equals(pointAtLength('M0,20 L400,20 L640,20 z'), "(580, 20)"); | |
19 assert_equals(pointAtLength('M0,20 L400,20 z M 320,20 L640,20'), "(100, 20)"); | |
20 assert_equals(pointAtLength('M0,20 L20,40'), "(20, 40)"); | |
21 }, "SVGGeometryElement.getPointAtLength with SVGPathElement"); | |
22 | |
23 test(function() { | |
24 var svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg") ; | |
25 var rectElement = document.createElementNS("http://www.w3.org/2000/svg", "rect "); | |
26 svgElement.appendChild(rectElement); | |
27 document.querySelector("p").appendChild(svgElement); | |
28 | |
29 function pointAtLength(rx, ry, width, height) { | |
30 rectElement.setAttribute("rx", rx); | |
31 rectElement.setAttribute("ry", ry); | |
32 rectElement.setAttribute("width", width); | |
33 rectElement.setAttribute("height", height); | |
34 | |
35 var point = rectElement.getPointAtLength(300); | |
36 return "(" + Math.round(point.x) + ", " + Math.round(point.y) + ")"; | |
37 } | |
38 | |
39 assert_equals(pointAtLength('0', '0', '200', '300'), "(200, 100)"); | |
40 assert_equals(pointAtLength('50', '50', '200', '300'), "(200, 172)"); | |
41 }, "SVGGeometryElement.getPointAtLength with SVGRectElement"); | |
42 | |
43 test(function() { | |
44 var svgElement = document.createElementNS("http://www.w3.org/2000/svg", "svg") ; | |
45 var circleElement = document.createElementNS("http://www.w3.org/2000/svg", "ci rcle"); | |
46 svgElement.appendChild(circleElement); | |
47 document.querySelector("p").appendChild(svgElement); | |
48 | |
49 function pointAtLength(string) { | |
50 circleElement.setAttribute("r", string); | |
51 | |
52 var point = circleElement.getPointAtLength(100); | |
53 return "(" + Math.round(point.x) + ", " + Math.round(point.y) + ")"; | |
54 } | |
55 | |
56 assert_equals(pointAtLength('10'), "(10, 0)"); | |
57 assert_equals(pointAtLength('100'), "(54, 84)"); | |
58 }, "SVGGeometryElement.getPointAtLength with SVGCircleElement"); | |
59 </script> | |
OLD | NEW |