private static boolean computeIntersectionOfPolygonsIfOnePolygonHasExactlyOneVertex(ConvexPolygon2DReadOnly polygonWithExactlyOneVertex, ConvexPolygon2DReadOnly otherPolygon, ConvexPolygon2DBasics intersectingPolygon) { if (otherPolygon.pointIsOnPerimeter(polygonWithExactlyOneVertex.getVertex(0))) { intersectingPolygon.set(polygonWithExactlyOneVertex); return false; } else { intersectingPolygon.clearAndUpdate(); return false; } }
@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())); }
private boolean buildCommonPolygonFromBridges(TIntArrayList bridgeIndicesP, TIntArrayList bridgeIndicesQ, TIntArrayList bridgeWasOnLeft, ConvexPolygon2DReadOnly polygonP, ConvexPolygon2DReadOnly polygonQ, ConvexPolygon2DBasics intersectingPolygonToPack) { crossingIndices.clear(); for (int i = 0; i < bridgeIndicesP.size(); i++) { // find intersection for bridge int bridgeIndexForPolygonP = bridgeIndicesP.get(i); int bridgeIndexForPolygonQ = bridgeIndicesQ.get(i); // for each bridge, compute the intersection points TIntArrayList indices = crossingIndices.add(); boolean success = findCrossingIndices(bridgeWasOnLeft.get(i) == 1, bridgeIndexForPolygonP, bridgeIndexForPolygonQ, polygonP, polygonQ, indices); if (!success) { intersectingPolygonToPack.clearAndUpdate(); return false; // No intersection. } } PriorityQueue p; boolean success = constructPolygonForIntersection(crossingIndices, polygonP, polygonQ, intersectingPolygonToPack); return success; }
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; } }
polygon.clearAndUpdate();
if (!success) intersectingPolygonToPack.clearAndUpdate(); return false;