/** * 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); } }
/** * Gets the read-only reference to 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 in the clockwise ordered list. * @return the read-only reference to the vertex. * @throws OutdatedPolygonException if {@link ConvexPolygon2DBasics#update()} has not been called * since last time this polygon's vertices were edited. */ @Override default Point2DReadOnly getVertex(int index) { checkIfUpToDate(); checkNonEmpty(); checkIndexInBoundaries(index); return getVertexBufferView().get(index); }
/** * 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); } }
/** * Gets the index of the vertex located before the vertex at the index {@code currentVertexIndex} * in the list of vertices. * <p> * Note that this polygon's vertices are clockwise ordered and that the first vertex has the * lowest x-coordinate. * </p> * * @param currentVertexIndex the current vertex index. * @return the before vertex index. * @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 int getPreviousVertexIndex(int currentVertexIndex) { checkIfUpToDate(); checkIndexInBoundaries(currentVertexIndex); checkNonEmpty(); if (currentVertexIndex < 1) return getNumberOfVertices() - 1; else return currentVertexIndex - 1; }
/** * Gets the index of the vertex located after the vertex at the index {@code currentVertexIndex} * in the list of vertices. * <p> * Note that this polygon's vertices are clockwise ordered and that the first vertex has the * lowest x-coordinate. * </p> * * @param currentVertexIndex the current vertex index. * @return the next vertex index. * @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 int getNextVertexIndex(int currentVertexIndex) { checkIfUpToDate(); checkIndexInBoundaries(currentVertexIndex); checkNonEmpty(); if (currentVertexIndex < getNumberOfVertices() - 1) return currentVertexIndex + 1; else return 0; }