/** * Gets the read-only reference to the vertex located after the {@code index}<sup>th</sup> vertex * of this polygon. * <p> * Note that the first vertex has the lowest x-coordinate. * </p> * * @param index the index of the vertex. * @return the read-only reference to the next vertex. * @throws OutdatedPolygonException if {@link ConvexPolygon2DBasics#update()} has not been called * since last time this polygon's vertices were edited. * @throws IndexOutOfBoundsException if the given {@code index} is negative or greater or equal * than this polygon's number of vertices. * @throws EmptyPolygonException if this polygon is empty when calling this method. */ default Point2DReadOnly getNextVertex(int index) { return getVertex(getNextVertexIndex(index)); }
/** * Gets the read-only reference to the vertex located after the {@code index}<sup>th</sup> vertex * of this polygon. * <p> * This method calculates a new index to emulate a counter-clockwise ordering of this polygon's * vertices. The first vertex has the lowest x-coordinate. * </p> * * @param index the index of the vertex in the counter-clockwise ordered list. * @return the read-only reference to the next vertex. * @throws OutdatedPolygonException if {@link ConvexPolygon2DBasics#update()} has not been called * since last time this polygon's vertices were edited. * @throws IndexOutOfBoundsException if the given {@code index} is negative or greater or equal * than this polygon's number of vertices. * @throws EmptyPolygonException if this polygon is empty when calling this method. */ default Point2DReadOnly getNextVertexCCW(int index) { return getVertexCCW(getNextVertexIndex(index)); }
/** * Adds a subset of this polygon's vertices into the given list. * <p> * The subset consists of the vertices from the vertex at {@code startIndexInclusive} to the * vertex {@code endIndexInclusive} while going from start to end in a clockwise order. * </p> * * @param startIndexInclusive the index of the first vertex to add. * @param endIndexInclusive the index of the last vertex to add. * @param pointListToPack the list into which the vertices are to be added. * @throws OutdatedPolygonException if {@link ConvexPolygon2DBasics#update()} has not been called * since last time this polygon's vertices were edited. * @throws EmptyPolygonException if this polygon is empty when calling this method. */ default void getPointsInClockwiseOrder(int startIndexInclusive, int endIndexInclusive, List<Point2DReadOnly> pointListToPack) { checkIfUpToDate(); checkIndexInBoundaries(startIndexInclusive); checkIndexInBoundaries(endIndexInclusive); int index = startIndexInclusive; while (true) { pointListToPack.add(getVertex(index)); if (index == endIndexInclusive) break; index = getNextVertexIndex(index); } }
indexP = polygonP.getNextVertexIndex(indexP); indexQ = polygonQ.getNextVertexIndex(indexQ);
/** * Adds a subset of this polygon's vertices into the given polygon. * <p> * The subset consists of the vertices from the vertex at {@code startIndexInclusive} to the * vertex {@code endIndexInclusive} while going from start to end in a clockwise order. * </p> * * @param startIndexInclusive the index of the first vertex to add. * @param endIndexInclusive the index of the last vertex to add. * @param polygonToPack the polygon into which the vertices are to be added. * @throws OutdatedPolygonException if {@link ConvexPolygon2DBasics#update()} has not been called * since last time this polygon's vertices were edited. * @throws EmptyPolygonException if this polygon is empty when calling this method. */ default void getVerticesInClockwiseOrder(int startIndexInclusive, int endIndexInclusive, ConvexPolygon2DBasics polygonToPack) { checkIfUpToDate(); checkIndexInBoundaries(startIndexInclusive); checkIndexInBoundaries(endIndexInclusive); int index = startIndexInclusive; while (true) { polygonToPack.addVertex(getVertex(index)); if (index == endIndexInclusive) break; index = getNextVertexIndex(index); } }
int nextVertexQIndex = polygonQ.getNextVertexIndex(leftMostIndexOnPolygonQ); Point2DReadOnly nextVertexQ = polygonQ.getVertex(nextVertexQIndex); int nextVertexPIndex = polygonP.getNextVertexIndex(leftMostIndexOnPolygonP); Point2DReadOnly nextVertexP = polygonP.getVertex(nextVertexPIndex); nextVertexQIndex = polygonQ.getNextVertexIndex(nextVertexQIndex); nextVertexQ = polygonQ.getVertex(nextVertexQIndex); nextVertexPIndex = polygonP.getNextVertexIndex(nextVertexPIndex); nextVertexP = polygonP.getVertex(nextVertexPIndex);
edgeToPack2.set(endVertex, polygon.getNextVertex(polygon.getNextVertexIndex(i))); return 2;
int nextVertexQIndex = polygonQ.getNextVertexIndex(leftMostIndexOnPolygonQ); Point2DReadOnly nextVertexQ = polygonQ.getVertex(nextVertexQIndex); nextVertexQIndex = polygonQ.getNextVertexIndex(nextVertexQIndex); nextVertexQ = polygonQ.getVertex(nextVertexQIndex);
currentPPolygonPointIndex = polygonP.getNextVertexIndex(currentPPolygonPointIndex); currentPolygonPPoint = polygonP.getVertex(currentPPolygonPointIndex); currentQPolygonPointIndex = polygonQ.getNextVertexIndex(currentQPolygonPointIndex); currentPolygonQPoint = polygonQ.getVertex(currentQPolygonPointIndex);