public static void Simplify(Polyline input, double threshold, HandleSegment handler) { if (input.Length < 2) return; Polyline output = new Polyline(); Recurse(input, threshold, handler, 0, input.Length - 1); }
private static void Recurse(Polyline input, double threshold, HandleSegment handler, int i, int j) { double maxDistance; int maxI; FindSplit(input, i, j, out maxDistance, out maxI); if (maxDistance > threshold * threshold) { Recurse(input, threshold, handler, i, maxI); Recurse(input, threshold, handler, maxI, j); } else { handler(i, j); } }