Skip to content

Commit

Permalink
Mesh.AppendTriangle can return multiple failure codes, InvalidID chec…
Browse files Browse the repository at this point in the history
…k is not sufficient.
  • Loading branch information
rms80 committed May 30, 2018
1 parent 929fb18 commit 4ae0035
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
16 changes: 9 additions & 7 deletions mesh/MeshEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -218,7 +218,7 @@ public virtual int[] StitchUnorderedEdges(List<Index2i> 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;
Expand Down Expand Up @@ -268,7 +268,7 @@ public virtual int[] StitchSpan(IList<int> vspan1, IList<int> 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;
Expand Down Expand Up @@ -539,9 +539,10 @@ static int bowtie_sorter(List<int> l1, List<int> l2) {

/// <summary>
/// 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.
/// </summary>
public void DisconnectAllBowties(int nMaxIters = 10)
public int DisconnectAllBowties(int nMaxIters = 10)
{
List<int> bowties = new List<int>(MeshIterators.BowtieVertices(Mesh));
int iter = 0;
Expand All @@ -550,6 +551,7 @@ public void DisconnectAllBowties(int nMaxIters = 10)
DisconnectBowtie(vid);
bowties = new List<int>(MeshIterators.BowtieVertices(Mesh));
}
return bowties.Count;
}


Expand Down
8 changes: 4 additions & 4 deletions mesh_ops/SimpleHoleFiller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

}

Expand Down

0 comments on commit 4ae0035

Please sign in to comment.