Intersects [message #179043] |
Mon, 25 April 2005 11:26  |
Eclipse User |
|
|
|
Originally posted by: james.willans.xactium.com
After almost two years of using GEF, I have to say that sometimes the
coordinate system still confuses me. In this instance I want to simply
test to see whether two figures intersect (one is some text on a
connection edge, the other is a node - although this detail is probably
not relevant).
So given those two figures:
IFigure text;
IFigure node;
My understanding is that text.getBounds().intersect(node.getBounds()) is
not guaranteed to work since each figure return the bounds according to
its coordinate system. However I thought that ensuring both bounds were
absolute:
Rectangle textRect = text.getBounds().getCopy();
text.translateToAbsolute(textRect);
Rectangle nodeRect = node.getBounds().getCopy();
node.translateToAbsolute(nodeRect);
would guarantee that both rectangles are in the same coordinate system,
and I could susbsequently test for:
textRect.getBounds().intersects(nodeRect);
However, this doesn't seem to work. Any ideas?
Thanks.
James
|
|
|
|
Re: Intersects [message #179205 is a reply to message #179043] |
Mon, 25 April 2005 17:36  |
Eclipse User |
|
|
|
"James Willans" <james.willans@xactium.com> wrote in message
news:10ff81388d9b5a5c4c495f5326d84e10$1@www.eclipse.org...
> After almost two years of using GEF, I have to say that sometimes the
> coordinate system still confuses me. In this instance I want to simply
> test to see whether two figures intersect (one is some text on a
> connection edge, the other is a node - although this detail is probably
> not relevant).
>
> So given those two figures:
>
> IFigure text;
> IFigure node;
>
> My understanding is that text.getBounds().intersect(node.getBounds()) is
> not guaranteed to work since each figure return the bounds according to
> its coordinate system. However I thought that ensuring both bounds were
> absolute:
>
> Rectangle textRect = text.getBounds().getCopy();
> text.translateToAbsolute(textRect);
>
> Rectangle nodeRect = node.getBounds().getCopy();
> node.translateToAbsolute(nodeRect);
>
> would guarantee that both rectangles are in the same coordinate system,
> and I could susbsequently test for:
>
> textRect.getBounds().intersects(nodeRect);
There is no getBounds() method on Rectangle, so you couldn't possibly be
doing exactly what you mention here. If you're invoking text.getBounds()
here, that obviously is your problem.
>
> However, this doesn't seem to work. Any ideas?
>
> Thanks.
>
> James
>
>
>
>
|
|
|
Powered by
FUDForum. Page generated in 0.04957 seconds