Today I encountered a puzzling scenario involving bounding box calculations, and it seems that I have yet to fully understand the situation.
To clarify, a bounding box is described as the smallest box in which an untransformed element can fit within.
I had always believed that for groups of elements, this meant obtaining the combined bounding box of all children.
However, what I found today was unexpected:
<g id="outer">
<g id="inner" transform="translate(100, 100)">
<rect x="0" y="0" width="100" height="100" />
</g>
</g>
The bounding boxes of these elements are as follows:
rect: x: 0, y: 0, w: 100, h: 100
#inner: x: 0, y: 0, w: 100, h: 100
#outer: x: 100, y: 100, w: 100, h: 100
I expected all boxes to be identical, but clearly that is not the case. The outer box does not simply encompass the inner elements (which would have been the #inner's bbox). Instead, it takes into consideration the transformation applied to the inner elements.
Therefore, can it be concluded that the bbox of a group is essentially the union of the TRANSFORMED bboxes of its children? Or more precisely, the combination of all getBoundingClientRect
calls (assuming scroll is disregarded since getCoundingClientRect
ignores scroll)?
I would greatly appreciate a reference directing me to the specific section of the specifications regarding this matter.