Esempio n. 1
0
        bool AdjustConnection(AM_Edge[] poldConn)
        {
            for (int i = 0; i < NumEdges; i++)
            {
                AM_Edge pconnSx = poldConn[i * 2];
                AM_Edge pconnDx = poldConn[(i * 2 + (NumEdges * 2) - 1) % (NumEdges * 2)];


                if (pconnDx == null && pconnSx == null)
                {
                    if (Vertex(i).Edge != null)
                    {
                        // Inserisce i due spigoli della faccia nell'anello del vertice
                        // individuato da Vertex(i)

                        AM_Edge pedge = ((AM_Edge)(Vertex(i).Edge)).FindLastConnected();
                        Debug.Assert(pedge != null);
                        AM_Edge poldnextEdge = pedge.Next;

                        m_pEdges[i].Prev      = pedge;
                        pedge.Next            = m_pEdges[i];
                        poldnextEdge.Prev     = m_pEdges[i].Next;
                        m_pEdges[i].Next.Next = poldnextEdge;
                    }
                    else
                    {
                        // Lo spigolo è isolato: inizializza l'anello

                        m_pEdges[i].Prev      = m_pEdges[i].Next;
                        m_pEdges[i].Next.Next = m_pEdges[i];
                        Vertex(i).Edge        = m_pEdges[i];
                    }
                }
                else
                {
                    if (pconnSx == pconnDx)
                    {
                        continue;
                    }
                    // vi erano connessioni preesistenti: l'anello viene aggiornato
                    if (pconnSx != null) // anello in senso antiorario
                    {
                        AM_Edge padjust = pconnSx;
                        AM_Edge pstart  = pconnSx.Prev;

                        /*TRACE_EDGE(padjust);
                         * TRACE_EDGE(pstart);*/

                        int ncheck = 0; //contatore per evitare loop infinito
                        while (padjust != null)
                        {
                            if (ncheck++ > 300)
                            {
                                Debug.Assert(false);
                                return(false);
                            }

                            if (padjust.Prev.Next == padjust)
                            {
                                break;
                            }
                            AM_Edge pnewconn = padjust;
                            padjust.Prev = pstart.FindLastConnected();
                            pstart       = padjust.Prev;
                            padjust      = pstart.Next;
                            pstart.Next  = pnewconn;
                        }
                    }

                    if (pconnDx != null) // anello in senso orario
                    {
                        AM_Edge padjust = pconnDx;
                        AM_Edge pstart  = pconnDx.Next;

                        /*TRACE_EDGE(padjust);
                         * TRACE_EDGE(pstart);*/
                        int ncheck = 0; //contatore per evitare loop infinito

                        while (padjust != null)
                        {
                            if (ncheck++ > 300)
                            {
                                Debug.Assert(false);
                                return(false);
                            }

                            if (padjust.Next.Prev == padjust)
                            {
                                break;
                            }
                            AM_Edge pnewconn = padjust;
                            padjust.Next = pstart.FindLastConnected(false);
                            pstart       = padjust.Next;
                            padjust      = pstart.Prev;
                            pstart.Prev  = pnewconn;
                        }
                    }
                }
            }

            return(true);
        }