From 4ae00358e8c5ba0b3603a821aa2e3e5d98d1d2d2 Mon Sep 17 00:00:00 2001 From: Ryan Schmidt Date: Tue, 29 May 2018 23:05:03 -0400 Subject: [PATCH] Mesh.AppendTriangle can return multiple failure codes, InvalidID check is not sufficient. --- mesh/MeshEditor.cs | 16 +++++++++------- mesh_ops/SimpleHoleFiller.cs | 8 ++++---- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/mesh/MeshEditor.cs b/mesh/MeshEditor.cs index 8f201332..c9fc872b 100644 --- a/mesh/MeshEditor.cs +++ b/mesh/MeshEditor.cs @@ -72,7 +72,7 @@ public virtual int[] AddTriangleFan_OrderedVertexLoop(int center, int[] vertex_l Index3i newT = new Index3i(center, b, a); int new_tid = Mesh.AppendTriangle(newT, group_id); - if (new_tid == DMesh3.InvalidID) + if (new_tid < 0) goto operation_failed; new_tris[i] = new_tid; @@ -109,7 +109,7 @@ public virtual int[] AddTriangleFan_OrderedEdgeLoop(int center, int[] edge_loop, Index3i newT = new Index3i(center, b, a); int new_tid = Mesh.AppendTriangle(newT, group_id); - if (new_tid == DMesh3.InvalidID) + if (new_tid < 0) goto operation_failed; new_tris[i] = new_tid; @@ -156,7 +156,7 @@ public virtual int[] StitchLoop(int[] vloop1, int[] vloop2, int group_id = -1) int tid1 = Mesh.AppendTriangle(t1, group_id); int tid2 = Mesh.AppendTriangle(t2, group_id); - if (tid1 == DMesh3.InvalidID || tid2 == DMesh3.InvalidID) + if (tid1 < 0 || tid2 < 0) goto operation_failed; new_tris[2 * i] = tid1; @@ -218,7 +218,7 @@ public virtual int[] StitchUnorderedEdges(List EdgePairs, int group_id int tid1 = Mesh.AppendTriangle(t1, group_id); int tid2 = Mesh.AppendTriangle(t2, group_id); - if (tid1 == DMesh3.InvalidID || tid2 == DMesh3.InvalidID) + if (tid1 < 0 || tid2 < 0) goto operation_failed; new_tris[2 * i] = tid1; @@ -268,7 +268,7 @@ public virtual int[] StitchSpan(IList vspan1, IList vspan2, int group_ int tid1 = Mesh.AppendTriangle(t1, group_id); int tid2 = Mesh.AppendTriangle(t2, group_id); - if (tid1 == DMesh3.InvalidID || tid2 == DMesh3.InvalidID) + if (tid1 < 0 || tid2 < 0) goto operation_failed; new_tris[2 * i] = tid1; @@ -539,9 +539,10 @@ static int bowtie_sorter(List l1, List l2) { /// /// Disconnect all bowtie vertices in mesh. Iterates because sometimes - /// disconnecting a bowtie creates new bowties (how??) + /// disconnecting a bowtie creates new bowties (how??). + /// Returns number of remaining bowties after iterations. /// - public void DisconnectAllBowties(int nMaxIters = 10) + public int DisconnectAllBowties(int nMaxIters = 10) { List bowties = new List(MeshIterators.BowtieVertices(Mesh)); int iter = 0; @@ -550,6 +551,7 @@ public void DisconnectAllBowties(int nMaxIters = 10) DisconnectBowtie(vid); bowties = new List(MeshIterators.BowtieVertices(Mesh)); } + return bowties.Count; } diff --git a/mesh_ops/SimpleHoleFiller.cs b/mesh_ops/SimpleHoleFiller.cs index 5ac92f55..1b0e072f 100644 --- a/mesh_ops/SimpleHoleFiller.cs +++ b/mesh_ops/SimpleHoleFiller.cs @@ -41,7 +41,7 @@ public virtual bool Fill(int group_id = -1) if ( Loop.Vertices.Length == 3 ) { Index3i tri = new Index3i(Loop.Vertices[0], Loop.Vertices[2], Loop.Vertices[1]); int new_tid = Mesh.AppendTriangle(tri, group_id); - if (new_tid == DMesh3.InvalidID) + if (new_tid < 0) return false; NewTriangles = new int[1] { new_tid }; NewVertex = DMesh3.InvalidID; @@ -72,9 +72,9 @@ public virtual bool Fill(int group_id = -1) if ( NewTriangles == null ) { Mesh.RemoveVertex(NewVertex, true, false); NewVertex = DMesh3.InvalidID; - } - - return true; + return false; + } else + return true; }