addPolygon method

void addPolygon(
  1. Polygon p
)

Implementation

void addPolygon(Polygon p) {
  double offsetDistance = distance;
  int offsetSide = Position.LEFT;
  if (distance < 0.0) {
    offsetDistance = -distance;
    offsetSide = Position.RIGHT;
  }

  LinearRing shell = p.getExteriorRing();
  List<Coordinate> shellCoord =
      CoordinateArrays.removeRepeatedPoints(shell.getCoordinates());
  // optimization - don't bother computing buffer
  // if the polygon would be completely eroded
  if (distance < 0.0 && isErodedCompletely(shell, distance)) return;
  // don't attempt to buffer a polygon with too few distinct vertices
  if (distance <= 0.0 && shellCoord.length < 3) return;

  addRingSide(shellCoord, offsetDistance, offsetSide, Location.EXTERIOR,
      Location.INTERIOR);

  for (int i = 0; i < p.getNumInteriorRing(); i++) {
    LinearRing hole = p.getInteriorRingN(i);
    List<Coordinate> holeCoord =
        CoordinateArrays.removeRepeatedPoints(hole.getCoordinates());

    // optimization - don't bother computing buffer for this hole
    // if the hole would be completely covered
    if (distance > 0.0 && isErodedCompletely(hole, -distance)) continue;

    // Holes are topologically labelled opposite to the shell, since
    // the interior of the polygon lies on their opposite side
    // (on the left, if the hole is oriented CCW)
    addRingSide(holeCoord, offsetDistance, Position.opposite(offsetSide),
        Location.INTERIOR, Location.EXTERIOR);
  }
}