Exemplo n.º 1
0
        private static void AssignFaceHandle(this Geometry geometry, int heHandle, Face newFace)
        {
            var oldFaceHandle = geometry.GetHalfEdgeByHandle(heHandle).IncidentFace;
            var currentHe     = geometry.GetHalfEdgeByHandle(heHandle);

            do
            {
                currentHe.IncidentFace = newFace.Handle;

                geometry.DictHalfEdges[currentHe.Handle] = currentHe;

                currentHe = geometry.GetHalfEdgeByHandle(currentHe.NextHalfEdge);
            } while (currentHe.Handle != heHandle);

            //Assign newFace to possible holes in the "old" face.
            var oldFace = geometry.GetFaceByHandle(oldFaceHandle);

            if (oldFace.InnerHalfEdges.Count == 0)
            {
                return;
            }

            var inner = new List <int>();

            inner.AddRange(oldFace.InnerHalfEdges);

            foreach (var heh in inner)
            {
                var origin = geometry.GetHalfEdgeByHandle(heh).OriginVertex;

                if (!geometry.IsPointInPolygon(newFace, geometry.GetVertexByHandle(origin)))
                {
                    continue;
                }

                oldFace.InnerHalfEdges.Remove(heh);
                newFace.InnerHalfEdges.Add(heh);

                var curHe = geometry.GetHalfEdgeByHandle(heh);
                do
                {
                    curHe.IncidentFace = newFace.Handle;

                    geometry.DictHalfEdges[curHe.Handle] = curHe;

                    curHe = geometry.GetHalfEdgeByHandle(curHe.NextHalfEdge);
                } while (curHe.Handle != heh);
            }
        }