/** * Scale this convex polygon about its centroid. * <p> * The polygon centroid remains unchanged. * </p> * * @param scaleFactor the scale factor to apply to this polygon. A value of {@code 1.0} does * nothing. * @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 scale(double scaleFactor) { scale(getCentroid(), scaleFactor); }
@Test public void testGetCentroid() { double[][] verticesArray = {{0.0, 0.0}, {0.0, 1.0}, {1.0, 0.0}, {1.0, 1.0}}; T doubles = createConvexPolygon2D(Vertex2DSupplier.asVertex2DSupplier(verticesArray)); Point2D centroid = new Point2D(); centroid.set(doubles.getCentroid()); assertEquals("Centroids should be equal", centroid, doubles.getCentroid()); }
@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())); }