Пример #1
0
        public void CutEar()
        {
            RegionPolygon polygon = new RegionPolygon(m_aUpdatedPolygonVertices);
            bool          bFinish = false;

            //if (polygon.GetPolygonType()==PolygonType.Convex) //don't have to cut ear
            //	bFinish=true;

            if (m_aUpdatedPolygonVertices.Length == 3) //triangle, don't have to cut ear
            {
                bFinish = true;
            }

            LatLng pt = new LatLng();

            while (bFinish == false) //UpdatedPolygon
            {
                int  i         = 0;
                bool bNotFound = true;
                while (bNotFound &&
                       (i < m_aUpdatedPolygonVertices.Length)) //loop till find an ear
                {
                    pt = m_aUpdatedPolygonVertices[i];
                    if (IsEarOfUpdatedPolygon(pt))
                    {
                        bNotFound = false; //got one, pt is an ear
                    }
                    else
                    {
                        i++;
                    }
                } //bNotFount
                  //An ear found:}
                if (pt != null)
                {
                    UpdatePolygonVertices(pt);
                }

                polygon = new RegionPolygon(m_aUpdatedPolygonVertices);
                //if ((polygon.GetPolygonType()==PolygonType.Convex)
                //	&& (m_aUpdatedPolygonVertices.Length==3))
                if (m_aUpdatedPolygonVertices.Length == 3)
                {
                    bFinish = true;
                }
            } //bFinish=false
            SetPolygons();
        }
Пример #2
0
        /****************************************************************
         *      To check whether the Vertex is an ear or not based updated Polygon vertices
         *
         *      ref. www-cgrl.cs.mcgill.ca/~godfried/teaching/cg-projects/97/Ian
         *      /algorithm1.html
         *
         *      If it is an ear, return true,
         *      If it is not an ear, return false;
         *****************************************************************/
        private bool IsEarOfUpdatedPolygon(LatLng vertex)
        {
            RegionPolygon polygon = new RegionPolygon(m_aUpdatedPolygonVertices);

            if (polygon.Vertices.PolygonVertex(vertex))
            {
                bool bEar = true;
                if (polygon.Vertices.PolygonVertexType(vertex) == PolygonType.Convex)
                {
                    LatLng pi = vertex;
                    LatLng pj = polygon.Vertices.PreviousPoint(vertex); //previous vertex
                    LatLng pk = polygon.Vertices.NextPoint(vertex);     //next vertex

                    for (int i = m_aUpdatedPolygonVertices.GetLowerBound(0);
                         i < m_aUpdatedPolygonVertices.GetUpperBound(0); i++)
                    {
                        LatLng pt = m_aUpdatedPolygonVertices[i];
                        if (!(pt.EqualsPoint(pi) || pt.EqualsPoint(pj) || pt.EqualsPoint(pk)))
                        {
                            if (TriangleContainsPoint(new LatLng[] { pj, pi, pk }, pt))
                            {
                                bEar = false;
                            }
                        }
                    }
                }    //ThePolygon.getVertexType(Vertex)=ConvexPt
                else //concave point
                {
                    bEar = false; //not an ear/
                }
                return(bEar);
            }
            else //not a polygon vertex;
            {
                System.Diagnostics.Trace.WriteLine("IsEarOfUpdatedPolygon: " +
                                                   "Not a polygon vertex");
                return(false);
            }
        }
Пример #3
0
        /********************************************************
         *      To update m_aUpdatedPolygonVertices:
         *      Take out Vertex from m_aUpdatedPolygonVertices array, add 3 points
         *      to the m_aEars
         **********************************************************/
        private void UpdatePolygonVertices(LatLng vertex)
        {
            ArrayList alTempPts = new ArrayList();

            for (int i = 0; i < m_aUpdatedPolygonVertices.Length; i++)
            {
                if (vertex.EqualsPoint(
                        m_aUpdatedPolygonVertices[i])) //add 3 pts to FEars
                {
                    RegionPolygon polygon = new RegionPolygon(m_aUpdatedPolygonVertices);
                    LatLng        pti     = vertex;
                    LatLng        ptj     = polygon.Vertices.PreviousPoint(vertex); //previous point
                    LatLng        ptk     = polygon.Vertices.NextPoint(vertex);     //next point

                    LatLng[] aEar = new LatLng[3];                                  //3 vertices of each ear
                    aEar[0] = ptj;
                    aEar[1] = pti;
                    aEar[2] = ptk;

                    m_alEars.Add(aEar);
                }
                else
                {
                    alTempPts.Add(m_aUpdatedPolygonVertices[i]);
                } //not equal points
            }

            if (m_aUpdatedPolygonVertices.Length
                - alTempPts.Count == 1)
            {
                int nLength = m_aUpdatedPolygonVertices.Length;
                m_aUpdatedPolygonVertices = new LatLng[nLength - 1];

                for (int i = 0; i < alTempPts.Count; i++)
                {
                    m_aUpdatedPolygonVertices[i] = (LatLng)alTempPts[i];
                }
            }
        }