04-06-2011 02:49 PM
Hi,
just notised strange thing:
XYRect rc = new XYRect(0, 0, 14, 18);
int x = rc.x; //0
int y = rc.y; //0
int width = rc.width; //14
int height = rc.height; //18
int x2 = rc.X2(); //14!!!!!
int y2 = rc.Y2(); //18!!!!
Shouldn't X2 and Y2 be zero based? x and y are zero based, so it strange that x2 and y2 aren't.
Just wondering...
04-06-2011 03:20 PM
I think that this is because they allow you to create a rectangle with 0 width or height (or both). If it instead said that X2() was 13, a width of 1 and 0 would be equal.
04-06-2011 03:27 PM
Well, if we create rect with coords (0, 0, 0, 0), it mean that rect has
width = 0
height = 0
If X2 and Y2 would be zero-based, and X2 = 0, Y2 = 0, than width and height of this rect would be 0, not 1.
In current implementation X2 and Y2 ALWAYS equal width and height...
Still don`t understand what`s the point.
Thank you!
04-06-2011 03:41 PM
I think the easiest way to think about it is that by giving it a width or height of 0 you are making it a vertical or horizontal line. If you give it a height AND width of 0 you get a point.
04-06-2011 05:13 PM
Yeah, it would make sense, but not in this case, because if you will create rect like this:
XYRect rc = new XYRect(0, 0, 0/*width*/, 0/*height*/);
rc.X2() and rc.Y2() will have values 0 as well as width and height will be equal to zero, which doesn't make any sense, because regarding to your theory it shoud be point, and point should have width and height 1.
Ok, now I'm confused even more...
04-06-2011 05:21 PM
Try thinking of this more in the geometry sense and not the "pixels are a width of 1" way. Lines are defined as something that has has only a length but no width. Points have no width or height. Now because we have to map points to *something*, they are mapped to a pixel, which is actually a fake unit of measurement (they come in different sizes so you can't just say something is a pixel wide and everyone knows how wide that is).
Maybe if you do your measurements from the middle of a pixel rather than the edge that will make it easier. So if you start in the middle of a pixel and go one pixel's width to the right, you are on 2 pixels but only have a width of 1 pixel.