findCoveredLineEdges method

void findCoveredLineEdges()

Traverse the star of edges, maintaining the current location in the result area at this node (if any). If any L edges are found in the interior of the result, mark them as covered.

Implementation

void findCoveredLineEdges() {
//Debug.print("findCoveredLineEdges");
//Debug.print(this);
  // Since edges are stored in CCW order around the node,
  // as we move around the ring we move from the right to the left side of the edge

  /**
   * Find first DirectedEdge of result area (if any).
   * The interior of the result is on the RHS of the edge,
   * so the start location will be:
   * - INTERIOR if the edge is outgoing
   * - EXTERIOR if the edge is incoming
   */
  int startLoc = Location.NONE;
  for (Iterator it = iterator(); it.moveNext();) {
    DirectedEdge nextOut = it.current as DirectedEdge;
    DirectedEdge nextIn = nextOut.getSym();
    if (!nextOut.isLineEdge()) {
      if (nextOut.isInResult()) {
        startLoc = Location.INTERIOR;
        break;
      }
      if (nextIn.isInResult()) {
        startLoc = Location.EXTERIOR;
        break;
      }
    }
  }
  // no A edges found, so can't determine if L edges are covered or not
  if (startLoc == Location.NONE) return;

  /**
   * move around ring, keeping track of the current location
   * (Interior or Exterior) for the result area.
   * If L edges are found, mark them as covered if they are in the interior
   */
  int currLoc = startLoc;
  for (Iterator it = iterator(); it.moveNext();) {
    DirectedEdge nextOut = it.current as DirectedEdge;
    DirectedEdge nextIn = nextOut.getSym();
    if (nextOut.isLineEdge()) {
      nextOut.getEdge().setCovered(currLoc == Location.INTERIOR);
//Debug.println(nextOut);
    } else {
      // edge is an Area edge
      if (nextOut.isInResult()) currLoc = Location.EXTERIOR;
      if (nextIn.isInResult()) currLoc = Location.INTERIOR;
    }
  }
}