public static Point2D getCloser(final Point2D o, final Point2D... other) { double minDist = Double.MAX_VALUE; Point2D result = null; for (Point2D pt : other) { if (pt != null) { final double dist = pt.distanceSq(o); if (dist < minDist) { minDist = dist; result = pt; } } } return result; }
private static Point2D getFarest(Point2D p1, Point2D p2, Collection<Point2D> all) { Point2D result = null; double farest = 0; for (Point2D p : all) { if (result == null) { result = p; farest = p1.distanceSq(result) + p2.distanceSq(result); continue; } final double candidat = p1.distanceSq(p) + p2.distanceSq(p); if (candidat < farest) { result = p; farest = candidat; } } if (result == null) { throw new IllegalArgumentException(); } return result; }
private double getCost(Point2D pt) { final Point2D start = getStartPoint(); final Point2D end = getEndPoint(); return pt.distanceSq(start) + pt.distanceSq(end); }
@Override public void mouseDragged(MouseEvent e) { if (MatchesPanel.getInstance().isEmpty()) return; if (firstMouseEvent != null) { e.consume(); JTextField label = ((TreeFromFile) list.getSelectedValue()).getLabel(); if(dragNDrop) { if(label == null) return; if(Point2D.distanceSq(e.getX(), e.getY(), firstMouseEvent.getX(), firstMouseEvent.getY()) > 25) { //do DnD list.getTransferHandler().exportAsDrag((JComponent) e.getSource(), firstMouseEvent, TransferHandler.COPY); } } else { addHighlight(label, firstMouseEvent, e); } } }
@Override public void mouseDragged(MouseEvent e) { if (MatchesPanel.getInstance().isEmpty()) return; if (firstMouseEvent != null) { e.consume(); if(dragNDrop) { if(textField == null) return; if(Point2D.distanceSq(e.getX(), e.getY(), firstMouseEvent.getX(), firstMouseEvent.getY()) > 25) { //do DnD textField.getTransferHandler().exportAsDrag((JComponent) e.getSource(), firstMouseEvent, TransferHandler.COPY); } } else { addHighlight(textField, firstMouseEvent, e); } } } }
if (source.distanceSq(target) > 1.0) { final double y1 = toRadians(source.getY()); final double y2 = toRadians(target.getY());
public static Point2D getCloser(final Point2D o, final Point2D... other) { double minDist = Double.MAX_VALUE; Point2D result = null; for (Point2D pt : other) { if (pt != null) { final double dist = pt.distanceSq(o); if (dist < minDist) { minDist = dist; result = pt; } } } return result; }
private boolean close(Point2D a, Point2D b) { return a.distanceSq(b) < 0.0001; }
public static double lengthSq(Point2D p0) { return p0.distanceSq(point00); }
private boolean close(Point2D a, Point2D b) { return a.distanceSq(b) < 0.0001; }
assert transform(target, null).distanceSq(source) < 1E-3 : target; } else { if (x >= 0 && x < width && y >= 0 && y < height) { assert transform(target, null).distanceSq(source) < 1E-3 : target; } else {
private double getCost(Point2D pt) { final Point2D start = getStartPoint(); final Point2D end = getEndPoint(); return pt.distanceSq(start) + pt.distanceSq(end); }
/** * @return */ public static Point2D.Double getPerpendicularPointToLine(Point2D ptA, Point2D ptB, Point2D ptC) { if (ptA == null || ptB == null || ptA.equals(ptB) || ptC == null) { return null; } double ax = ptA.getX(), ay = ptA.getY(); double bx = ptB.getX(), by = ptB.getY(); double cx = ptC.getX(), cy = ptC.getY(); double r = ((ay - cy) * (ay - by) + (ax - cx) * (ax - bx)) / Point2D.distanceSq(ax, ay, bx, by); return new Point2D.Double(ax + r * (bx - ax), ay + r * (by - ay)); }
/** * Compares coodinates of Direct Positions * @param Direct Position to compare with * @return TRUE, if coordinates accord, FALSE if they dont. */ public static boolean equals(Point2D p0, Point2D p1, double tol) { return p0.equals(p1) || p0.distanceSq(p1) < (tol * tol); }
/** * Returns whether the local location hits the first control point (also meant to be the source anchor). * @param localLocation the local location * @return true if it hits the first control point */ public final boolean isFirstControlPointHitAt (Point localLocation) { int endRadius = endPointShape.getRadius (); endRadius *= endRadius; Point firstPoint = getFirstControlPoint (); if (firstPoint != null) if (Point2D.distanceSq (firstPoint.x, firstPoint.y, localLocation.x, localLocation.y) <= endRadius) return true; return false; }
/** * Returns whether the local location hits the last control point (also meant to be the target anchor). * @param localLocation the local location * @return true if it hits the last control point */ public final boolean isLastControlPointHitAt (Point localLocation) { int endRadius = endPointShape.getRadius (); endRadius *= endRadius; Point lastPoint = getLastControlPoint (); if (lastPoint != null) if (Point2D.distanceSq (lastPoint.x, lastPoint.y, localLocation.x, localLocation.y) <= endRadius) return true; return false; }
/** * Returns whether the local location hits the last control point (also meant to be the target anchor). * @param localLocation the local location * @return true if it hits the last control point */ public final boolean isLastControlPointHitAt (Point localLocation) { int endRadius = endPointShape.getRadius (); endRadius *= endRadius; Point lastPoint = getLastControlPoint (); if (lastPoint != null) if (Point2D.distanceSq (lastPoint.x, lastPoint.y, localLocation.x, localLocation.y) <= endRadius) return true; return false; }
/** * Returns whether the local location hits the first control point (also meant to be the source anchor). * @param localLocation the local location * @return true if it hits the first control point */ public final boolean isFirstControlPointHitAt (Point localLocation) { int endRadius = endPointShape.getRadius (); endRadius *= endRadius; Point firstPoint = getFirstControlPoint (); if (firstPoint != null) if (Point2D.distanceSq (firstPoint.x, firstPoint.y, localLocation.x, localLocation.y) <= endRadius) return true; return false; }
/** * Returns an index of a control point that is hit by the local location * @param localLocation the local location * @return the index; -1 if no control point was hit */ public final int getControlPointHitAt (Point localLocation) { int controlRadius = controlPointShape.getRadius (); controlRadius *= controlRadius; if (isFirstControlPointHitAt (localLocation)) return 0; if (isLastControlPointHitAt (localLocation)) return controlPoints.size () - 1; for (int i = 0; i < controlPoints.size (); i ++) { Point point = controlPoints.get (i); if (Point2D.distanceSq (point.x, point.y, localLocation.x, localLocation.y) <= controlRadius) return i; } return -1; }
@Override public void mouseDragged(MouseEvent e) { if (MatchesPanel.getInstance().isEmpty()) return; if (firstMouseEvent != null) { e.consume(); if(dragNDrop) { if(textField == null) return; if(Point2D.distanceSq(e.getX(), e.getY(), firstMouseEvent.getX(), firstMouseEvent.getY()) > 25) { //do DnD textField.getTransferHandler().exportAsDrag((JComponent) e.getSource(), firstMouseEvent, TransferHandler.COPY); } } else { addHighlight(textField, firstMouseEvent, e); } } } }