コード例 #1
0
        private static bool Legalize(DTSweepContext tcx, DelaunayTriangle t)
        {
            for (int i = 0; i < 3; i++)
            {
                if (t.EdgeIsDelaunay[i])
                {
                    continue;
                }

                DelaunayTriangle ot = t.Neighbors[i];
                if (ot == null)
                {
                    continue;
                }

                TriangulationPoint p  = t.Points[i];
                TriangulationPoint op = ot.OppositePoint(t, p);
                int oi = ot.IndexOf(op);

                if (ot.EdgeIsConstrained[oi] || ot.EdgeIsDelaunay[oi])
                {
                    t.SetConstrainedEdgeAcross(p, ot.EdgeIsConstrained[oi]);
                    continue;
                }

                if (!TriangulationUtil.SmartIncircle(p, t.PointCCWFrom(p), t.PointCWFrom(p), op))
                {
                    continue;
                }


                t.EdgeIsDelaunay[i]   = true;
                ot.EdgeIsDelaunay[oi] = true;

                RotateTrianglePair(t, p, ot, op);

                if (!Legalize(tcx, t))
                {
                    tcx.MapTriangleToNodes(t);
                }
                if (!Legalize(tcx, ot))
                {
                    tcx.MapTriangleToNodes(ot);
                }

                t.EdgeIsDelaunay[i]   = false;
                ot.EdgeIsDelaunay[oi] = false;

                return(true);
            }
            return(false);
        }