private void ComputeSelect(Envelope searchEnv, int start0, int end0, MonotoneChainSelectAction mcs) { Coordinate p0 = pts[start0]; Coordinate p1 = pts[end0]; mcs.tempEnv1.Initialize(p0, p1); // terminating condition for the recursion if (end0 - start0 == 1) { mcs.Select(this, start0); return; } // nothing to do if the envelopes don't overlap if (!searchEnv.Intersects(mcs.tempEnv1)) { return; } // the chains overlap, so split each in half and iterate (binary search) int mid = (start0 + end0) / 2; // Assert: mid != start or end (since we checked above for end - start <= 1) // check terminating conditions before recursing if (start0 < mid) { ComputeSelect(searchEnv, start0, mid, mcs); } if (mid < end0) { ComputeSelect(searchEnv, mid, end0, mcs); } }
/// <summary> /// Determine all the line segments in the chain whose envelopes overlap /// the searchEnvelope, and process them /// </summary> public void Select(Envelope searchEnv, MonotoneChainSelectAction mcs) { ComputeSelect(searchEnv, start, end, mcs); }