addRegion method

void addRegion(
  1. List<Coordinate> region
)

Implementation

void addRegion(List<JTS.Coordinate> region) {
  if (!selfIntersection) {
    throw new Exception(
        "The addRegion() function is only intended for use when selfIntersection = false");
  }

  // Ensure that the polygon is fully closed (the start point and end point are exactly the same)
  if (!Epsilon().pointsSame(region[region.length - 1], region[0])) {
    region.add(region[0]);
  }

  // regions are a list of points:
  //  [ [0, 0], [100, 0], [50, 100] ]
  // you can add multiple regions before running calculate
  var pt1 = new JTS.Coordinate(0, 0);
  var pt2 = region[region.length - 1];

  for (var i = 0; i < region.length; i++) {
    pt1 = pt2;
    pt2 = region[i];

    var forward = Epsilon().pointsCompare(pt1, pt2);
    if (forward == 0) // points are equal, so we have a zero-length segment
      continue; // just skip it

    eventAddSegment(
        segmentNew(forward < 0 ? pt1 : pt2, forward < 0 ? pt2 : pt1), true);
  }
}