/** * Clears this polygon, adds a single vertex at ({@link Double#NaN}, {@link Double#NaN}), and * updates it. */ @Override default void setToNaN() { clear(); addVertex(Double.NaN, Double.NaN); update(); }
private boolean computeIntersectionOfPolygonsIfOnePolygonHasExactlyTwoVerticesAndTheOtherHasAtLeastTwoVertices(ConvexPolygon2DReadOnly polygonWithExactlyTwoVertices, ConvexPolygon2DReadOnly polygonWithAtLeastTwoVertices, ConvexPolygon2DBasics intersectingPolygon) { polygonWithTwoVerticesAsLineSegment.set(polygonWithExactlyTwoVertices.getVertex(0), polygonWithExactlyTwoVertices.getVertex(1)); int intersections = polygonWithAtLeastTwoVertices.intersectionWith(polygonWithTwoVerticesAsLineSegment, intersection1, intersection2); if (intersections == 0) { intersectingPolygon.clearAndUpdate(); return false; } else if (intersections == 1) { intersectingPolygon.clear(); intersectingPolygon.addVertex(intersection1); intersectingPolygon.update(); return true; } else { intersectingPolygon.clear(); intersectingPolygon.addVertex(intersection1); intersectingPolygon.addVertex(intersection2); intersectingPolygon.update(); return true; } }
/** * Clears this polygon, adds a single vertex at (0, 0), and updates it. */ @Override default void setToZero() { clear(); addVertex(0.0, 0.0); update(); }
@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())); }
/** * This method does: * <ol> * <li>{@link #clear()}. * <li>{@link #addVertices(Vertex2DSupplier)}. * <li>{@link #update()}. * </ol> * * @param vertex2DSupplier the supplier of vertices. * @see Vertex2DSupplier * @see #addVertices(Vertex2DSupplier) */ default void set(Vertex2DSupplier vertex2DSupplier) { clear(); addVertices(vertex2DSupplier); update(); }
EuclidCoreTestTools.assertTuple2DContainsOnlyNaN(maxPoint); EuclidCoreTestTools.assertTuple2DContainsOnlyNaN(minPoint); polygon.clear(); polygon.update(); EuclidCoreTestTools.assertTuple2DContainsOnlyNaN(maxPoint);
/** * This method does: * <ol> * <li>{@link #clear()}. * <li>{@link #addVertices(Vertex3DSupplier)}. * <li>{@link #update()}. * </ol> * * @param vertex3DSupplier the supplier of vertices. * @see Vertex3DSupplier * @see #addVertices(Vertex3DSupplier) */ default void set(Vertex3DSupplier vertex3DSupplier) { clear(); addVertices(vertex3DSupplier); update(); }
/** * Sets this polygon such that it represents the smallest convex hull that contains all the vertices * supplied by the two suppliers. * <p> * Note that the resulting polygon is ready to be used for any operations, no need to call * {@link #update()}. * </p> * * @param firstVertex2DSupplier the first supplier of vertices. * @param secondVertex2DSupplier the second supplier of vertices. */ default void set(Vertex2DSupplier firstVertex2DSupplier, Vertex2DSupplier secondVertex2DSupplier) { clear(); addVertices(firstVertex2DSupplier); addVertices(secondVertex2DSupplier); update(); }
/** * Efficiently combines two Disjoint Polygons. Returns false if not disjoint. * * @param polygon1 ConvexPolygon2d * @param polygon2 ConvexPolygon2d * @param combinedPolygonToPack ConvexPolygon2d polygon in which we put the convex hull * containing polygon1 and polygon2. * @param connectingEdge1ToPack LineSegment2d first connecting edge between polygon1 and * polygon2. * @param connectingEdge2Topack LineSegment2d second connecting edge between polygon1 and * polygon2. * @return true if succeeded, false if failed */ public boolean combineDisjointPolygons(ConvexPolygon2DReadOnly polygon1, ConvexPolygon2DReadOnly polygon2, ConvexPolygon2DBasics combinedPolygonToPack, LineSegment2DBasics connectingEdge1ToPack, LineSegment2DBasics connectingEdge2Topack) { boolean success = findConnectingEdgesVerticesIndexes(polygon1, polygon2, verticesIndices); if (!success) return false; combinedPolygonToPack.clear(); polygon1.getVerticesInClockwiseOrder(verticesIndices[0][1], verticesIndices[0][0], combinedPolygonToPack); polygon2.getVerticesInClockwiseOrder(verticesIndices[1][0], verticesIndices[1][1], combinedPolygonToPack); combinedPolygonToPack.update(); getConnectingEdges(polygon1, polygon2, connectingEdge1ToPack, connectingEdge2Topack, verticesIndices); return true; }
polygonToPack.clear(); for (int i = 0; i < intersectionArrayList.size(); i++) polygonToPack.addVertex(intersectionArrayList.get(i));
polygonToPack.clear(); polygonAsLineSegment.direction(true, normalizedVector); normalizedVector.scale(-distance); midPoint.scale(0.5); polygonToPack.clear(); polygonToPack.addVertex(midPoint); polygonToPack.update(); polygonAsLineSegment.pointBetweenEndpointsGivenPercentage(1 - percentageAlongSegment, newVertex1); polygonToPack.clear(); polygonToPack.addVertex(newVertex0); polygonToPack.addVertex(newVertex1); if (!foundSolution) polygonToPack.clear(); polygonToPack.addVertex(polygonQ.getCentroid()); polygonToPack.update();
polygon.clear(); polygon.update(); return;