From ab8c6127dd16fef7a0b627e6b04b6bf06d5010b3 Mon Sep 17 00:00:00 2001 From: andywiecko Date: Tue, 7 Nov 2023 18:55:43 +0100 Subject: [PATCH] refactor: misc refinement cleanup --- Runtime/Triangulator.cs | 62 ++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/Runtime/Triangulator.cs b/Runtime/Triangulator.cs index 11e924d..e0c742b 100644 --- a/Runtime/Triangulator.cs +++ b/Runtime/Triangulator.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; using Unity.Burst; @@ -1894,7 +1895,9 @@ private int UnsafeInsertPoint(float2 p, int initTriangle, NativeList heQueu visitedTriangles[initTriangle] = true; RecalculateBadTriangles(p); + BuildStarPolygon(); ProcessBadTriangles(pId, heQueue, tQueue); + BuildNewTriangles(pId, heQueue, tQueue); return pId; } @@ -1938,9 +1941,9 @@ private void VisitEdge(float2 p, int t0, int t1) } } - private void ProcessBadTriangles(int pId, NativeList heQueue, NativeList tQueue) + private void BuildStarPolygon() { - // 1. Find the "first" halfedge of the polygon. + // Find the "first" halfedge of the polygon. var initHe = -1; for (int i = 0; i < badTriangles.Length; i++) { @@ -1963,7 +1966,7 @@ private void ProcessBadTriangles(int pId, NativeList heQueue, NativeList heQueue, NativeList heQueue, NativeList tQueue) + { + // Remove bad triangles and recalculate polygon path halfedges. badTriangles.Sort(); for (int t = badTriangles.Length - 1; t >= 0; t--) { @@ -2048,12 +2054,25 @@ private void ProcessBadTriangles(int pId, NativeList heQueue, NativeList he ? ohe - offset : ohe; + if (o > -1) + { + halfedges[o] = -1; + } + halfedges.RemoveAt(he); + } + + private void BuildNewTriangles(int pId, NativeList heQueue, NativeList tQueue) + { + // Build triangles/circles for inserted point pId. var initTriangles = triangles.Length; triangles.Length += 3 * pathPoints.Length; circles.Length += pathPoints.Length; - for (int i = 0; i < pathPoints.Length - 1; i++) { triangles[initTriangles + 3 * i + 0] = pId; @@ -2066,6 +2085,7 @@ private void ProcessBadTriangles(int pId, NativeList heQueue, NativeList heQueue, NativeList heQueue, NativeList heQueue, NativeList he ? ohe - offset : ohe; - if (o > -1) - { - halfedges[o] = -1; - } - halfedges.RemoveAt(he); - } } private interface IPlantingSeedJobMode