@Test public void testConstructorWithRepeatedPoints() { ArrayList<Point2D> listOfPoints = new ArrayList<>(); listOfPoints.add(new Point2D(0.0, 0.0)); listOfPoints.add(new Point2D(1.0, 1.0)); listOfPoints.add(new Point2D(1.0, 1.0)); listOfPoints.add(new Point2D(1.0, 1.0)); listOfPoints.add(new Point2D(1.0, 0.0)); listOfPoints.add(new Point2D(0.0, 0.0)); T convexPolygon2d = createConvexPolygon2D(Vertex2DSupplier.asVertex2DSupplier(listOfPoints)); // Above point list contains 3 unique points assertEquals(3, convexPolygon2d.getNumberOfVertices()); }
/** * Translated this polygon. * * @param x the translation along the x-axis to apply to each of this polygon's vertices. * @param y the translation along the y-axis to apply to each of this polygon's vertices. * @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 translate(double x, double y) { checkIfUpToDate(); for (int i = 0; i < getNumberOfVertices(); i++) { getVertexUnsafe(i).add(x, y); } updateBoundingBox(); updateCentroidAndArea(); }
/** * Transforms this convex polygon using the given homogeneous transformation matrix. * * @param transform the transform to apply on the vertices of this convex polygon. Not modified. * @param checkIfTransformInXYPlane whether this method should assert that the rotation part of the * given transform represents a transformation in the XY plane. * @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. * @throws NotAMatrix2DException if {@code checkIfTransformInXYPlane == true} and the rotation part * of {@code transform} is not a transformation in the XY plane. */ default void applyTransform(Transform transform, boolean checkIfTransformInXYPlane) { checkIfUpToDate(); notifyVerticesChanged(); for (int i = 0; i < getNumberOfVertices(); i++) { getVertexUnsafe(i).applyTransform(transform, checkIfTransformInXYPlane); } update(); }
/** * Transforms this convex polygon using the inverse of the given homogeneous transformation matrix. * * @param transform the transform to apply on the vertices of this convex polygon. Not modified. * @param checkIfTransformInXYPlane whether this method should assert that the rotation part of the * given transform represents a transformation in the XY plane. * @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. * @throws NotAMatrix2DException if {@code checkIfTransformInXYPlane == true} and the rotation part * of {@code transform} is not a transformation in the XY plane. */ default void applyInverseTransform(Transform transform, boolean checkIfTransformInXYPlane) { checkIfUpToDate(); notifyVerticesChanged(); for (int i = 0; i < getNumberOfVertices(); i++) { getVertexUnsafe(i).applyInverseTransform(transform, checkIfTransformInXYPlane); } update(); } }
@Test public void testSetAndUpdates() { T doubleInt = createEmptyConvexPolygon2D(); int numberOfVertices = 4; double[][] verticesArray = {{0.0, 0.0}, {0.0, 1.0}, {1.0, 0.0}, {1.0, 1.0}}; doubleInt.set(Vertex2DSupplier.asVertex2DSupplier(verticesArray, numberOfVertices)); assertEquals("Number of vertices should be 4", 4.0, doubleInt.getNumberOfVertices(), EPSILON); assertTrue(doubleInt.isUpToDate()); }
@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())); }
notifyVerticesChanged(); for (int i = 0; i < getNumberOfVertices(); i++)
while (index < polygonToCut.getNumberOfVertices())
for (int i = 0; i < polygon.getNumberOfVertices(); i++) assertFalse(polygon.canObserverSeeEdge(i, observer1)); for (int i = 0; i < polygon.getNumberOfVertices(); i++) for (int i = 0; i < polygon.getNumberOfVertices(); i++)
int vertices = polygon.getNumberOfVertices(); while (vertices > desiredVertices) polygon.update(); vertices = polygon.getNumberOfVertices();
assertEquals(1, polygonTranslation.getNumberOfVertices()); Point2D pointTranslation = new Point2D(pointThatDefinesThePolygon); pointTranslation.add(arbitraryPoint0);
assertEquals(2, polygonTranslation.getNumberOfVertices()); Point2D pointTranslation0 = new Point2D(pointThatDefinesThePolygon0); Point2D pointTranslation1 = new Point2D(pointThatDefinesThePolygon1);
int numberOfVertices = polygon.getNumberOfVertices(); int prevIndex = numberOfVertices - 1; int nextIndex = 0;