propagateSideLabels method

void propagateSideLabels(
  1. int geomIndex
)

Implementation

void propagateSideLabels(int geomIndex) {
  // 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
  int startLoc = Location.NONE;

  // initialize loc to location of last L side (if any)
//System.out.println("finding start location");
  for (Iterator it = iterator(); it.moveNext();) {
    EdgeEnd e = it.current;
    Label label = e.getLabel()!;
    if (label.isAreaWithIndex(geomIndex) &&
        label.getLocationWithPosIndex(geomIndex, Position.LEFT) !=
            Location.NONE)
      startLoc = label.getLocationWithPosIndex(geomIndex, Position.LEFT);
  }

  // no labelled sides found, so no labels to propagate
  if (startLoc == Location.NONE) return;

  int currLoc = startLoc;
  for (Iterator it = iterator(); it.moveNext();) {
    EdgeEnd e = it.current;
    Label label = e.getLabel()!;
    // set null ON values to be in current location
    if (label.getLocationWithPosIndex(geomIndex, Position.ON) ==
        Location.NONE) label.setLocation(geomIndex, Position.ON, currLoc);
    // set side labels (if any)
    if (label.isAreaWithIndex(geomIndex)) {
      int leftLoc = label.getLocationWithPosIndex(geomIndex, Position.LEFT);
      int rightLoc = label.getLocationWithPosIndex(geomIndex, Position.RIGHT);
      // if there is a right location, that is the next location to propagate
      if (rightLoc != Location.NONE) {
//Debug.print(rightLoc != currLoc, this);
        if (rightLoc != currLoc)
          throw new TopologyException(
              "side location conflict ${e.getCoordinate()}");
        if (leftLoc == Location.NONE) {
          Assert.shouldNeverReachHere(
              "found single null side (at ${e.getCoordinate()})");
        }
        currLoc = leftLoc;
      } else {
        /** RHS is null - LHS must be null too.
         *  This must be an edge from the other geometry, which has no location
         *  labelling for this geometry.  This edge must lie wholly inside or outside
         *  the other geometry (which is determined by the current location).
         *  Assign both sides to be the current location.
         */
        assert(
            label.getLocationWithPosIndex(geomIndex, Position.LEFT) ==
                Location.NONE,
            "found single null side");
        label.setLocation(geomIndex, Position.RIGHT, currLoc);
        label.setLocation(geomIndex, Position.LEFT, currLoc);
      }
    }
  }
}