views:

58

answers:

2

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, but 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!

+2  A: 

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 :)

Jon Skeet
If that happens to be the case, then there should be at least two flavors of Rectangle. Why would anyone dealing with a pixelated device want to label points between pixels?
@roygbiv: I tend to think it's a more elegant model which works better with scaling for different DPIs, but I think it should at least be clearer.
Jon Skeet
+1  A: 

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.

Jacob G
@Jacob G - Yup that's what I said in my post.
@roygbiv- I'm sorry, but you said nothing like that in your post. You were questioning whether it was correct for the "right" property to be 100 vs 99 in your scenario. I was providing additional documentation supporting the fact that it being 100 is correct. I'm not sure how answering the question you asked warrants a downvote.
Jacob G