private static boolean buildCommonPolygonFromBridges(ArrayList<Integer> bridgeIndicesP, ArrayList<Integer> bridgeIndicesQ, ArrayList<Boolean> bridgeWasOnLeft, ConvexPolygon2d polygonP, ConvexPolygon2d polygonQ, ConvexPolygon2d intersectingPolygonToPack) { int[][][] crossingIndices = new int[bridgeIndicesP.size()][][]; for (int i = 0; i < crossingIndices.length; i++) { // find intersection for bridge int bridgeIndexForPolygonP = bridgeIndicesP.get(i); int bridgeIndexForPolygonQ = bridgeIndicesQ.get(i); // for each bridge, compute the intersection points crossingIndices[i] = findCrossingIndices(bridgeWasOnLeft.get(i), bridgeIndexForPolygonP, bridgeIndexForPolygonQ, polygonP, polygonQ); if (crossingIndices[i] == null) { intersectingPolygonToPack.clearAndUpdate(); return false; // No intersection. } } boolean success = constructPolygonForIntersection(bridgeWasOnLeft, crossingIndices, polygonP, polygonQ, intersectingPolygonToPack); return success; }
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; }