/** * 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(); }
/** * 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 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(); }
/** * Invalidates this bounding box by setting all its coordinates to {@link Double#NaN}. */ @Override default void setToNaN() { getMinPoint().setToNaN(); getMaxPoint().setToNaN(); }
/** * Resets this bounding box by setting both its minimum and maximum coordinates to (0, 0). */ @Override default void setToZero() { getMinPoint().setToZero(); getMaxPoint().setToZero(); }
/** * 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); } } }
/** * 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(); }
/** * 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(); }
/** * 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(Point2DReadOnly min, Point2DReadOnly max) { getMinPoint().set(min); getMaxPoint().set(max); checkBounds(); }
/** * Redefines this bounding box with new minimum and maximum coordinates. * * @param minX the new minimum x-coordinate for this bounding box. * @param minY the new minimum y-coordinate for this bounding box. * @param maxX the new maximum x-coordinates for this bounding box. * @param maxY the new maximum y-coordinates 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 set(double minX, double minY, double maxX, double maxY) { getMinPoint().set(minX, minY); getMaxPoint().set(maxX, maxY); checkBounds(); }
/** * 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()); }
@Test public void testGetBoundingBox() { double[][] verticesArray = {{0.0, 0.0}, {0.0, 1.0}, {1.0, 0.0}, {1.0, 1.0}}; T doubles = createConvexPolygon2D(Vertex2DSupplier.asVertex2DSupplier(verticesArray)); BoundingBox2DBasics box = doubles.getBoundingBox(); assertEquals("Bounding boxes should be equal", box.getMinPoint().getX(), 0.0, EPSILON); assertEquals("Bounding boxes should be equal", box.getMinPoint().getX(), 0.0, EPSILON); assertEquals("Bounding boxes should be equal", box.getMaxPoint().getY(), 1.0, EPSILON); assertEquals("Bounding boxes should be equal", box.getMaxPoint().getY(), 1.0, EPSILON); }
@Test public void testClear() { ArrayList<Point2D> verticesList = new ArrayList<>(); verticesList.add(new Point2D(0.0, 0.0)); verticesList.add(new Point2D(0.0, 1.0)); verticesList.add(new Point2D(1.0, 0.0)); verticesList.add(new Point2D(1.0, 1.0)); T list = createConvexPolygon2D(Vertex2DSupplier.asVertex2DSupplier(verticesList)); assertEquals("Number of vertices should be 4", 4.0, list.getNumberOfVertices(), EPSILON); assertTrue(list.isUpToDate()); list.clearAndUpdate(); assertEquals("Number of vertices should be 0", 0.0, list.getNumberOfVertices(), EPSILON); assertTrue(list.isUpToDate()); list.clear(); assertFalse(list.isUpToDate()); list.clearAndUpdate(); assertTrue(list.isUpToDate()); EuclidCoreTestTools.assertTuple2DContainsOnlyNaN(list.getBoundingBox().getMinPoint()); EuclidCoreTestTools.assertTuple2DContainsOnlyNaN(list.getBoundingBox().getMaxPoint()); EuclidCoreTestTools.assertTuple2DContainsOnlyNaN(list.getCentroid()); assertTrue(Double.isNaN(list.getArea())); }
Point2DBasics maxPoint = polygon.getBoundingBox().getMaxPoint(); Point2DBasics minPoint = polygon.getBoundingBox().getMinPoint(); Point2DBasics maxPoint = polygon.getBoundingBox().getMaxPoint(); Point2DBasics minPoint = polygon.getBoundingBox().getMinPoint(); EuclidCoreTestTools.assertTuple2DContainsOnlyNaN(maxPoint);