/**************************************************************** * 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(Coordinate vertex) { PolygonHelper polygon = new PolygonHelper(m_aUpdatedPolygonVertices); if (polygon.PolygonVertex(vertex)) { bool bEar = true; if (polygon.VertexType(vertex) == PolygonVertexType.ConvexPoint) { Coordinate pi = vertex; Coordinate pj = polygon.PreviousPoint(vertex); //previous vertex Coordinate pk = polygon.NextPoint(vertex); //next vertex for (int i = m_aUpdatedPolygonVertices.GetLowerBound(0); i < m_aUpdatedPolygonVertices.GetUpperBound(0); i++) { Coordinate pt = m_aUpdatedPolygonVertices[i]; if (!(pt.Equals(pi) || pt.Equals(pj) || pt.Equals(pk))) { if (TriangleContainsPoint(new Coordinate[] { 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; { Debug.WriteLine("IsEarOfUpdatedPolygon: " + "Not a polygon vertex"); return(false); } }
/******************************************************** * To update m_aUpdatedPolygonVertices: * Take out Vertex from m_aUpdatedPolygonVertices array, add 3 points * to the m_aEars **********************************************************/ private void UpdatePolygonVertices(Coordinate vertex) { ArrayList alTempPts = new ArrayList(); for (int i = 0; i < m_aUpdatedPolygonVertices.Length; i++) { //add 3 pts to FEars if (vertex.Equals(m_aUpdatedPolygonVertices[i])) { PolygonHelper polygon = new PolygonHelper(m_aUpdatedPolygonVertices); Coordinate pti = vertex; Coordinate ptj = polygon.PreviousPoint(vertex); //previous point Coordinate ptk = polygon.NextPoint(vertex); //next point //3 vertices of each ear Coordinate[] aEar = new Coordinate[3]; 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 Coordinate[nLength - 1]; for (int i = 0; i < alTempPts.Count; i++) { m_aUpdatedPolygonVertices[i] = (Coordinate)alTempPts[i]; } } }