Skip to content

Commit

Permalink
F!! triangle reindexing
Browse files Browse the repository at this point in the history
  • Loading branch information
tvomacka committed May 29, 2024
1 parent d339925 commit aa8caa0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
28 changes: 25 additions & 3 deletions Geometrica/DataStructures/DelaunayTriangulation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,30 @@ public static Triangle[] LegalizeTriangle(Triangle[] triangles, Triangle targetT
if (InCircle(targetTriangle[0], targetTriangle[1], targetTriangle[2], oppositeTriangle[oppositePointIndex]))
return triangles;

var origNeighborsTarget = new[] {
var origNeighborsTarget = new[]
{
targetTriangle.GetNeighbor(neighborIndex),
targetTriangle.GetNeighbor((neighborIndex + 1) % 3),
targetTriangle.GetNeighbor((neighborIndex + 2) % 3)
};
var origNeighborsOpposite = new[] {
var origNeighborsOpposite = new[]
{
oppositeTriangle.GetNeighbor(oppositePointIndex),
oppositeTriangle.GetNeighbor((oppositePointIndex + 1) % 3),
oppositeTriangle.GetNeighbor((oppositePointIndex + 2) % 3)
};
var origPointsTarget = new[]
{
targetTriangle[neighborIndex],
targetTriangle[(neighborIndex + 1) % 3],
targetTriangle[(neighborIndex + 2) % 3]
};
var origPointsOpposite = new[]
{
oppositeTriangle[oppositePointIndex],
oppositeTriangle[(oppositePointIndex + 1) % 3],
oppositeTriangle[(oppositePointIndex + 2) % 3]
};

if (origNeighborsTarget[2] != null)
{
Expand All @@ -115,7 +129,15 @@ public static Triangle[] LegalizeTriangle(Triangle[] triangles, Triangle targetT
origNeighborsOpposite[2].SetNeighbor(targetIndex, targetTriangle);
}

//for each of the original neighbors, set their neighbor references to the newly created triangles
targetTriangle[0] = origPointsTarget[0];
targetTriangle[1] = origPointsOpposite[0];
targetTriangle[2] = origPointsTarget[2];
targetTriangle.SetNeighbors(origNeighborsOpposite[2], origNeighborsTarget[1], oppositeTriangle);

oppositeTriangle[0] = origPointsTarget[0];
oppositeTriangle[1] = origPointsOpposite[2];
oppositeTriangle[2] = origPointsOpposite[0];
oppositeTriangle.SetNeighbors(origNeighborsOpposite[1], origNeighborsTarget[2], targetTriangle);

return triangles;
}
Expand Down
2 changes: 1 addition & 1 deletion GeometricaTests/DelaunayTriangulationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public void LegalizeTriangle_SwapsEdge_ForNonDelaunayPair()
triangles = DelaunayTriangulation.LegalizeTriangle(triangles, t1, 0);

var actual = string.Join<Triangle>(" ", triangles);
Assert.AreEqual("", actual);
Assert.AreEqual("Triangle [0; 0] [0.9; 0.9] [0; 1] Triangle [0; 0] [1; 0] [0.9; 0.9]", actual);
}

[TestMethod]
Expand Down

0 comments on commit aa8caa0

Please sign in to comment.