/**
  * Get the closest anchor to point p.
  *
  * @param p the reference point
  * @return the closest anchor to point p
  */
 protected ConnectionAnchor getClosestAnchorAt(Point p) {
   if (anchorMap == null) fillAnchorMap();
   ConnectionAnchor closest = null;
   double min = Long.MAX_VALUE;
   for (ConnectionAnchor anchor : anchorMap.values()) {
     Point p2 = anchor.getLocation(null);
     double d = p.getDistance(p2);
     if (d < min) {
       min = d;
       closest = anchor;
     }
   }
   return closest;
 }
Beispiel #2
0
 public ConnectionAnchor getTargetConnectionAnchorAt(Point p) {
   ConnectionAnchor closest = null;
   long min = Long.MAX_VALUE;
   Enumeration e = getTargetConnectionAnchors().elements();
   while (e.hasMoreElements()) {
     ConnectionAnchor c = (ConnectionAnchor) e.nextElement();
     Point p2 = c.getLocation(null);
     long d = p.getDistance2(p2);
     if (d < min) {
       min = d;
       closest = c;
     }
   }
   return closest;
 }
 public ConnectionAnchor getOutgoingConnectionAnchorAt(Point p) {
   ConnectionAnchor closest = null;
   long min = Long.MAX_VALUE;
   for (ConnectionAnchor c : outgoingConnectionAnchors) {
     Point p2 = c.getLocation(null);
     long d = p.getDistance2(p2);
     if (d < min) {
       min = d;
       closest = c;
     }
   }
   if (min > 100) {
     return defaultConnectionAnchor;
   }
   return closest;
 }