2 <title>getBBox tests</title>
3 <script src=../../resources/testharness.js></script>
4 <script src=../../resources/testharnessreport.js></script>
5 <div id="testcontainer">
6 <svg width="1" height="1" visibility="hidden">
8 <polygon id="p1" fill="none" stroke="red" />
9 <rect id="r1" x="50" y="50" width="50" height="50" fill="green" />
12 <rect id="r2" x="50" y="50" width="50" height="50" fill="green" />
13 <rect id="r3" x="20" y="20" width="20" height="0" fill="red" />
14 <rect id="r4" x="120" y="20" width="20" height="20" fill="blue" style="display:none" />
15 <ellipse id="c1" cx="20" cy="120" rx="0" ry="20" fill="black" />
17 <rect id="r5" x="120" y="120" width="-1" height="100" fill="cyan" />
21 <path id="p2" fill="none" stroke="red" />
22 <rect id="r6" x="50" y="50" width="50" height="50" fill="green" />
23 <!-- The following path should be included in the bbox. -->
27 <polyline id="p3" fill="none" stroke="red" />
28 <rect id="r7" x="50" y="50" width="50" height="50" fill="green" />
31 <path id="p4" d="M3"/>
32 <rect id="r8" x="50" y="50" width="50" height="50" fill="green" />
35 <polygon id="p5" points="47" fill="none" stroke="red" />
36 <rect id="r9" x="50" y="50" width="50" height="50" fill="green" />
39 <polyline id="p6" points="47" fill="none" stroke="red" />
40 <rect id="r10" x="50" y="50" width="50" height="50" fill="green" />
43 <path id="p7" d="M40 20h0" fill="none" stroke="red" />
44 <rect id="r11" x="50" y="50" width="50" height="50" fill="green" />
50 var EPSILON = Math.pow(2, -24); // float epsilon
52 function assert_rect_approx_equals(rect, expected, epsilon) {
53 assert_approx_equals(rect.x, expected.x, epsilon, "x");
54 assert_approx_equals(rect.y, expected.y, epsilon, "y");
55 assert_approx_equals(rect.width, expected.width, epsilon, "width");
56 assert_approx_equals(rect.height, expected.height, epsilon, "height");
60 assert_rect_approx_equals(document.getElementById("p1").getBBox(), {"x":0, "y":0, "width":0, "height":0 }, EPSILON);
61 }, "getBBox on polygon with no points attribute");
63 assert_rect_approx_equals(document.getElementById("p3").getBBox(), {"x":0, "y":0, "width":0, "height":0}, EPSILON);
64 }, "getBBox on polyline with no points attribute");
66 assert_rect_approx_equals(document.getElementById("p2").getBBox(), {"x":0, "y":0, "width":0, "height":0 }, EPSILON);
67 }, "getBBox on path with no d attribute");
69 assert_rect_approx_equals(document.getElementById("p4").getBBox(), {"x":0, "y":0, "width":0, "height":0 }, EPSILON);
70 }, "getBBox on path with no valid path segments in d attribute");
72 assert_rect_approx_equals(document.getElementById("p5").getBBox(), {"x":0, "y":0, "width":0, "height":0 }, EPSILON);
73 }, "getBBox on polygon with no valid point in the points attribute");
75 assert_rect_approx_equals(document.getElementById("p6").getBBox(), {"x":0, "y":0, "width":0, "height":0 }, EPSILON);
76 }, "getBBox on polyline with no valid point in the points attribute");
78 assert_rect_approx_equals(document.getElementById("g1").getBBox(), document.getElementById("r1").getBBox(), EPSILON);
79 }, "polygon doesn't contribute to parent bbox");
81 assert_rect_approx_equals(document.getElementById("g1").getBBox(), document.getElementById("r2").getBBox(), EPSILON);
82 }, "group with hidden child");
84 assert_rect_approx_equals(document.getElementById("g3").getBBox(), document.getElementById("r6").getBBox(), EPSILON);
85 }, "path doesn't contribute to parent bbox");
87 assert_rect_approx_equals(document.getElementById("g5").getBBox(), document.getElementById("r8").getBBox(), EPSILON);
88 }, "path with only invalid segments doesn't contribute to parent bbox");
90 assert_rect_approx_equals(document.getElementById("g4").getBBox(), document.getElementById("r7").getBBox(), EPSILON);
91 }, "polyline doesn't contribute to parent bbox");
93 assert_rect_approx_equals(document.getElementById("g6").getBBox(), document.getElementById("r9").getBBox(), EPSILON);
94 }, "polygon with no valid points doesn't contribute to parent bbox");
96 assert_rect_approx_equals(document.getElementById("g7").getBBox(), document.getElementById("r10").getBBox(), EPSILON);
97 }, "polyline with no valid points doesn't contribute to parent bbox");
99 assert_rect_approx_equals(document.getElementById("p7").getBBox(), {"x":40, "y":20, "width":0, "height":0 }, EPSILON);
100 }, "getBBox on path with no height");
102 assert_rect_approx_equals(document.getElementById("g8").getBBox(), {"x":40, "y":20, "width":60, "height":80 }, EPSILON);
103 }, "path with no height should contribute to parent bbox");