Skip to content

Commit

Permalink
refactor: refinement internal methods (3)
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 15, 2024
1 parent 3f344bb commit d071913
Showing 1 changed file with 55 additions and 46 deletions.
101 changes: 55 additions & 46 deletions Runtime/Triangulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2700,7 +2700,8 @@ private void SplitEdge(int he, NativeList<int> heQueue, NativeList<int> tQueue)

if (halfedges[he] != -1)
{
UnsafeInsertPointBulk(p, initTriangle: he / 3, heQueue, tQueue);
UnsafeInsertPointBulk(p, initTriangle: he / 3);
AdaptQueues(heQueue, tQueue);
ProcessPathHalfedgesForEnqueueing(heQueue, tQueue, boundary: false);

var h0 = triangles.Length - 3;
Expand Down Expand Up @@ -2748,7 +2749,8 @@ private void SplitEdge(int he, NativeList<int> heQueue, NativeList<int> tQueue)
}
else
{
UnsafeInsertPointBoundary(p, initHe: he, heQueue, tQueue);
UnsafeInsertPointBoundary(p, initHe: he);
AdaptQueues(heQueue, tQueue);
ProcessPathHalfedgesForEnqueueing(heQueue, tQueue, boundary: true);

//var h0 = triangles.Length - 3;
Expand Down Expand Up @@ -2805,7 +2807,8 @@ private void SplitTriangle(int tId, NativeList<int> heQueue, NativeList<int> tQu

if (edges.IsEmpty)
{
UnsafeInsertPointBulk(c.Center, initTriangle: tId, heQueue, tQueue);
UnsafeInsertPointBulk(c.Center, initTriangle: tId);
AdaptQueues(heQueue, tQueue);
ProcessPathHalfedgesForEnqueueing(heQueue, tQueue, boundary: false);
}
else
Expand Down Expand Up @@ -2859,19 +2862,19 @@ private int UnsafeInsertPointCommon(T2 p, int initTriangle)
return pId;
}

private void UnsafeInsertPointBulk(T2 p, int initTriangle, NativeList<int> heQueue = default, NativeList<int> tQueue = default)
private void UnsafeInsertPointBulk(T2 p, int initTriangle)
{
var pId = UnsafeInsertPointCommon(p, initTriangle);
BuildStarPolygon();
ProcessBadTriangles(heQueue, tQueue);
ProcessBadTriangles();
BuildNewTrianglesForStar(pId);
}

private void UnsafeInsertPointBoundary(T2 p, int initHe, NativeList<int> heQueue = default, NativeList<int> tQueue = default)
private void UnsafeInsertPointBoundary(T2 p, int initHe)
{
var pId = UnsafeInsertPointCommon(p, initHe / 3);
BuildAmphitheaterPolygon(initHe);
ProcessBadTriangles(heQueue, tQueue);
ProcessBadTriangles();
BuildNewTrianglesForAmphitheater(pId);
}

Expand Down Expand Up @@ -2971,7 +2974,7 @@ private void BuildStarPolygon()
}
}

private void ProcessBadTriangles(NativeList<int> heQueue, NativeList<int> tQueue)
private void ProcessBadTriangles()
{
static void RemoveHalfedge(NativeList<int> halfedges, int he, int offset)
{
Expand Down Expand Up @@ -3017,44 +3020,6 @@ static void RemoveHalfedge(NativeList<int> halfedges, int he, int offset)
pathHalfedges[i] -= 3;
}
}

// Adapt he queue
if (heQueue.IsCreated)
{
for (int i = 0; i < heQueue.Length; i++)
{
var he = heQueue[i];
if (he == 3 * tId + 0 || he == 3 * tId + 1 || he == 3 * tId + 2)
{
heQueue[i] = -1;
continue;
}

if (he > 3 * tId + 2)
{
heQueue[i] -= 3;
}
}
}

// Adapt t queue
if (tQueue.IsCreated)
{
for (int i = 0; i < tQueue.Length; i++)
{
var q = tQueue[i];
if (q == tId)
{
tQueue[i] = -1;
continue;
}

if (q > tId)
{
tQueue[i]--;
}
}
}
}
}

Expand Down Expand Up @@ -3161,6 +3126,50 @@ private void BuildNewTrianglesForAmphitheater(int pId)
halfedges[heOffset + 3 * (pathPoints.Length - 2) + 2] = -1;
}

private void AdaptQueues(NativeList<int> heQueue, NativeList<int> tQueue)
{
for (int t = badTriangles.Length - 1; t >= 0; t--)
{
var tId = badTriangles[t];

if (heQueue.IsCreated)
{
for (int i = 0; i < heQueue.Length; i++)
{
var he = heQueue[i];
if (he == 3 * tId + 0 || he == 3 * tId + 1 || he == 3 * tId + 2)
{
heQueue[i] = -1;
continue;
}

if (he > 3 * tId + 2)
{
heQueue[i] -= 3;
}
}
}

if (tQueue.IsCreated)
{
for (int i = 0; i < tQueue.Length; i++)
{
var q = tQueue[i];
if (q == tId)
{
tQueue[i] = -1;
continue;
}

if (q > tId)
{
tQueue[i]--;
}
}
}
}
}

private void ProcessPathHalfedgesForEnqueueing(NativeList<int> heQueue, NativeList<int> tQueue, bool boundary)
{
var iters = boundary ? pathPoints.Length - 1 : pathPoints.Length;
Expand Down

0 comments on commit d071913

Please sign in to comment.