Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Gef Connections getting the center of the of the rectangle edge
Gef Connections getting the center of the of the rectangle edge [message #755635] Wed, 09 November 2011 07:47 Go to next message
karthick9686@gmail.com Missing nameFriend
Messages: 41
Registered: July 2011
Member
the getLocation method the chopbox anchor is given below . it Gets a Rectangle from getbox and returns the Point where a line from the center of the Rectangle to the Point intersects the Rectangle.


/**
* Gets a Rectangle from {@link #getBox()} and returns the Point where a
* line from the center of the Rectangle to the Point <i>reference</i>
* intersects the Rectangle.
*
* @param reference
* The reference point
* @return The anchor location
*/
public Point getLocation(Point reference) {
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); // This avoids
// divide-by-zero

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

// r.width, r.height, dx, and dy are guaranteed to be non-zero.
float scale = 0.5f / Math.max(Math.abs(dx) / r.width, Math.abs(dy)
/ r.height);

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

return new Point(Math.round(centerX), Math.round(centerY));
}

How to modify the getLocation method so that i get only the center of the edge where the line intersects the rectangle?
Re: Gef Connections getting the center of the of the rectangle edge [message #755637 is a reply to message #755635] Wed, 09 November 2011 07:51 Go to previous messageGo to next message
Alexander Nyssen is currently offline Alexander NyssenFriend
Messages: 243
Registered: July 2009
Location: L√ľnen
Senior Member
Well, I suppose by checking, which of the getBounds().getTop(), getRight(), getBottom() and getLeft() has the lowest distance to the intersection point...
Re: Gef Connections getting the center of the of the rectangle edge [message #755674 is a reply to message #755637] Wed, 09 November 2011 09:29 Go to previous message
karthick9686@gmail.com Missing nameFriend
Messages: 41
Registered: July 2011
Member
Thanks for you advice i am now able to put the connections to the four centers of the rectangle . if any need code please mail at karthick9686@gmail.com
Previous Topic:Gef Connection source and endpoint location update
Next Topic:ScrollableThumbnail Nullpointer
Goto Forum:
  


Current Time: Mon Nov 29 00:53:19 GMT 2021

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

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

Back to the top