Пример #1
0
bool MyObject::buildHalfEdges(THalfEdgeList& lst)
{
    int pli, i;

    TPointPairHash m_pntmap;
    m_pntmap.reserve(150);
    // the pointer is the half edge already between these points

    for(pli = 0; pli < nPolys; ++pli)
    {
        MyPolygon *pol = poly[pli];

        HalfEdge *he = nullptr, *lasthe = nullptr;
        for(i = 3; i >= 0; --i)
        {
            //he = new HalfEdge(pol, pol->vtx[i], he);
            HalfEdge *prevhe = he;
            he = m_alloc->m_hePool.allocate();
            he->init(pol, pol->vtx[i], prevhe);
            lst.push_back(he);
            if (lasthe == nullptr)
                lasthe = he;

            if (pol->vtx[i]->he == nullptr)
                pol->vtx[i]->he = he;

        }
        lasthe->next = he;
        pol->he = he;

        for(i = 3; i >= 0; --i)
        {	
            PointPair pp(he->point, he->next->point);
            TPointPairHash::iterator it = m_pntmap.find(pp);
            if (it == m_pntmap.end()) // its not there, add it
                m_pntmap.insert(make_pair(pp, he));
            else
            {
                HalfEdge *she = it->second;
                M_ASSERT((she->next->point == he->point) && (he->next->point == she->point));
                he->pair = she;
                she->pair = he;
                m_pntmap.erase(it); // no longer needed in the map
            }
            he = he->next;
        }
        // maximum size of m_pntmap is 134
    }

    M_ASSERT(m_pntmap.empty());

    return true;
}