<!DOCTYPE html>
<title>SVGSVGElement getIntersectionList() and getEnclosureList() behavior</title>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<svg id="svg" xmlns="http://www.w3.org/2000/svg" width="200" height="200">
<g id="container" transform="translate(50, 50)">
<g id="subcontainer"></g>
</g>
</svg>
<script>
const svg = document.getElementById('svg');
const container = document.getElementById('container');
const subcontainer = document.getElementById('subcontainer');
for (var i = 0; i < 10; i++) {
for (var j = 0; j < 10; j++) {
var r = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
r.setAttribute('x', i * 10 + 1);
r.setAttribute('y', j * 10 + 1);
r.setAttribute('width', 8);
r.setAttribute('height', 8);
r.setAttribute('fill', 'green');
if (j < 5)
container.appendChild(r);
else
subcontainer.appendChild(r);
}
}
function check_enclosure_and_intersection(ref_id, enclosure1, intersection1, enclosure2, intersection2) {
const reference_element = ref_id ? document.getElementById(ref_id) : null;
const rect = svg.createSVGRect();
rect.x = rect.y = 50;
rect.width = rect.height = 100;
assert_equals(svg.getEnclosureList(rect, reference_element).length, enclosure1);
assert_equals(svg.getIntersectionList(rect, reference_element).length, intersection1);
rect.x = rect.y = 55;
rect.width = rect.height = 90;
assert_equals(svg.getEnclosureList(rect, reference_element).length, enclosure2);
assert_equals(svg.getIntersectionList(rect, reference_element).length, intersection2);
}
const test = async_test();
window.onload = test.step_func_done(() => {
check_enclosure_and_intersection(null, 100, 100, 64, 100);
check_enclosure_and_intersection('container', 100, 100, 64, 100);
check_enclosure_and_intersection('subcontainer', 50, 50, 32, 50);
// Zooming should not affect the results.
if (window.testRunner) {
testRunner.zoomPageIn();
testRunner.zoomPageIn();
testRunner.zoomPageIn();
}
check_enclosure_and_intersection(null, 100, 100, 64, 100);
check_enclosure_and_intersection('container', 100, 100, 64, 100);
check_enclosure_and_intersection('subcontainer', 50, 50, 32, 50);
// But a viewbox transform should.
svg.setAttribute('viewBox', '0 0 150 150');
check_enclosure_and_intersection(null, 36, 49, 25, 36);
check_enclosure_and_intersection('container', 36, 49, 25, 36);
check_enclosure_and_intersection('subcontainer', 6, 14, 0, 6);
});
</script>