TriangleNet.Quality.CheckDelaunay C# (CSharp) Method

CheckDelaunay() public method

Ensure that the mesh is (constrained) Delaunay.
public CheckDelaunay ( ) : bool
return bool
        public bool CheckDelaunay()
        {
            Otri loop = default(Otri);
            Otri oppotri = default(Otri);
            Osub opposubseg = default(Osub);
            Vertex triorg, tridest, triapex;
            Vertex oppoapex;
            bool shouldbedelaunay;
            int horrors;
            bool saveexact;

            // Temporarily turn on exact arithmetic if it's off.
            saveexact = Behavior.NoExact;
            Behavior.NoExact = false;
            horrors = 0;

            // Run through the list of triangles, checking each one.
            foreach (var tri in mesh.triangles.Values)
            {
                loop.triangle = tri;

                // Check all three edges of the triangle.
                for (loop.orient = 0; loop.orient < 3;
                     loop.orient++)
                {
                    triorg = loop.Org();
                    tridest = loop.Dest();
                    triapex = loop.Apex();
                    loop.Sym(ref oppotri);
                    oppoapex = oppotri.Apex();
                    // Only test that the edge is locally Delaunay if there is an
                    // adjoining triangle whose pointer is larger (to ensure that
                    // each pair isn't tested twice).
                    shouldbedelaunay = (oppotri.triangle != Mesh.dummytri) &&
                          !Otri.IsDead(oppotri.triangle) && loop.triangle.id < oppotri.triangle.id &&
                          (triorg != mesh.infvertex1) && (triorg != mesh.infvertex2) &&
                          (triorg != mesh.infvertex3) &&
                          (tridest != mesh.infvertex1) && (tridest != mesh.infvertex2) &&
                          (tridest != mesh.infvertex3) &&
                          (triapex != mesh.infvertex1) && (triapex != mesh.infvertex2) &&
                          (triapex != mesh.infvertex3) &&
                          (oppoapex != mesh.infvertex1) && (oppoapex != mesh.infvertex2) &&
                          (oppoapex != mesh.infvertex3);
                    if (mesh.checksegments && shouldbedelaunay)
                    {
                        // If a subsegment separates the triangles, then the edge is
                        // constrained, so no local Delaunay test should be done.
                        loop.SegPivot(ref opposubseg);
                        if (opposubseg.seg != Mesh.dummysub)
                        {
                            shouldbedelaunay = false;
                        }
                    }
                    if (shouldbedelaunay)
                    {
                        if (Primitives.NonRegular(triorg, tridest, triapex, oppoapex) > 0.0)
                        {
                            logger.Warning(String.Format("Non-regular pair of triangles found (IDs {0}/{1}).",
                                loop.triangle.id, oppotri.triangle.id), "Quality.CheckDelaunay()");
                            horrors++;
                        }
                    }
                }

            }

            if (horrors == 0) // && Behavior.Verbose
            {
                logger.Info("Mesh is Delaunay.");
            }

            // Restore the status of exact arithmetic.
            Behavior.NoExact = saveexact;

            return (horrors == 0);
        }