In Mozilla's documentation for their rectangle class Rect
, one of the functions they mention is the map()
function, which takes a function as a parameter. The description of the function is:
Calls a specified function on each of the left, right, top, and bottom values of the rectangle.
But the inherent attributes of the rectangle are x
, y
, width
, and height
. While the "right" and "bottom" of the rectangle can easily be calculated, it just seems weird that the map
function would modify calculated values, and not the actual attributes of the Rect
object. Is this a typo in the documentation? It wouldn't be that weird; I found several other small typos while looking though that page of documentation, alone, but this one actually affects how the function works. Since the Rect
class isn't one that's meant to be instantiated, I don't know how to test Mozilla's code to check this myself, either.
I understand the concept of a map function and what it does, but I don't routinely use them, so maybe this is just how they typically work. It would make sense to call the same function on four of the same types of values (left, top, right, bottom: positions) rather than on two of one (x, y: positions) and two of another (width, height: quantities).
By looking up the Rect object on DXR, it seems that the documentation is correct.
By doing some codaeology (I made up this word, code+archeology :-D), I found that the map function was introduced with bug 520910. The reviewer didn't seem to have any concern with using right
and bottom
in place of height
and width
.
Opinion: I would dare say that it makes sense to map on four of the same types of values (left, top, right, bottom: positions), as you said. That even makes more sense because width
and height
are only used to initialize the Rect
: right
and bottom
are the ones always used internally.
Pro-Tip: If you want to check Mozilla's code, you can take a peek at the code (and even quickly search in it!) using DXR.