Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: refinement internal methods (3) #273

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading