|
6 | 6 | <link rel="help" href="https://w3c.github.io/svgwg/svg2-draft/types.html#__svg__SVGGraphicsElement__getBBox"> |
7 | 7 | <link rel="help" href="https://w3c.github.io/svgwg/svg2-draft/coords.html#BoundingBoxes"> |
8 | 8 | <svg> |
| 9 | + <!-- negative values are errors, auto will be substituted, which for width, |
| 10 | + height and r is 0 --> |
9 | 11 | <rect id="rect1" x="1" y="2" width="-10" height="20"/> |
10 | 12 | <rect id="rect2" x="1" y="2" width="10" height="-20"/> |
11 | 13 | <circle id="circle" cx="1" cy="2" r="-10"/> |
| 14 | + <!-- specifying a negative value for rx or ry is invalid so the other valid |
| 15 | + radius will be substituted only 0 will produce a degenerate ellipse --> |
12 | 16 | <ellipse id="ellipse1" cx="1" cy="12" rx="-5" ry="10"/> |
13 | 17 | <ellipse id="ellipse2" cx="6" cy="2" rx="5" ry="-10"/> |
| 18 | + <circle id="ellipse1-ref" cx="1" cy="12" r="10"/> |
| 19 | + <circle id="ellipse2-ref" cx="6" cy="2" r="5"/> |
| 20 | + <ellipse id="ellipse3" cx="1" cy="12" rx="0" ry="10"/> |
| 21 | + <ellipse id="ellipse4" cx="6" cy="2" rx="5" ry="0"/> |
14 | 22 | <image id="image1" x="1" y="2" width="-10" height="20" href="/images/green-100x50.png"/> |
15 | 23 | <image id="image2" x="1" y="2" width="10" height="-20" href="/images/green-100x50.png"/> |
16 | 24 | <image id="image3" x="1" y="2" width="-10" height="20"/> |
|
20 | 28 | </svg> |
21 | 29 | <script> |
22 | 30 | function assertBBox(id, x, y, width, height) { |
23 | | - var bbox = document.getElementById(id).getBBox(); |
| 31 | + let bbox = document.getElementById(id).getBBox(); |
24 | 32 | assert_equals(bbox.x, x, id + ': x'); |
25 | 33 | assert_equals(bbox.y, y, id + ': y'); |
26 | 34 | assert_equals(bbox.width, width, id + ': width'); |
27 | 35 | assert_equals(bbox.height, height, id + ': height'); |
28 | 36 | } |
29 | 37 |
|
| 38 | +function assertSameBBox(id1, id2) { |
| 39 | + let bbox = document.getElementById(id2).getBBox(); |
| 40 | + assertBBox(id1, bbox.x, bbox.y, bbox.width, bbox.height); |
| 41 | +} |
| 42 | + |
30 | 43 | function testBBox(id, x, y, width, height) { |
31 | 44 | test(() => { assertBBox(id, x, y, width, height) }, id); |
32 | 45 | } |
33 | 46 |
|
| 47 | +function testSameBBox(id1, id2) { |
| 48 | + test(() => { assertSameBBox(id1, id2) }, id1); |
| 49 | +} |
| 50 | + |
34 | 51 | // Per resolution (issue #1018): if a shape is not rendered (negative or |
35 | 52 | // zero dimension), getBBox returns (0, 0, 0, 0). |
36 | 53 | testBBox('rect1', 0, 0, 0, 0); |
37 | 54 | testBBox('rect2', 0, 0, 0, 0); |
38 | 55 | testBBox('circle', 0, 0, 0, 0); |
39 | | -testBBox('ellipse1', 0, 0, 0, 0); |
40 | | -testBBox('ellipse2', 0, 0, 0, 0); |
| 56 | +testSameBBox('ellipse1', 'ellipse1-ref'); |
| 57 | +testSameBBox('ellipse2', 'ellipse2-ref'); |
| 58 | +testBBox('ellipse3', 0, 0, 0, 0); |
| 59 | +testBBox('ellipse4', 0, 0, 0, 0); |
41 | 60 | testBBox('image3', 0, 0, 0, 0); |
42 | 61 | testBBox('image4', 0, 0, 0, 0); |
43 | 62 | testBBox('foreign1', 0, 0, 0, 0); |
|
0 commit comments