Пример #1
0
 private void CreateMountains()
 {
     foreach (Edge edge in this._edgeList)
     {
         if (edge.MPoints.Count > 2)
         {
             MonotoneMountain monotoneMountain = new MonotoneMountain();
             List <Point>     pointList        = new List <Point>((IEnumerable <Point>)edge.MPoints);
             pointList.Sort((Comparison <Point>)((p1, p2) => p1.X.CompareTo(p2.X)));
             foreach (Point point in pointList)
             {
                 monotoneMountain.Add(point);
             }
             monotoneMountain.Process();
             foreach (List <Point> triangle in monotoneMountain.Triangles)
             {
                 this.Triangles.Add(triangle);
             }
             this._xMonoPoly.Add(monotoneMountain);
         }
     }
 }
Пример #2
0
        // Build a list of x-monotone mountains
        private void CreateMountains()
        {
            foreach (Edge edge in _edgeList)
            {
                if (edge.MPoints.Count > 2)
                {
                    MonotoneMountain mountain = new MonotoneMountain();

                    // Sorting is a perfromance hit. Literature says this can be accomplised in
                    // linear time, although I don't see a way around using traditional methods
                    // when using a randomized incremental algorithm

                    // Insertion sort is one of the fastest algorithms for sorting arrays containing
                    // fewer than ten elements, or for lists that are already mostly sorted.

                    List <Point> points = new List <Point>(edge.MPoints);
                    points.Sort((p1, p2) => p1.X.CompareTo(p2.X));

                    foreach (Point p in points)
                    {
                        mountain.Add(p);
                    }

                    // Triangulate monotone mountain
                    mountain.Process();

                    // Extract the triangles into a single list
                    foreach (List <Point> t in mountain.Triangles)
                    {
                        Triangles.Add(t);
                    }

                    _xMonoPoly.Add(mountain);
                }
            }
        }