Skip to content

Commit

Permalink
Test that Delaunay triangles wind clockwise (#624)
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Peters <[email protected]>
  • Loading branch information
scpeters authored Aug 15, 2024
1 parent bc57626 commit 3413caa
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions graphics/src/DelaunayTriangulation_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,25 @@ TEST_F(DelaunayTriangulation, DelaunayTriangulation)

// there should be 8 triangles.
EXPECT_EQ(subMesh.IndexCount() / 3u, 8u);

// verify that triangles have clockwise winding
for (int t = 0; t < subMesh.IndexCount() / 3u; ++t)
{
int vertexIndex1 = subMesh.Index(t*3 + 0);
int vertexIndex2 = subMesh.Index(t*3 + 1);
int vertexIndex3 = subMesh.Index(t*3 + 2);
// compute displacement from vertex 1 to 2
auto displacement12 =
subMesh.Vertex(vertexIndex2) - subMesh.Vertex(vertexIndex1);
// compute displacement from vertex 2 to 3
auto displacement23 =
subMesh.Vertex(vertexIndex3) - subMesh.Vertex(vertexIndex2);
// compute cross product (v2-v1) x (v3 - v2)
auto crossProduct_12_23 = displacement12.Cross(displacement23);
// X and Y components should be zero
EXPECT_DOUBLE_EQ(0.0, crossProduct_12_23.X());
EXPECT_DOUBLE_EQ(0.0, crossProduct_12_23.Y());
// Z component should be negative for a clockwise winding
EXPECT_LT(crossProduct_12_23.Z(), 0.0);
}
}

0 comments on commit 3413caa

Please sign in to comment.