/** * 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. */ default boolean epsilonEquals(BoundingBox2DReadOnly other, double epsilon) { return getMinPoint().epsilonEquals(other.getMinPoint(), epsilon) && getMaxPoint().epsilonEquals(other.getMaxPoint(), epsilon); }
/** * Tests if this bounding box and {@code other} intersects. * <p> * The two bounding boxes are considered to not be intersecting if they share a corner or an edge. * </p> * * @param other the other bounding box to test if it is intersecting with this bounding box. Not * Modified. * @return {@code true} if the two bounding boxes intersect, {@code false} otherwise. */ default boolean intersectsExclusive(BoundingBox2DReadOnly other) { checkBounds(); if (other.getMinX() >= getMaxX() || other.getMaxX() <= getMinX()) return false; if (other.getMinY() >= getMaxY() || other.getMaxY() <= getMinY()) return false; return true; }
/** {@inheritDoc} */ @Override default boolean containsNaN() { return BoundingBox2DReadOnly.super.containsNaN(); }
/** * Calculates the squared value of the distance between the minimum and maximum coordinates of this * bounding box. * * @return the squared value of this bounding box diagonal. * @throws RuntimeException if this bounding box is improper according to {@link #checkBounds()}. */ default double getDiagonalLengthSquared() { checkBounds(); return getMinPoint().distanceSquared(getMaxPoint()); }
/** * Gets the size along the x-axis of this polygon's bounding box. * * @return the range on the x-axis of the bounding box. * @throws OutdatedPolygonException if {@link ConvexPolygon2DBasics#update()} has not been called * since last time this polygon's vertices were edited. */ default double getBoundingBoxRangeX() { BoundingBox2DReadOnly boundingBox = getBoundingBox(); return boundingBox.getMaxX() - boundingBox.getMinX(); }
/** * Gets the minimum coordinate of this bounding box and stores it in the given array * {@code maxToPack}. * * @param minToPack array in which the minimum coordinate of this bounding box is stored. Modified. */ default void getMinPoint(double[] minToPack) { getMinPoint().get(minToPack); }
/** * Gets the maximum coordinate of this bounding box and stores it in the given {@code maxToPack}. * * @param maxToPack point 2D in which the maximum coordinate of this bounding box is stored. * Modified. */ default void getMaxPoint(Point2DBasics maxToPack) { maxToPack.set(getMaxPoint()); }
/** * Gets the lowest y-coordinate value of the vertices composing this polygon. * * @return the minimum y-coordinate. * @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 double getMinY() { return getBoundingBox().getMinY(); }
/** * Gets the lowest x-coordinate value of the vertices composing this polygon. * * @return the minimum x-coordinate. * @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 double getMinX() { return getBoundingBox().getMinX(); }
/** * Gets the highest y-coordinate value of the vertices composing this polygon. * * @return the maximum y-coordinate. * @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 double getMaxY() { return getBoundingBox().getMaxY(); }
/** * Gets the highest x-coordinate value of the vertices composing this polygon. * * @return the maximum x-coordinate. * @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 double getMaxX() { return getBoundingBox().getMaxX(); }
/** * Asserts on a per component basis that the two bounding box 2Ds are equal to an * {@code epsilon}. * <p> * Note: the two arguments are considered to be equal if they are both equal to {@code null}. * </p> * * @param messagePrefix prefix to add to the error message. * @param expected the expected bounding box 2D. Not modified. * @param actual the actual bounding box 2D. Not modified. * @param epsilon the tolerance to use. * @param format the format to use for printing each component when an {@code AssertionError} is * thrown. * @throws AssertionError if the two bounding box 2Ds are not equal. If only one of the arguments * is equal to {@code null}. */ public static void assertBoundingBox2DEquals(String messagePrefix, BoundingBox2DReadOnly expected, BoundingBox2DReadOnly actual, double epsilon, String format) { if (expected == null && actual == null) return; if (!(expected != null && actual != null)) throwNotEqualAssertionError(messagePrefix, expected, actual, format); if (!expected.epsilonEquals(actual, epsilon)) { throwNotEqualAssertionError(messagePrefix, expected, actual, format); } }
/** * Asserts on a per component basis that the two bounding box 2Ds represent the same geometry to * an {@code epsilon}. * <p> * Note: the two arguments are considered to be equal if they are both equal to {@code null}. * </p> * * @param messagePrefix prefix to add to the error message. * @param expected the expected bounding box 2D. Not modified. * @param actual the actual bounding box 2D. Not modified. * @param epsilon the tolerance to use. * @param format the format to use for printing each component when an {@code AssertionError} is * thrown. * @throws AssertionError if the two bounding box 2Ds do not represent the same geometry. If only * one of the arguments is equal to {@code null}. */ public static void assertBoundingBox2DGeometricallyEquals(String messagePrefix, BoundingBox2DReadOnly expected, BoundingBox2DReadOnly actual, double epsilon, String format) { if (expected == null && actual == null) return; if (!(expected != null && actual != null)) throwNotEqualAssertionError(messagePrefix, expected, actual, format); if (!expected.geometricallyEquals(actual, epsilon)) { throwNotEqualAssertionError(messagePrefix, expected, actual, format); } }
/** * Calculates the coordinate of the center of this bounding box and stores it in the given * {@code centerToPack}. * * @param centerToPack point 2D in which the center of this bounding box is stored. Modified. * @throws RuntimeException if this bounding box is improper according to {@link #checkBounds()}. */ default void getCenterPoint(Point2DBasics centerToPack) { checkBounds(); centerToPack.interpolate(getMinPoint(), getMaxPoint(), 0.5); }
/** * Gets the minimum x-coordinate of this bounding box. * * @return the minimum x-coordinate. */ default double getMinX() { return getMinPoint().getX(); }
/** * Gets the maximum y-coordinate of this bounding box. * * @return the maximum y-coordinate. */ default double getMaxY() { return getMaxPoint().getY(); }
/** * Tests if this bounding box and {@code other} intersects. * <p> * The two bounding boxes are considered to be intersecting if they share a corner or an edge. * </p> * * @param other the other bounding box to test if it is intersecting with this bounding box. Not * Modified. * @return {@code true} if the two bounding boxes intersect, {@code false} otherwise. * @throws RuntimeException if this bounding box is improper according to {@link #checkBounds()}. */ default boolean intersectsInclusive(BoundingBox2DReadOnly other) { checkBounds(); if (other.getMinX() > getMaxX() || other.getMaxX() < getMinX()) return false; if (other.getMinY() > getMaxY() || other.getMaxY() < getMinY()) return false; return true; }
/** * Tests on a per component basis, if this bounding box 2D is exactly equal to {@code other}. * * @param other the other bounding box 2D to compare against this. Not modified. * @return {@code true} if the two bounding boxes are exactly equal component-wise, {@code false} * otherwise. */ default boolean equals(BoundingBox2DReadOnly other) { if (other == null) return false; else return getMinPoint().equals(other.getMinPoint()) && getMaxPoint().equals(other.getMaxPoint()); }
/** * Computes the coordinates of the two intersections between a line and this bounding box. * <p> * In the case the line and the bounding box do not intersect, this method returns {@code 0} and * {@code firstIntersectionToPack} and {@code secondIntersectionToPack} are set to * {@link Double#NaN}. * </p> * * @param pointOnLine a point located on the infinitely long line. Not modified. * @param lineDirection the line direction. Not modified. * @param firstIntersectionToPack the coordinate of the first intersection. Can be {@code null}. * Modified. * @param secondIntersectionToPack the coordinate of the second intersection. Can be {@code null}. * Modified. * @return the number of intersections between the line and this bounding box. It is either equal to * 0 or 2. * @throws RuntimeException if this bounding box is improper according to {@link #checkBounds()}. */ default int intersectionWithLine2D(Point2DReadOnly pointOnLine, Vector2DReadOnly lineDirection, Point2DBasics firstIntersectionToPack, Point2DBasics secondIntersectionToPack) { checkBounds(); return intersectionBetweenLine2DAndBoundingBox2D(getMinPoint(), getMaxPoint(), pointOnLine, lineDirection, firstIntersectionToPack, secondIntersectionToPack); }
/** * Gets the minimum coordinate of this bounding box and stores it in the given {@code minToPack}. * * @param minToPack point 2D in which the minimum coordinate of this bounding box is stored. * Modified. */ default void getMinPoint(Point2DBasics minToPack) { minToPack.set(getMinPoint()); }