/** * 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 minimum x-coordinate of this bounding box. * * @return the minimum x-coordinate. */ default double getMinX() { return getMinPoint().getX(); }
/** * 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()); }
/** * Gets the minimum y-coordinate of this bounding box. * * @return the minimum y-coordinate. */ default double getMinY() { return getMinPoint().getY(); }
/** * 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 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()); }
/** * 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. */ default boolean geometricallyEquals(BoundingBox2DReadOnly other, double epsilon) { return getMinPoint().geometricallyEquals(other.getMinPoint(), epsilon) && getMaxPoint().geometricallyEquals(other.getMaxPoint(), epsilon); } }
/** * Gets a representative {@code String} of {@code boundingBox2D} given a specific format to use. * <p> * Using the default format {@link #DEFAULT_FORMAT}, this provides a {@code String} as follows: * * <pre> * Bounding Box 2D: min = ( 0.174, 0.732 ), max = (-0.558, -0.380 ) * </pre> * </p> * * @param format the format to use for each number. * @param boundingBox2D the object to get the {@code String} of. Not modified. * @return the representative {@code String}. */ public static String getBoundingBox2DString(String format, BoundingBox2DReadOnly boundingBox2D) { if (boundingBox2D == null) return "null"; else return getBoundingBox2DString(format, boundingBox2D.getMinPoint(), boundingBox2D.getMaxPoint()); }
/** * 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()); }
/** * Tests if the min and max points defining this bounding box contain at least one * {@link Double#NaN}. * * @return {@code true} if this bounding box contains at least one {@link Double#NaN}, {@code fasle} * otherwise. */ default boolean containsNaN() { return getMinPoint().containsNaN() || getMaxPoint().containsNaN(); }
/** * 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 size along the y-axis of this polygon's bounding box. * * @return the range on the y-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 getBoundingBoxRangeY() { BoundingBox2DReadOnly boundingBox = getBoundingBox(); return boundingBox.getMaxPoint().getY() - boundingBox.getMinPoint().getY(); }
/** * 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); }
/** * 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. */ default void set(BoundingBox2DReadOnly other) { getMinPoint().set(other.getMinPoint()); getMaxPoint().set(other.getMaxPoint()); }
return intersectionBetweenRay2DAndBoundingBox2D(getMinPoint(), getMaxPoint(), rayOrigin, rayDirection, firstIntersectionToPack, secondIntersectionToPack);
return intersectionBetweenLineSegment2DAndBoundingBox2D(getMinPoint(), getMaxPoint(), lineSegmentStart, lineSegmentEnd, firstIntersectionToPack, secondIntersectionToPack);
public RotatableConvexPolygonTerrainObject(Vector3D normal, ConvexPolygon2D convexPolygon, double centroidHeight, AppearanceDefinition appearance) { if (normal.getZ() <= 0.0) throw new RuntimeException("Top surface normal must have a positive z-value. Normal.z = " + normal.getZ()); this.convexPolygon = new ConvexPolygon2D(convexPolygon); Point3D centroid = new Point3D(convexPolygon.getCentroid().getX(), convexPolygon.getCentroid().getY(), centroidHeight); this.topPlane = new Plane3D(centroid, normal); BoundingBox2DReadOnly polygonBoundingBox = convexPolygon.getBoundingBox(); double highest = Double.NEGATIVE_INFINITY; double lowest = 0.0; double height; for (int i = 0; i < convexPolygon.getNumberOfVertices(); i++) { Point2DReadOnly vertex = convexPolygon.getVertex(i); height = heightAt(vertex.getX(), vertex.getY(), 0.0); if (height < lowest) lowest = height; if (height > highest) highest = height; } Point2DReadOnly minPoint = polygonBoundingBox.getMinPoint(); Point2DReadOnly maxPoint = polygonBoundingBox.getMaxPoint(); double[] minPoint3d = {minPoint.getX(), minPoint.getY(), lowest}; double[] maxPoint3d = {maxPoint.getX(), maxPoint.getY(), highest}; this.boundingBox = new BoundingBox3D(minPoint3d, maxPoint3d); initSidePlanes(); this.linkGraphics = new Graphics3DObject(); this.appearance = appearance; addLinkGraphics(convexPolygon, boundingBox); }