/** * Translated this polygon. * * @param x the translation along the x-axis to apply to each of this polygon's vertices. * @param y the translation along the y-axis to apply to each of this polygon's vertices. * @throws OutdatedPolygonException if {@link #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 translate(double x, double y) { checkIfUpToDate(); for (int i = 0; i < getNumberOfVertices(); i++) { getVertexUnsafe(i).add(x, y); } updateBoundingBox(); updateCentroidAndArea(); }
/** * Transforms this convex polygon using the given homogeneous transformation matrix. * * @param transform the transform to apply on the vertices of this convex polygon. Not modified. * @param checkIfTransformInXYPlane whether this method should assert that the rotation part of the * given transform represents a transformation in the XY plane. * @throws OutdatedPolygonException if {@link #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. * @throws NotAMatrix2DException if {@code checkIfTransformInXYPlane == true} and the rotation part * of {@code transform} is not a transformation in the XY plane. */ default void applyTransform(Transform transform, boolean checkIfTransformInXYPlane) { checkIfUpToDate(); notifyVerticesChanged(); for (int i = 0; i < getNumberOfVertices(); i++) { getVertexUnsafe(i).applyTransform(transform, checkIfTransformInXYPlane); } update(); }
/** * Transforms this convex polygon using the inverse of the given homogeneous transformation matrix. * * @param transform the transform to apply on the vertices of this convex polygon. Not modified. * @param checkIfTransformInXYPlane whether this method should assert that the rotation part of the * given transform represents a transformation in the XY plane. * @throws OutdatedPolygonException if {@link #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. * @throws NotAMatrix2DException if {@code checkIfTransformInXYPlane == true} and the rotation part * of {@code transform} is not a transformation in the XY plane. */ default void applyInverseTransform(Transform transform, boolean checkIfTransformInXYPlane) { checkIfUpToDate(); notifyVerticesChanged(); for (int i = 0; i < getNumberOfVertices(); i++) { getVertexUnsafe(i).applyInverseTransform(transform, checkIfTransformInXYPlane); } update(); } }
checkIfUpToDate(); notifyVerticesChanged();