/** * Finds the index of the closest vertex to the query. * * @param point the coordinates of the query. Not modified. * @return the index of the closest vertex to the query. * @throws ReferenceFrameMismatchException if {@code point} and {@code this} are not expressed in * the same reference frame. * @see #getClosestVertexIndex(Point2DReadOnly) */ default int getClosestVertexIndex(FramePoint2DReadOnly point) { checkReferenceFrameMatch(point); return ConvexPolygon2DReadOnly.super.getClosestVertexIndex(point); }
/** * Finds the index of the closest vertex to the given line. * * @param line the query. Not modified. * @return the index of the closest vertex to the query. * @throws ReferenceFrameMismatchException if {@code line} and {@code this} are not expressed in * the same reference frame. * @see #getClosestVertexIndex(Line2DReadOnly) */ default int getClosestVertexIndex(FrameLine2DReadOnly line) { checkReferenceFrameMatch(line); return ConvexPolygon2DReadOnly.super.getClosestVertexIndex(line); }
/** * Finds the index of the closest vertex to the given line. * <p> * Edge cases: * <ul> * <li>If the polygon has no vertices, this method fails and returns {@code false}. * </ul> * </p> * * @param line the query. Not modified. * @param vertexToPack point used to store the result. Modified. * @return whether this method succeeded or not. * @throws OutdatedPolygonException if {@link ConvexPolygon2DBasics#update()} has not been called * since last time this polygon's vertices were edited. */ default boolean getClosestVertex(Line2DReadOnly line, Point2DBasics vertexToPack) { int vertexIndex = getClosestVertexIndex(line); if (vertexIndex == -1) return false; vertexToPack.set(getVertex(vertexIndex)); return true; }
/** * Finds the index of the closest vertex to the query. * <p> * Edge cases: * <ul> * <li>If the polygon has no vertices, this method fails and returns {@code false}. * </ul> * </p> * * @param point the coordinates of the query. Not modified. * @param vertexToPack point used to store the result. Modified. * @return whether this method succeeded or not. * @throws OutdatedPolygonException if {@link ConvexPolygon2DBasics#update()} has not been called * since last time this polygon's vertices were edited. */ default boolean getClosestVertex(Point2DReadOnly point, Point2DBasics vertexToPack) { int vertexIndex = getClosestVertexIndex(point); if (vertexIndex == -1) return false; vertexToPack.set(getVertex(vertexIndex)); return true; }
/** * Finds the index of the closest vertex to the given line. * <p> * WARNING: This method generates garbage. * </p> * <p> * Edge cases: * <ul> * <li>If the polygon has no vertices, this method fails and returns {@code false}. * </ul> * </p> * * @param line the query. Not modified. * @return the coordinates of the closest vertex or {@code null} if this method failed. * @throws OutdatedPolygonException if {@link ConvexPolygon2DBasics#update()} has not been called * since last time this polygon's vertices were edited. */ default Point2DBasics getClosestVertexCopy(Line2DReadOnly line) { int vertexIndex = getClosestVertexIndex(line); if (vertexIndex == -1) return null; return new Point2D(getVertex(vertexIndex)); }
/** * Finds the index of the closest vertex to the query. * <p> * WARNING: This method generates garbage. * </p> * <p> * Edge cases: * <ul> * <li>If the polygon has no vertices, this method fails and returns {@code null}. * </ul> * </p> * * @param point the coordinates of the query. Not modified. * @return the coordinates of the closest vertex, or {@code null} if this method failed. * @throws OutdatedPolygonException if {@link ConvexPolygon2DBasics#update()} has not been called * since last time this polygon's vertices were edited. */ default Point2DBasics getClosestVertexCopy(Point2DReadOnly point) { int vertexIndex = getClosestVertexIndex(point); if (vertexIndex == -1) return null; return new Point2D(getVertex(vertexIndex)); }
int indexOfClosestOtherPoint = other.getClosestVertexIndex(getVertex(0));