From 3f344bb14cc673ff64443dc9f041beb44bbee213 Mon Sep 17 00:00:00 2001 From: andywiecko Date: Tue, 15 Oct 2024 17:15:22 +0200 Subject: [PATCH] refactor: refinement internal methods (2) This refactor is part of a series of changes preparing for the introduction of a dynamic point insertion utility. --- Runtime/Triangulator.cs | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/Runtime/Triangulator.cs b/Runtime/Triangulator.cs index 327c963..0264a32 100644 --- a/Runtime/Triangulator.cs +++ b/Runtime/Triangulator.cs @@ -2701,6 +2701,7 @@ private void SplitEdge(int he, NativeList heQueue, NativeList 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; @@ -2748,6 +2749,7 @@ private void SplitEdge(int he, NativeList heQueue, NativeList tQueue) else { UnsafeInsertPointBoundary(p, initHe: he, heQueue, tQueue); + ProcessPathHalfedgesForEnqueueing(heQueue, tQueue, boundary: true); //var h0 = triangles.Length - 3; var id = 3 * (pathPoints.Length - 1); @@ -2804,6 +2806,7 @@ private void SplitTriangle(int tId, NativeList heQueue, NativeList tQu if (edges.IsEmpty) { UnsafeInsertPointBulk(c.Center, initTriangle: tId, heQueue, tQueue); + ProcessPathHalfedgesForEnqueueing(heQueue, tQueue, boundary: false); } else { @@ -2861,7 +2864,7 @@ private void UnsafeInsertPointBulk(T2 p, int initTriangle, NativeList heQue var pId = UnsafeInsertPointCommon(p, initTriangle); BuildStarPolygon(); ProcessBadTriangles(heQueue, tQueue); - BuildNewTrianglesForStar(pId, heQueue, tQueue); + BuildNewTrianglesForStar(pId); } private void UnsafeInsertPointBoundary(T2 p, int initHe, NativeList heQueue = default, NativeList tQueue = default) @@ -2869,7 +2872,7 @@ private void UnsafeInsertPointBoundary(T2 p, int initHe, NativeList heQueue var pId = UnsafeInsertPointCommon(p, initHe / 3); BuildAmphitheaterPolygon(initHe); ProcessBadTriangles(heQueue, tQueue); - BuildNewTrianglesForAmphitheater(pId, heQueue, tQueue); + BuildNewTrianglesForAmphitheater(pId); } private void RecalculateBadTriangles(T2 p) @@ -3055,7 +3058,7 @@ static void RemoveHalfedge(NativeList halfedges, int he, int offset) } } - private void BuildNewTrianglesForStar(int pId, NativeList heQueue, NativeList tQueue) + private void BuildNewTrianglesForStar(int pId) { // Build triangles/circles for inserted point pId. var initTriangles = triangles.Length; @@ -3106,25 +3109,9 @@ private void BuildNewTrianglesForStar(int pId, NativeList 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 heQueue, NativeList tQueue) + private void BuildNewTrianglesForAmphitheater(int pId) { // Build triangles/circles for inserted point pId. var initTriangles = triangles.Length; @@ -3172,10 +3159,16 @@ private void BuildNewTrianglesForAmphitheater(int pId, NativeList heQueue, } halfedges[heOffset] = -1; halfedges[heOffset + 3 * (pathPoints.Length - 2) + 2] = -1; + } + + private void ProcessPathHalfedgesForEnqueueing(NativeList heQueue, NativeList 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))