Skip to content

Commit

Permalink
refactor: refinement internal methods (2)
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 8212ccf commit 3f344bb
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions Runtime/Triangulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2701,6 +2701,7 @@ private void SplitEdge(int he, NativeList<int> heQueue, NativeList<int> tQueue)
if (halfedges[he] != -1)
{
UnsafeInsertPointBulk(p, initTriangle: he / 3, heQueue, tQueue);
ProcessPathHalfedgesForEnqueueing(heQueue, tQueue, boundary: false);

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

//var h0 = triangles.Length - 3;
var id = 3 * (pathPoints.Length - 1);
Expand Down Expand Up @@ -2804,6 +2806,7 @@ private void SplitTriangle(int tId, NativeList<int> heQueue, NativeList<int> tQu
if (edges.IsEmpty)
{
UnsafeInsertPointBulk(c.Center, initTriangle: tId, heQueue, tQueue);
ProcessPathHalfedgesForEnqueueing(heQueue, tQueue, boundary: false);
}
else
{
Expand Down Expand Up @@ -2861,15 +2864,15 @@ private void UnsafeInsertPointBulk(T2 p, int initTriangle, NativeList<int> heQue
var pId = UnsafeInsertPointCommon(p, initTriangle);
BuildStarPolygon();
ProcessBadTriangles(heQueue, tQueue);
BuildNewTrianglesForStar(pId, heQueue, tQueue);
BuildNewTrianglesForStar(pId);
}

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

private void RecalculateBadTriangles(T2 p)
Expand Down Expand Up @@ -3055,7 +3058,7 @@ static void RemoveHalfedge(NativeList<int> halfedges, int he, int offset)
}
}

private void BuildNewTrianglesForStar(int pId, NativeList<int> heQueue, NativeList<int> tQueue)
private void BuildNewTrianglesForStar(int pId)
{
// Build triangles/circles for inserted point pId.
var initTriangles = triangles.Length;
Expand Down Expand Up @@ -3106,25 +3109,9 @@ private void BuildNewTrianglesForStar(int pId, NativeList<int> heQueue, NativeLi
}
halfedges[heOffset] = heOffset + 3 * (pathPoints.Length - 1) + 2;
halfedges[heOffset + 3 * (pathPoints.Length - 1) + 2] = heOffset;

if (heQueue.IsCreated)
{
for (int i = 0; i < pathPoints.Length; i++)
{
var he = heOffset + 3 * i + 1;
if (constrainedHalfedges[he] && IsEncroached(he))
{
heQueue.Add(he);
}
else if (tQueue.IsCreated && IsBadTriangle(he / 3))
{
tQueue.Add(he / 3);
}
}
}
}

private void BuildNewTrianglesForAmphitheater(int pId, NativeList<int> heQueue, NativeList<int> tQueue)
private void BuildNewTrianglesForAmphitheater(int pId)
{
// Build triangles/circles for inserted point pId.
var initTriangles = triangles.Length;
Expand Down Expand Up @@ -3172,10 +3159,16 @@ private void BuildNewTrianglesForAmphitheater(int pId, NativeList<int> heQueue,
}
halfedges[heOffset] = -1;
halfedges[heOffset + 3 * (pathPoints.Length - 2) + 2] = -1;
}

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

if (heQueue.IsCreated)
{
for (int i = 0; i < pathPoints.Length - 1; i++)
for (int i = 0; i < iters; i++)
{
var he = heOffset + 3 * i + 1;
if (constrainedHalfedges[he] && IsEncroached(he))
Expand Down

0 comments on commit 3f344bb

Please sign in to comment.