/// <summary> /// Simplification by using Douglas-Peucker variant algorithm /// </summary> /// <param name="points">input points</param> /// <param name="maxPoints">the maximum number of points of the simplified polyline</param> /// <returns>simplified polyline</returns> private static bool[] SimplifyByDouglasPeuckerNHelp(GPoint[] points, int maxPoints) { int pointCount = points.Length; bool[] keys = new bool[pointCount]; keys[0] = true; // the first point is always a key keys[pointCount - 1] = true; // the last point is always a key int keyCount = 2; PriorityQueue <SubPolyAlt> queue = new PriorityQueue <SubPolyAlt>(); SubPolyAlt subPoly = new SubPolyAlt(0, pointCount - 1); subPoly.KeyInfo = FindKey(points, subPoly.First, subPoly.Last); queue.Push(subPoly); // add complete poly while (!queue.IsEmpty()) { subPoly = queue.Top(); // take a sub poly queue.Pop(); // store the key keys[subPoly.KeyInfo.Index] = true; // check point count tolerance keyCount++; if (keyCount == maxPoints) { break; } // split the polyline at the key and recurse SubPolyAlt left = new SubPolyAlt(subPoly.First, subPoly.KeyInfo.Index); left.KeyInfo = FindKey(points, left.First, left.Last); if (left.KeyInfo.Index > 0) { queue.Push(left); } SubPolyAlt right = new SubPolyAlt(subPoly.KeyInfo.Index, subPoly.Last); right.KeyInfo = FindKey(points, right.First, right.Last); if (right.KeyInfo.Index > 0) { queue.Push(right); } } return(keys); }
public int CompareTo(object obj) { SubPolyAlt other = obj as SubPolyAlt; if (other == null) { return(-1); } if (KeyInfo.Dist2 < other.KeyInfo.Dist2) { return(-1); } else if (KeyInfo.Dist2 < other.KeyInfo.Dist2) { return(1); } else { return(0); } }