findChainEnd method

int findChainEnd(
  1. List<Coordinate> pts,
  2. int start
)

@return the index of the last point in the monotone chain

Implementation

int findChainEnd(List<Coordinate> pts, int start) {
  // determine quadrant for chain
  int chainQuad = Quadrant.quadrantFromCoords(pts[start], pts[start + 1]);
  int last = start + 1;
  while (last < pts.length) {
    //if (last - start > 100) break;
    // compute quadrant for next possible segment in chain
    int quad = Quadrant.quadrantFromCoords(pts[last - 1], pts[last]);
    if (quad != chainQuad) break;
    last++;
  }
  return last - 1;
}