From a029bb2faf0b996fd0b8cfaecec9dee0d82474b1 Mon Sep 17 00:00:00 2001 From: andywiecko Date: Tue, 26 Sep 2023 18:51:13 +0200 Subject: [PATCH] refactor: extract halfedges list Move the allocation of `halfedges` from the job to `Triangulator`. This change is required to adapt other algorithms for the `halfedges` approach. --- Runtime/Triangulator.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Runtime/Triangulator.cs b/Runtime/Triangulator.cs index 86a42ff..0bbe8dc 100644 --- a/Runtime/Triangulator.cs +++ b/Runtime/Triangulator.cs @@ -222,6 +222,7 @@ public class OutputData private NativeList outputPositions; private NativeList outputTriangles; private NativeList triangles; + private NativeList halfedges; private NativeList circles; private NativeList trianglesToEdges; private NativeHashMap> edgesToTriangles; @@ -245,6 +246,7 @@ public Triangulator(int capacity, Allocator allocator) outputPositions = new(capacity, allocator); outputTriangles = new(6 * capacity, allocator); triangles = new(capacity, allocator); + halfedges = new(6 * capacity, allocator); circles = new(capacity, allocator); trianglesToEdges = new(capacity, allocator); edgesToTriangles = new(capacity, allocator); @@ -269,6 +271,7 @@ public void Dispose() outputPositions.Dispose(); outputTriangles.Dispose(); triangles.Dispose(); + halfedges.Dispose(); circles.Dispose(); trianglesToEdges.Dispose(); edgesToTriangles.Dispose(); @@ -743,6 +746,7 @@ private struct ClearDataJob : IJob private NativeList outputPositions; private NativeList outputTriangles; private NativeList triangles; + private NativeList halfedges; private NativeList circles; private NativeList trianglesToEdges; private NativeHashMap> edgesToTriangles; @@ -756,6 +760,7 @@ public ClearDataJob(Triangulator triangulator) outputPositions = triangulator.outputPositions; outputTriangles = triangulator.outputTriangles; triangles = triangulator.triangles; + halfedges = triangulator.halfedges; circles = triangulator.circles; trianglesToEdges = triangulator.trianglesToEdges; edgesToTriangles = triangulator.edgesToTriangles; @@ -774,6 +779,7 @@ public void Execute() outputPositions.Clear(); outputTriangles.Clear(); triangles.Clear(); + halfedges.Clear(); circles.Clear(); trianglesToEdges.Clear(); edgesToTriangles.Clear(); @@ -805,6 +811,7 @@ private struct DistComparer : IComparer private NativeArray inputPositions; private NativeList outputPositions; private NativeList trianglesRaw; + private NativeList halfedgesRaw; [NativeDisableContainerSafetyRestriction] private NativeArray positions; @@ -838,6 +845,7 @@ public DelaunayTriangulationJob(Triangulator triangulator) inputPositions = triangulator.Input.Positions; outputPositions = triangulator.outputPositions; trianglesRaw = triangulator.triangles; + halfedgesRaw = triangulator.halfedges; positions = default; ids = default; @@ -906,8 +914,8 @@ public void Execute() var maxTriangles = math.max(2 * n - 5, 0); trianglesRaw.Length = maxTriangles; triangles = trianglesRaw.AsArray().Reinterpret(3 * sizeof(int)); - - using var _halfedges = halfedges = new(3 * maxTriangles, Allocator.Temp); + halfedgesRaw.Length = 3 * maxTriangles; + halfedges = halfedgesRaw.AsArray(); hashSize = (int)math.ceil(math.sqrt(n)); using var _hullPrev = hullPrev = new(n, Allocator.Temp); @@ -1084,6 +1092,7 @@ public void Execute() } trianglesRaw.Length = trianglesLen / 3; + halfedgesRaw.Length = trianglesLen; } private int Legalize(int a)