/// <summary> /// Remove the segs in the section of the line. /// </summary> /// <param name="line"></param> /// <param name="start"></param> /// <param name="end"></param> private void Remove(TaggedLineString line, int start, int end) { for (int i = start; i < end; i++) { TaggedLineSegment seg = line.GetSegment(i); inputIndex.Remove(seg); } }
/// <summary> /// /// </summary> /// <param name="i"></param> /// <param name="j"></param> /// <param name="depth"></param> private void SimplifySection(int i, int j, int depth) { depth += 1; int[] sectionIndex = new int[2]; if ((i + 1) == j) { LineSegment newSeg = line.GetSegment(i); line.AddToResult(newSeg); // leave this segment in the input index, for efficiency return; } double[] distance = new double[1]; int furthestPtIndex = FindFurthestPoint(linePts, i, j, distance); bool isValidToFlatten = true; // must have enough points in the output line if (line.ResultSize < line.MinimumSize && depth < 2) { isValidToFlatten = false; } // flattening must be less than distanceTolerance if (distance[0] > DistanceTolerance) { isValidToFlatten = false; } // test if flattened section would cause intersection LineSegment candidateSeg = new LineSegment(); candidateSeg.P0 = linePts[i]; candidateSeg.P1 = linePts[j]; sectionIndex[0] = i; sectionIndex[1] = j; if (HasBadIntersection(line, sectionIndex, candidateSeg)) { isValidToFlatten = false; } if (isValidToFlatten) { LineSegment newSeg = Flatten(i, j); line.AddToResult(newSeg); return; } SimplifySection(i, furthestPtIndex, depth); SimplifySection(furthestPtIndex, j, depth); }