/**
  * Computes the {@link Polygon} formed by this ring and any contained holes.
  *
  * @return the {@link Polygon} formed by this ring and its holes.
  */
 public Polygon getPolygon() {
   LinearRing[] holeLR = null;
   if (holes != null) {
     holeLR = new LinearRing[holes.size()];
     for (int i = 0; i < holes.size(); i++) {
       holeLR[i] = (LinearRing) holes.get(i);
     }
   }
   Polygon poly = factory.createPolygon(ring, holeLR);
   return poly;
 }
  /**
   * Find the innermost enclosing shell EdgeRing containing the argument EdgeRing, if any. The
   * innermost enclosing ring is the <i>smallest</i> enclosing ring. The algorithm used depends on
   * the fact that: <br>
   * ring A contains ring B iff envelope(ring A) contains envelope(ring B) <br>
   * This routine is only safe to use if the chosen point of the hole is known to be properly
   * contained in a shell (which is guaranteed to be the case if the hole does not touch its shell)
   *
   * @return containing EdgeRing, if there is one or null if no containing EdgeRing is found
   */
  public static EdgeRing findEdgeRingContaining(EdgeRing testEr, List shellList) {
    LinearRing testRing = testEr.getRing();
    Envelope testEnv = testRing.getEnvelopeInternal();
    Coordinate testPt = testRing.getCoordinateN(0);

    EdgeRing minShell = null;
    Envelope minShellEnv = null;
    for (Iterator it = shellList.iterator(); it.hasNext(); ) {
      EdgeRing tryShell = (EdgeRing) it.next();
      LinearRing tryShellRing = tryShell.getRing();
      Envelope tryShellEnv = tryShellRing.getEnvelopeInternal();
      // the hole envelope cannot equal the shell envelope
      // (also guards against testing rings against themselves)
      if (tryShellEnv.equals(testEnv)) continue;
      // hole must be contained in shell
      if (!tryShellEnv.contains(testEnv)) continue;

      testPt =
          CoordinateArrays.ptNotInList(testRing.getCoordinates(), tryShellRing.getCoordinates());
      boolean isContained = false;
      if (CGAlgorithms.isPointInRing(testPt, tryShellRing.getCoordinates())) isContained = true;

      // check if this new containing ring is smaller than the current minimum ring
      if (isContained) {
        if (minShell == null || minShellEnv.contains(tryShellEnv)) {
          minShell = tryShell;
          minShellEnv = minShell.getRing().getEnvelopeInternal();
        }
      }
    }
    return minShell;
  }
 /**
  * Computes the list of coordinates which are contained in this ring. The coordinatea are computed
  * once only and cached.
  *
  * @return an array of the {@link Coordinate}s in this ring
  */
 private Coordinate[] getCoordinates() {
   if (ringPts == null) {
     CoordinateList coordList = new CoordinateList();
     for (Iterator i = deList.iterator(); i.hasNext(); ) {
       DirectedEdge de = (DirectedEdge) i.next();
       PolygonizeEdge edge = (PolygonizeEdge) de.getEdge();
       addEdge(edge.getLine().getCoordinates(), de.getEdgeDirection(), coordList);
     }
     ringPts = coordList.toCoordinateArray();
   }
   return ringPts;
 }
 /**
  * Adds a hole to the polygon formed by this ring.
  *
  * @param hole the {@link LinearRing} forming the hole.
  */
 public void addHole(LinearRing hole) {
   if (holes == null) holes = new ArrayList();
   holes.add(hole);
 }
 /**
  * Adds a {@link DirectedEdge} which is known to form part of this ring.
  *
  * @param de the {@link DirectedEdge} to add.
  */
 public void add(DirectedEdge de) {
   deList.add(de);
 }