Пример #1
0
 public void ClearDiagonalList()
 {
     if (head != null)
     {
         head = null;
     }
     n = 0;
 }
Пример #2
0
 public void DrawDiagonals(System.Drawing.Graphics g, System.Drawing.Color inColor)
 {
     System.Diagnostics.Debug.WriteLine("Drawing diagonals");
     cDiagonal dtemp = head;
     //g.setColor(inColor);
     //do
     //{
     //    g.drawLine(dtemp.v1.v.x, dtemp.v1.v.y, dtemp.v2.v.x, dtemp.v2.v.y);
     //    dtemp = dtemp.next;
     //} while (dtemp != head);
 }
Пример #3
0
 public void InsertBeforeHead(cDiagonal diag)
 {
     if (head == null)
     {
         InitHead(diag);
     }
     else
     {
         InsertBefore(diag, head);
     }
 }
Пример #4
0
        public void PrintDiagonals()
        {
            cDiagonal temp = head;
            int       i    = 0;

            do
            {
                temp.PrintDiagonal(i);
                temp = temp.next;
                i++;
            } while (temp != head);
        }
Пример #5
0
        /*---------------------------------------------------------------------
         * Prints out n-3 diagonals (as pairs of integer indices)
         * which form a triangulation of P.  This algorithm is O(n^2).
         * See Chapter 1 for a full explanation.
         * Triangulate operates on listcopy rather than list, so that
         * the original polygon is not destroyed.
         */
        public void Triangulate()
        {
            cVertex   v0, v1, v2, v3, v4;    // five consecutive pointCloud
            cDiagonal diag;
            int       n        = listcopy.n; //number of pointCloud; shrinks to 3
            bool      earfound = false;      //to prevent infinite loop on improper input

            EarInit();

            /* Each step of outer loop removes one ear. */
            while (n > 3)
            {
                /* Inner loop searches for an ear. */
                v2 = listcopy.head;
                do
                {
                    if (v2.IsEar)
                    {
                        /* Ear found. Fill variables. */
                        v3 = v2.NextVertex; v4 = v3.NextVertex;
                        v1 = v2.PrevVertex; v0 = v1.PrevVertex;

                        /* (v1,v3) is a diagonal */
                        earfound = true;
                        diag     = new cDiagonal(v1, v3);
                        diag.PrintDiagonal(listcopy.n - n);
                        diaglist.InsertBeforeHead(diag);

                        /* Update earity of diagonal endpoints */
                        v1.IsEar = Diagonal(v0, v3);
                        v3.IsEar = Diagonal(v1, v4);

                        /* Cut off the ear v2 */
                        v1.NextVertex = v3;
                        v3.PrevVertex = v1;
                        listcopy.head = v3; /* In case the head was v2. */
                        n--;
                        break;              /* out of inner loop; resume outer loop */
                    } /* end if ear found */
                    v2 = v2.NextVertex;
                } while (v2 != listcopy.head);
                if (!earfound)
                {
                    System.Diagnostics.Debug.WriteLine("Polygon is nonsimple: cannot triangulate");
                    break;
                }
                else
                {
                    earfound = false;
                }
                diagdrawn = false;
            } /* end outer while loop */
        }
Пример #6
0
 private void InsertBefore(cDiagonal newD, cDiagonal old)
 {
     if (head == null)
     {
         InitHead(newD);
     }
     else
     {
         old.prev.next = newD;
         newD.prev     = old.prev;
         newD.next     = old;
         old.prev      = newD;
         n++;
     }
 }
Пример #7
0
 private void InitHead(cDiagonal diag)
 {
     head      = new cDiagonal(diag.v1, diag.v2);
     head.next = head.prev = head;
     n         = 1;
 }
Пример #8
0
 public cDiagonalList()
 {
     head = null;
     n    = 0;
 }
Пример #9
0
 public cDiagonal()
 {
     next = prev = null;
     v1   = v2 = new cVertex();
 }