Ejemplo n.º 1
0
        public MeshResult RemoveEdge(int eID, bool bRemoveIsolatedVertices)
        {
            if (!edges_refcount.IsValid(eID))
            {
                Util.gDevAssert(false);
                return(MeshResult.Failed_NotATriangle);
            }

            int     i  = 3 * eID;
            Index2i ev = new Index2i(edges[i], edges[i + 1]);

            vertex_edges[ev.a].Remove(eID);
            vertex_edges[ev.b].Remove(eID);

            edges_refcount.Decrement(eID);

            // Decrement vertex refcounts. If any hit 1 and we got remove-isolated flag,
            // we need to remove that vertex
            for (int j = 0; j < 2; ++j)
            {
                int vid = ev[j];
                vertices_refcount.Decrement(vid);
                if (bRemoveIsolatedVertices && vertices_refcount.RefCount(vid) == 1)
                {
                    vertices_refcount.Decrement(vid);
                    Util.gDevAssert(vertices_refcount.IsValid(vid) == false);
                    vertex_edges[vid] = null;
                }
            }

            UpdateTimeStamp(true);
            return(MeshResult.Ok);
        }
Ejemplo n.º 2
0
        /// <summary>
        // This function checks that the graph is well-formed, ie all internal data
        // structures are consistent
        /// </summary>
        public bool CheckValidity(FailMode eFailMode = FailMode.Throw)
        {
            bool          is_ok        = true;
            Action <bool> CheckOrFailF = (b) => {
                is_ok = is_ok && b;
            };

            if (eFailMode == FailMode.DebugAssert)
            {
                CheckOrFailF = (b) => {
                    Debug.Assert(b);
                    is_ok = is_ok && b;
                };
            }
            else if (eFailMode == FailMode.gDevAssert)
            {
                CheckOrFailF = (b) => {
                    Util.gDevAssert(b);
                    is_ok = is_ok && b;
                };
            }
            else if (eFailMode == FailMode.Throw)
            {
                CheckOrFailF = (b) => {
                    if (b == false)
                    {
                        throw new Exception("DGraph2.CheckValidity: check failed");
                    }
                };
            }

            // edge verts/tris must exist
            foreach (int eID in EdgeIndices())
            {
                CheckOrFailF(IsEdge(eID));
                CheckOrFailF(edges_refcount.RefCount(eID) == 1);
                Index2i ev = GetEdgeV(eID);
                CheckOrFailF(IsVertex(ev[0]));
                CheckOrFailF(IsVertex(ev[1]));
                CheckOrFailF(ev[0] < ev[1]);
            }

            // verify compact check
            bool is_compact = vertices_refcount.Is_dense;

            if (is_compact)
            {
                for (int vid = 0; vid < vertices.Length / 3; ++vid)
                {
                    CheckOrFailF(vertices_refcount.IsValid(vid));
                }
            }

            // vertex edges must exist and reference this vert
            foreach (int vID in VertexIndices())
            {
                CheckOrFailF(IsVertex(vID));

                Vector2D v = GetVertex(vID);
                CheckOrFailF(double.IsNaN(v.LengthSquared) == false);
                CheckOrFailF(double.IsInfinity(v.LengthSquared) == false);

                List <int> l = vertex_edges[vID];
                foreach (int edgeid in l)
                {
                    CheckOrFailF(IsEdge(edgeid));
                    CheckOrFailF(Edge_has_v(edgeid, vID));

                    int otherV = Edge_other_v(edgeid, vID);
                    int e2     = FindEdge(vID, otherV);
                    CheckOrFailF(e2 != InvalidID);
                    CheckOrFailF(e2 == edgeid);
                    e2 = FindEdge(otherV, vID);
                    CheckOrFailF(e2 != InvalidID);
                    CheckOrFailF(e2 == edgeid);
                }

                CheckOrFailF(vertices_refcount.RefCount(vID) == l.Count + 1);
            }

            return(is_ok);
        }