Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: LayoutTests/svg/custom/path-getTotalLength.svg

Issue 233063003: Improve the reliability and accuracy of SVG getTotalLength (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Improved Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | LayoutTests/svg/custom/path-getTotalLength-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <svg xmlns="http://www.w3.org/2000/svg"> 1 <svg xmlns="http://www.w3.org/2000/svg">
2 <g id='log' /> 2 <g id='log' />
3 <script> 3 <script>
4 <![CDATA[ 4 <![CDATA[
5 if (window.testRunner) 5 if (window.testRunner)
6 testRunner.dumpAsText(); 6 testRunner.dumpAsText();
7 7
8 var svgNS = "http://www.w3.org/2000/svg"; 8 var svgNS = "http://www.w3.org/2000/svg";
9 var pathElement = document.createElementNS(svgNS, 'path'); 9 var pathElement = document.createElementNS(svgNS, 'path');
10 var errorTolerance = .1;
11 10
12 var logOffset = 20; 11 var logOffset = 20;
13 function result(didPass, string) { 12 function result(didPass, string) {
14 var newText = document.createElementNS(svgNS, "text"); 13 var newText = document.createElementNS(svgNS, "text");
15 newText.setAttribute("x", 10); 14 newText.setAttribute("x", 10);
16 newText.setAttribute("y", logOffset); 15 newText.setAttribute("y", logOffset);
17 logOffset += 20; 16 logOffset += 20;
18 newText.textContent = string; 17 newText.textContent = string;
19 var newTspan = document.createElementNS(svgNS, "tspan"); 18 var newTspan = document.createElementNS(svgNS, "tspan");
20 if (didPass) { 19 if (didPass) {
21 newTspan.textContent = "PASS: "; 20 newTspan.textContent = "PASS: ";
22 newTspan.style.fill = "green"; 21 newTspan.style.fill = "green";
23 } else { 22 } else {
24 newTspan.textContent = "FAIL: "; 23 newTspan.textContent = "FAIL: ";
25 newTspan.style.fill = "red"; 24 newTspan.style.fill = "red";
26 } 25 }
27 newText.insertBefore(newTspan, newText.firstChild); 26 newText.insertBefore(newTspan, newText.firstChild);
28 document.getElementById('log').appendChild(newText); 27 document.getElementById('log').appendChild(newText);
29 } 28 }
30 29
31 function expectLength(path, expectedLength) { 30 function expectLength(path, expectedLength, errorTolerance) {
32 pathElement.setAttribute("d", path); 31 pathElement.setAttribute("d", path);
33 32
34 var actualLength; 33 var actualLength;
35 try { 34 try {
36 actualLength = pathElement.getTotalLength(); 35 actualLength = pathElement.getTotalLength();
37 if (Math.abs(actualLength - expectedLength) < errorTolerance) 36 if (Math.abs(actualLength - expectedLength) < errorTolerance)
38 result(true, path + "\" = " + actualLength); 37 result(true, path + " = " + actualLength);
39 else 38 else
40 result(false, path + "\" expected: " + expectedLength + " ac tual: " + actualLength); 39 result(false, path + " expected: " + expectedLength + " actu al: " + actualLength);
41 } catch(e) { 40 } catch(e) {
42 result(false, path + "\" expected: " + expectedLength + " got ex ception: " + e); 41 result(false, path + " expected: " + expectedLength + " got exce ption: " + e);
43 } 42 }
44 } 43 }
45 44
46 var errorCount = 0; 45 var errorCount = 0;
47 46
48 // Tests go here: 47 // Tests go here:
49 expectLength('M 0 0 L 100 0 L 100 100 L 0 100 Z', 400); 48 expectLength('M 0 0 L 100 0 L 100 100 L 0 100 Z', 400, 0.000001);
50 expectLength('M 0 0 l 100 0 l 0 100 l -100 0 Z', 400); 49 expectLength('M 0 0 l 100 0 l 0 100 l -100 0 Z', 400, 0.000001);
51 expectLength('M 0 0 t 0 100', 100); 50 expectLength('M 0 0 t 0 100', 100, 0.1);
52 expectLength('M 0 0 Q 55 50 100 100', 141.4); // I'm not sure if this i s actually right 51 expectLength('M 0 0 Q 55 50 100 100', 141.4803314, 0.000001);
52 expectLength('M 778.4191616766467 375.19086364081954 C 781.239563 375.19 08569 786.8525244750526 346.60170830052556 786.8802395209582 346.87991373394766' , 29.86020, 0.0001);
53 expectLength('M 0 0 C 0.00001 0.00001 0.00002 0.00001 0.00003 0', 0.0000 344338, 0.000000001);
53 ]]> 54 ]]>
54 </script> 55 </script>
55 </svg> 56 </svg>
OLDNEW
« no previous file with comments | « no previous file | LayoutTests/svg/custom/path-getTotalLength-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698