/** * Redefines this bounding box with new minimum and maximum coordinates. * * @param min the new minimum coordinates for this bounding box. Not modified. * @param max the new maximum coordinates for this bounding box. Not modified. * @throws RuntimeException if any of the minimum coordinates is strictly greater than the maximum * coordinate on the same axis. */ default void set(double[] min, double[] max) { getMinPoint().set(min); getMaxPoint().set(max); checkBounds(); }
/** * Combines this bounding box with {@code other} such that it becomes the smallest bounding box * containing this and {@code other}. * * @param other the other bounding box to combine with this. Not modified. */ default void combine(BoundingBox2DReadOnly other) { combine(this, other); }
/** * Tests on a per-component basis on the minimum and maximum coordinates if this bounding box is * equal to {@code other} with the tolerance {@code epsilon}. * * @param other the query. Not modified. * @param epsilon the tolerance to use. * @return {@code true} if the two bounding boxes are equal, {@code false} otherwise. */ @Override public boolean epsilonEquals(BoundingBox2D other, double epsilon) { return BoundingBox2DBasics.super.epsilonEquals(other, epsilon); }
/** * Sets the maximum coordinate of this bounding box. * * @param max the maximum coordinate for this bounding box. Not modified. * @throws RuntimeException if any of the minimum coordinates is strictly greater than the maximum * coordinate on the same axis. */ default void setMax(Point2DReadOnly max) { getMaxPoint().set(max); checkBounds(); }
/** * Updates the bounding box properties. */ default void updateBoundingBox() { BoundingBox2DBasics boundingBox = getBoundingBox(); boundingBox.setToNaN(); boundingBox.updateToIncludePoints(this); }
/** * Sets the minimum coordinate of this bounding box. * * @param min the minimum coordinates for this bounding box. Not modified. * @throws RuntimeException if any of the minimum coordinates is strictly greater than the maximum * coordinate on the same axis. */ default void setMin(double[] min) { getMinPoint().set(min); checkBounds(); }
/** * Resets this bounding box by setting both its minimum and maximum coordinates to (0, 0). */ @Override default void setToZero() { getMinPoint().setToZero(); getMaxPoint().setToZero(); }
Point2DBasics maxPoint = polygon.getBoundingBox().getMaxPoint(); Point2DBasics minPoint = polygon.getBoundingBox().getMinPoint(); for (Point2D point : points) assertTrue(polygon.getBoundingBox().isInsideInclusive(point)); assertFalse(polygon.getBoundingBox().isInsideInclusive(point)); Point2DBasics maxPoint = polygon.getBoundingBox().getMaxPoint(); Point2DBasics minPoint = polygon.getBoundingBox().getMinPoint(); EuclidCoreTestTools.assertTuple2DContainsOnlyNaN(maxPoint); EuclidCoreTestTools.assertTuple2DContainsOnlyNaN(minPoint);
/** * Redefines this bounding box to be the same as the given {@code other}. * * @param other the bounding box used to redefine this bounding box. Not modified. */ @Override public void set(BoundingBox2D other) { BoundingBox2DBasics.super.set(other); }
/** * Updates this bounding box to be the smallest bounding box that includes this and the supplied * points. * * @param vertex2DSupplier the supply of points. */ default void updateToIncludePoints(Vertex2DSupplier vertex2DSupplier) { for (int index = 0; index < vertex2DSupplier.getNumberOfVertices(); index++) updateToIncludePoint(vertex2DSupplier.getVertex(index)); }
/** * Compares {@code this} to {@code other} to determine if the two bounding boxes are geometrically * similar, i.e. the distance between their min and max points is less than or equal to * {@code epsilon}. * * @param other the bounding box to compare to. Not modified. * @param epsilon the tolerance of the comparison. * @return {@code true} if the two bounding boxes represent the same geometry, {@code false} * otherwise. */ @Override public boolean geometricallyEquals(BoundingBox2D other, double epsilon) { return BoundingBox2DBasics.super.geometricallyEquals(other, epsilon); } }
/** * Invalidates this bounding box by setting all its coordinates to {@link Double#NaN}. */ @Override default void setToNaN() { getMinPoint().setToNaN(); getMaxPoint().setToNaN(); }
/** * Sets the maximum coordinate of this bounding box. * * @param max the maximum coordinates for this bounding box. Not modified. * @throws RuntimeException if any of the minimum coordinates is strictly greater than the maximum * coordinate on the same axis. */ default void setMax(double[] max) { getMaxPoint().set(max); checkBounds(); }
/** * Sets the minimum coordinate of this bounding box. * * @param min the minimum coordinate for this bounding box. Not modified. * @throws RuntimeException if any of the minimum coordinates is strictly greater than the maximum * coordinate on the same axis. */ default void setMin(Point2DReadOnly min) { getMinPoint().set(min); checkBounds(); }
/** * Sets this bounding box to the union of {@code boundingBoxOne} and {@code boundingBoxTwo}. * <p> * This bounding box is set such that it is the smallest bounding box containing the two given * bounding boxes. * </p> * * @param boundingBoxOne the first bounding box. Can be the same instance as this. Not modified. * @param boundingBoxTwo the second bounding box. Can be the same instance as this. Not modified. */ default void combine(BoundingBox2DReadOnly boundingBoxOne, BoundingBox2DReadOnly boundingBoxTwo) { double minX = Math.min(boundingBoxOne.getMinX(), boundingBoxTwo.getMinX()); double minY = Math.min(boundingBoxOne.getMinY(), boundingBoxTwo.getMinY()); double maxX = Math.max(boundingBoxOne.getMaxX(), boundingBoxTwo.getMaxX()); double maxY = Math.max(boundingBoxOne.getMaxY(), boundingBoxTwo.getMaxY()); set(minX, minY, maxX, maxY); }
/** * Updates this bounding box to be the smallest bounding box that includes this and the given point. * * @param point the point to be included in this bounding box. Not modified. */ default void updateToIncludePoint(Point2DReadOnly point) { updateToIncludePoint(point.getX(), point.getY()); }
/** * Redefines this bounding box given its {@code center} location and half its size along each axis * {@code halfSize}. * * @param center the new center location of this bounding box. Not modified. * @param halfSize half the size of this bounding box. Not modified. */ default void set(Point2DReadOnly center, Vector2DReadOnly halfSize) { getMinPoint().sub(center, halfSize); getMaxPoint().add(center, halfSize); checkBounds(); }
/** * Updates this bounding box to be the smallest bounding box that includes this and the given point. * * @param x x-coordinate of the point to be included in this bounding box. Not modified. * @param y y-coordinate of the point to be included in this bounding box. Not modified. */ default void updateToIncludePoint(double x, double y) { if (Double.isNaN(getMinPoint().getX()) || x < getMinPoint().getX()) { getMinPoint().setX(x); } if (Double.isNaN(getMinPoint().getY()) || y < getMinPoint().getY()) { getMinPoint().setY(y); } if (Double.isNaN(getMaxPoint().getX()) || x > getMaxPoint().getX()) { getMaxPoint().setX(x); } if (Double.isNaN(getMaxPoint().getY()) || y > getMaxPoint().getY()) { getMaxPoint().setY(y); } } }
/** * Sets the maximum coordinate of this bounding box. * * @param maxX the new maximum x-coordinate for this bounding box. * @param maxY the new maximum y-coordinate for this bounding box. * @throws RuntimeException if any of the minimum coordinates is strictly greater than the maximum * coordinate on the same axis. */ default void setMax(double maxX, double maxY) { getMaxPoint().set(maxX, maxY); checkBounds(); }
/** * Sets the minimum coordinate of this bounding box. * * @param minX the new minimum x-coordinate for this bounding box. * @param minY the new minimum y-coordinate for this bounding box. * @throws RuntimeException if any of the minimum coordinates is strictly greater than the maximum * coordinate on the same axis. */ default void setMin(double minX, double minY) { getMinPoint().set(minX, minY); checkBounds(); }