Bug in Draw2D Ellipse class [message #70247] |
Fri, 14 March 2003 01:28  |
Eclipse User |
|
|
|
Originally posted by: jayuen.alumni.uwaterloo.ca
Hi:
Based on some experimentation with our application, we have found a bug in
the org.eclipse.draw2d.Ellipse class in the containsPoint(int, int) method.
public boolean containsPoint(int x, int y) {
Rectangle r = getBounds();
int ux = x - r.x - r.width/2;
int uy = y - r.y - r.height/2;
return ((ux*ux) << 10 ) / (r.width*r.width)
+ ((uy*uy) << 10) / (r.height*r.height) <= 256;
}
The problem here is that when ux or uy are too large, the combination of
squaring either ux or uy and shifting by 10 bits overflows the integer and
the number becomes negative. An example of "too large" is 2000. This
causes the return value to be true which may not be the desired effect.
A fix for this is to declare ux and uy as longs rather than ints.
Jason
|
|
|
|
|
Re: Bug in Draw2D Ellipse class [message #70470 is a reply to message #70451] |
Fri, 14 March 2003 11:25   |
Eclipse User |
|
|
|
Originally posted by: none.us.ibm.com
Good point, we should do the bounding box test first, and if that fails, the
ellipse test wouldn't execute.
"Jason Yuen" <jayuen@alumni.uwaterloo.ca> wrote in message
news:b4stt8$mlc$1@rogue.oti.com...
> Actually, we came across the bug when we had a large FreeformLayer area in
> our editor. If we mouse-clicked at a large enough distance away from an
> elliptical figure, the algorithm in the Figure class for finding a figure
at
> the clicked mouse coordinates eventually hit the containsPoint method for
> the Ellipse and failed (well, passed when it shouldn't have)
>
> "Randy Hudson" <none@us.ibm.com> wrote in message
> news:b4ss13$kn5$1@rogue.oti.com...
> > http://dev.eclipse.org/bugs/show_bug.cgi?id=22701
> > We were assuming that ellipses would ever get so big. Oh well. We will
> fix
> > this.
> >
> > "Jason Yuen" <jayuen@alumni.uwaterloo.ca> wrote in message
> > news:b4rsub$suk$1@rogue.oti.com...
> > > Hi:
> > >
> > > Based on some experimentation with our application, we have found a
bug
> in
> > > the org.eclipse.draw2d.Ellipse class in the containsPoint(int, int)
> > method.
> > >
> > > public boolean containsPoint(int x, int y) {
> > > Rectangle r = getBounds();
> > > int ux = x - r.x - r.width/2;
> > > int uy = y - r.y - r.height/2;
> > >
> > > return ((ux*ux) << 10 ) / (r.width*r.width)
> > > + ((uy*uy) << 10) / (r.height*r.height) <= 256;
> > > }
> > >
> > > The problem here is that when ux or uy are too large, the combination
of
> > > squaring either ux or uy and shifting by 10 bits overflows the integer
> and
> > > the number becomes negative. An example of "too large" is 2000. This
> > > causes the return value to be true which may not be the desired
effect.
> > >
> > > A fix for this is to declare ux and uy as longs rather than ints.
> > >
> > > Jason
> > >
> > >
> > >
> > >
> >
> >
>
>
|
|
|
Re: Bug in Draw2D Ellipse class [message #70824 is a reply to message #70470] |
Sat, 15 March 2003 11:17  |
Eclipse User |
|
|
|
Hm, If i remember correctly there must be
if (super.containsPoint(x, y))
By the way Randy you predicted a problem with overflow just a few days
before first user hit into it :) I think that long instead of int will be
sufficient.
"Randy Hudson" <none@us.ibm.com>
|
|
|
Powered by
FUDForum. Page generated in 0.04898 seconds