Confused about the getBoundingClientRect() function in Javascript.
According to the official document, if const rect = getBoundingClientRect();, then we have
rect.width = rect.right - rect.left;
rect.height = rect.bottom - rect.top;
Does it means the left right position are left inclusive and right exclusive, i.e. [left, right)? Otherwise it should be
rect.height = rect.bottom - rect.top + 1;
Look at the following 5x5 map.
In [inclusive, inclusive] mode, the bounding rect all the 1s should be left=2, right=4, top=3, bottom=4,
and we have
width=right-left+1=4-2+1
height=bottom-top+1=4-3+1
5x5 Grid
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 1 1 1
0 0 1 1 1
A more specified question:
what does rect.left mean? Does it mean that the distance to left of client container or the ith pixel? What about rect.right?
Consider it this way :
If the gray square represents screen space, then the red square has bounding box :
{
x: 1, y: 1,
width: 3, height: 3
}
Which means that it has left=1, right=4, and therefore, right-left=width