.NET Rectangle Off By 1
After working with the .NET GDI+ Rectangle object, I've noticed that if I create a rectangle that is X:0 * Y:0 * Width:100 * Height:100, the Right
and Bottom
properties are set to 100, 100. Shouldn't this be 99, 99? 0 - 99 is 100 pixels. 0 - 100 is 101 pixels.
FWIW, the documentation does say the right is computed by x + width
and the bottom is y + height
, bu开发者_开发问答t is that correct? Perhaps "correct" doesn't matter here as long it's consistent?
All I know is that it is somewhat (read... very) annoying!
It depends on whether you regard the coordinates as labelling whole pixels, or labelling points between pixels. If you regard them as infinitely small points, then the number of pixels between (0, 0) and (100, 0) is 100 pixels. If, however, you regard them as labelling the pixels - such that both pixels (0, 0) and (100, 0) are included in the rectangle, then that's clearly 101 pixels wide as you say.
It would be nice to have this spelled out somewhere, of course. I suspect it is, but I haven't run across the relevant documentation. Hopefully someone can provide a link :)
From the documentation:
"The dimensions of the client area are also described by a Rectangle structure that contains client coordinates for the area. In all cases, the upper-left coordinate of the rectangle is included in the client area, while the lower-right coordinate is excluded. Graphics operations do not include the right and lower edges of a client area."
So, your x points comprise the set [0,100) which is 100 values.
精彩评论