Skip to content

Commit

Permalink
refactor: refinement internal methods
Browse files Browse the repository at this point in the history
This refactor is part of a series of changes preparing for the introduction of a dynamic point insertion utility.
  • Loading branch information
andywiecko committed Oct 13, 2024
1 parent 57bad49 commit 8212ccf
Showing 1 changed file with 30 additions and 39 deletions.
69 changes: 30 additions & 39 deletions Runtime/Triangulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2876,32 +2876,23 @@ private void RecalculateBadTriangles(T2 p)
{
while (trianglesQueue.TryDequeue(out var tId))
{
VisitEdge(p, 3 * tId + 0);
VisitEdge(p, 3 * tId + 1);
VisitEdge(p, 3 * tId + 2);
}
}

private void VisitEdge(T2 p, int t0)
{
var he = halfedges[t0];
if (he == -1 || constrainedHalfedges[he])
{
return;
}

var otherId = he / 3;
if (visitedTriangles[otherId])
{
return;
}
for (int i = 0; i < 3; i++)
{
var he = halfedges[3 * tId + i];
var otherId = he / 3;
if (he == -1 || constrainedHalfedges[he] || visitedTriangles[otherId])
{
continue;
}

var circle = circles[otherId];
if (utils.le(utils.Cast(utils.distancesq(circle.Center, p)), circle.RadiusSq))
{
badTriangles.Add(otherId);
trianglesQueue.Enqueue(otherId);
visitedTriangles[otherId] = true;
var circle = circles[otherId];
if (utils.le(utils.Cast(utils.distancesq(circle.Center, p)), circle.RadiusSq))
{
badTriangles.Add(otherId);
trianglesQueue.Enqueue(otherId);
visitedTriangles[otherId] = true;
}
}
}
}

Expand Down Expand Up @@ -2979,6 +2970,17 @@ private void BuildStarPolygon()

private void ProcessBadTriangles(NativeList<int> heQueue, NativeList<int> tQueue)
{
static void RemoveHalfedge(NativeList<int> halfedges, int he, int offset)
{
var ohe = halfedges[he];
var o = ohe > he ? ohe - offset : ohe;
if (o > -1)
{
halfedges[o] = -1;
}
halfedges.RemoveAt(he);
}

// Remove bad triangles and recalculate polygon path halfedges.
badTriangles.Sort();
for (int t = badTriangles.Length - 1; t >= 0; t--)
Expand All @@ -2988,9 +2990,9 @@ private void ProcessBadTriangles(NativeList<int> heQueue, NativeList<int> tQueue
triangles.RemoveAt(3 * tId + 1);
triangles.RemoveAt(3 * tId + 0);
circles.RemoveAt(tId);
RemoveHalfedge(3 * tId + 2, 0);
RemoveHalfedge(3 * tId + 1, 1);
RemoveHalfedge(3 * tId + 0, 2);
RemoveHalfedge(halfedges, 3 * tId + 2, 0);
RemoveHalfedge(halfedges, 3 * tId + 1, 1);
RemoveHalfedge(halfedges, 3 * tId + 0, 2);
constrainedHalfedges.RemoveAt(3 * tId + 2);
constrainedHalfedges.RemoveAt(3 * tId + 1);
constrainedHalfedges.RemoveAt(3 * tId + 0);
Expand Down Expand Up @@ -3053,17 +3055,6 @@ private void ProcessBadTriangles(NativeList<int> heQueue, NativeList<int> tQueue
}
}

private void RemoveHalfedge(int he, int offset)
{
var ohe = halfedges[he];
var o = ohe > he ? ohe - offset : ohe;
if (o > -1)
{
halfedges[o] = -1;
}
halfedges.RemoveAt(he);
}

private void BuildNewTrianglesForStar(int pId, NativeList<int> heQueue, NativeList<int> tQueue)
{
// Build triangles/circles for inserted point pId.
Expand Down

0 comments on commit 8212ccf

Please sign in to comment.