Welcome to the Official BlackBerry® Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
New Contributor
Galian
Posts: 7
Registered: 05-07-2010
My Carrier: none

XYRect bug?

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...

Please use plain text.
Developer
jprofitt
Posts: 604
Registered: 12-27-2010

Re: XYRect bug?

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.

Please use plain text.
New Contributor
Galian
Posts: 7
Registered: 05-07-2010
My Carrier: none

Re: XYRect bug?

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!

Please use plain text.
Developer
jprofitt
Posts: 604
Registered: 12-27-2010

Re: XYRect bug?

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.

Please use plain text.
New Contributor
Galian
Posts: 7
Registered: 05-07-2010
My Carrier: none

Re: XYRect bug?

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...

Please use plain text.
Developer
jprofitt
Posts: 604
Registered: 12-27-2010

Re: XYRect bug?

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.

Please use plain text.