double distSq = line.ptSegDistSq(point);
/** * Returns the square of the shortest distance from a point to this * line segment. * * @param pt the point whose distance is being measured * @return the square of the distance from the specified point to this segment. */ public double ptSegDistSq(mxPoint pt) { return new Line2D.Double(getX(), getY(), endPoint.getX(), endPoint .getY()).ptSegDistSq(pt.getX(), pt.getY()); }
/** * Returns the square of the shortest distance from a point to this * line segment. * * @param pt the point whose distance is being measured * @return the square of the distance from the specified point to this segment. */ public double ptSegDistSq(mxPoint pt) { return new Line2D.Double(getX(), getY(), endPoint.getX(), endPoint .getY()).ptSegDistSq(pt.getX(), pt.getY()); }
Point2D p = edge.getPoint(i); Point2D p1 = edge.getPoint(i + 1); dist = new Line2D.Double(p, p1).ptSegDistSq(point); if (dist < min) { min = dist;
/** * Finds the index of the nearest segment on the given cell state for the * specified coordinate pair. */ public static int findNearestSegment(mxCellState state, double x, double y) { int index = -1; if (state.getAbsolutePointCount() > 0) { mxPoint last = state.getAbsolutePoint(0); double min = Double.MAX_VALUE; for (int i = 1; i < state.getAbsolutePointCount(); i++) { mxPoint current = state.getAbsolutePoint(i); double dist = new Line2D.Double(last.x, last.y, current.x, current.y).ptSegDistSq(x, y); if (dist < min) { min = dist; index = i - 1; } last = current; } } return index; }
/** * Finds the index of the nearest segment on the given cell state for the * specified coordinate pair. */ public static int findNearestSegment(mxCellState state, double x, double y) { int index = -1; if (state.getAbsolutePointCount() > 0) { mxPoint last = state.getAbsolutePoint(0); double min = Double.MAX_VALUE; for (int i = 1; i < state.getAbsolutePointCount(); i++) { mxPoint current = state.getAbsolutePoint(i); double dist = new Line2D.Double(last.x, last.y, current.x, current.y).ptSegDistSq(x, y); if (dist < min) { min = dist; index = i - 1; } last = current; } } return index; }