Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » how to determine whether a line segment intersects
how to determine whether a line segment intersects [message #187604] Wed, 13 July 2005 20:00 Go to next message
Eclipse UserFriend
Originally posted by: bencomo.us.ibm.com

Randy / Pratik / GEF Jedi Masters:

In my subclass of ChopboxAnchor, I have overridden the getLocation method
to check if the line segment intersects the TextFlow's bounds. However,
PointList#intersects(Rectangle) is not returns false when the line segment
intersects. Please let me know if you see what I am missing.

Thank you in advance,
Al.-

public Point getLocation(Point reference)
{
Rectangle textRect = null;
PointList pointList = new PointList();

textRect = taskFigure.getLabel().getBounds().getCopy();
taskFigure.getLabel().translateToAbsolute(textRect);

Rectangle r = Rectangle.SINGLETON;
r.setBounds(getBox());
r.translate(-1, -1);
r.resize(1, 1);

getOwner().translateToAbsolute(r);

float centerX = r.x + 0.5f * r.width;
float centerY = r.y + 0.5f * r.height;

if (r.isEmpty() || (reference.x == (int) centerX && reference.y ==
(int) centerY))
return new Point((int) centerX, (int) centerY);

float dx = reference.x - centerX;
float dy = reference.y - centerY;

float scale = 0.5f / Math.max(Math.abs(dx) / r.width, Math.abs(dy) /
r.height);

dx *= scale;
dy *= scale;
centerX += dx;
centerY += dy;

Point linkPoint = new Point(Math.round(centerX), Math.round(centerY));

pointList.addPoint(linkPoint);

if (pointList.intersects(textRect))
{
// I am not doing anyhting here yet...
// I just want to check if intersects() returns true
return linkPoint; // Apply offset before return it..
}
return linkPoint;
}
Re: how to determine whether a line segment intersects [message #187613 is a reply to message #187604] Wed, 13 July 2005 22:58 Go to previous message
Eclipse UserFriend
Originally posted by: none.unknown.com

Did you try debugging at all to see what's happening? Your code is
needlessly complicated. You don't need to copy anything from the super
method, you can just call super when needed (which, by the way, you don't
need to do if you just want to see if the line segment is intersecting the
text).

As for the problem, I only see you adding one point to the PointList.

"Al Bencomo" <bencomo@us.ibm.com> wrote in message
news:cc6bb09211b2b8a1030041591c445c53$1@www.eclipse.org...
> Randy / Pratik / GEF Jedi Masters:
>
> In my subclass of ChopboxAnchor, I have overridden the getLocation method
> to check if the line segment intersects the TextFlow's bounds. However,
> PointList#intersects(Rectangle) is not returns false when the line segment
> intersects. Please let me know if you see what I am missing.
>
> Thank you in advance,
> Al.-
>
> public Point getLocation(Point reference)
> {
> Rectangle textRect = null;
> PointList pointList = new PointList();
>
> textRect = taskFigure.getLabel().getBounds().getCopy();
> taskFigure.getLabel().translateToAbsolute(textRect);
>
> Rectangle r = Rectangle.SINGLETON;
> r.setBounds(getBox());
> r.translate(-1, -1);
> r.resize(1, 1);
>
> getOwner().translateToAbsolute(r);
>
> float centerX = r.x + 0.5f * r.width;
> float centerY = r.y + 0.5f * r.height;
>
> if (r.isEmpty() || (reference.x == (int) centerX && reference.y ==
> (int) centerY))
> return new Point((int) centerX, (int) centerY);
>
> float dx = reference.x - centerX;
> float dy = reference.y - centerY;
>
> float scale = 0.5f / Math.max(Math.abs(dx) / r.width, Math.abs(dy) /
> r.height);
>
> dx *= scale;
> dy *= scale;
> centerX += dx;
> centerY += dy;
>
> Point linkPoint = new Point(Math.round(centerX), Math.round(centerY));
>
> pointList.addPoint(linkPoint);
>
> if (pointList.intersects(textRect))
> {
> // I am not doing anyhting here yet...
> // I just want to check if intersects() returns true
> return linkPoint; // Apply offset before return it..
> }
> return linkPoint;
> }
>
Previous Topic:DND within editor and natively
Next Topic:double click on java file opens resource set
Goto Forum:
  


Current Time: Wed Apr 24 14:39:56 GMT 2024

Powered by FUDForum. Page generated in 0.03050 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top