Skip to content

Commit

Permalink
refactor: remove edges to triangles mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
andywiecko committed Oct 16, 2023
1 parent 88b78bc commit 65e8c68
Showing 1 changed file with 1 addition and 34 deletions.
35 changes: 1 addition & 34 deletions Runtime/Triangulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ public class OutputData
private NativeList<Triangle> triangles;
private NativeList<int> halfedges;
private NativeList<Circle> circles;
private NativeHashMap<Edge, FixedList32Bytes<int>> edgesToTriangles;
private NativeList<Edge> constraintEdges;
private NativeReference<Status> status;

Expand All @@ -217,7 +216,6 @@ public Triangulator(int capacity, Allocator allocator)
triangles = new(capacity, allocator);
halfedges = new(6 * capacity, allocator);
circles = new(capacity, allocator);
edgesToTriangles = new(capacity, allocator);
constraintEdges = new(capacity, allocator);
status = new(Status.OK, allocator);

Expand All @@ -242,7 +240,6 @@ public void Dispose()
triangles.Dispose();
halfedges.Dispose();
circles.Dispose();
edgesToTriangles.Dispose();
constraintEdges.Dispose();
status.Dispose();

Expand Down Expand Up @@ -717,7 +714,6 @@ private struct ClearDataJob : IJob
private NativeList<Triangle> triangles;
private NativeList<int> halfedges;
private NativeList<Circle> circles;
private NativeHashMap<Edge, FixedList32Bytes<int>> edgesToTriangles;
private NativeList<Edge> constraintEdges;
private NativeList<int> pointsToRemove;
private NativeList<int> pointsOffset;
Expand All @@ -730,7 +726,6 @@ public ClearDataJob(Triangulator triangulator)
triangles = triangulator.triangles;
halfedges = triangulator.halfedges;
circles = triangulator.circles;
edgesToTriangles = triangulator.edgesToTriangles;
constraintEdges = triangulator.constraintEdges;
pointsToRemove = triangulator.pointsToRemove;
pointsOffset = triangulator.pointsOffset;
Expand All @@ -748,7 +743,6 @@ public void Execute()
triangles.Clear();
halfedges.Clear();
circles.Clear();
edgesToTriangles.Clear();
constraintEdges.Clear();

pointsToRemove.Clear();
Expand Down Expand Up @@ -1160,49 +1154,22 @@ private struct RecalculateTriangleMappingsJob : IJob
{
[ReadOnly]
private NativeArray<Triangle> triangles;
private NativeHashMap<Edge, FixedList32Bytes<int>> edgesToTriangles;
private NativeList<Circle> circles;
private NativeList<float2> positions;

public RecalculateTriangleMappingsJob(Triangulator triangulator)
{
triangles = triangulator.triangles.AsDeferredJobArray();
edgesToTriangles = triangulator.edgesToTriangles;
circles = triangulator.circles;
positions = triangulator.outputPositions;
}

public void Execute()
{
circles.Length = triangles.Length;
edgesToTriangles.Clear();
for (int i = 0; i < triangles.Length; i++)
{
Execute(i);
}
}

private void Execute(int t)
{
var (i, j, k) = triangles[t];

circles[t] = CalculateCircumCircle((i, j, k), positions.AsArray());

RegisterEdgeData((i, j), t);
RegisterEdgeData((j, k), t);
RegisterEdgeData((k, i), t);
}

private void RegisterEdgeData(Edge edge, int triangleId)
{
if (edgesToTriangles.TryGetValue(edge, out var tris))
{
tris.Add(triangleId);
edgesToTriangles[edge] = tris;
}
else
{
edgesToTriangles.Add(edge, new() { triangleId });
circles[i] = CalculateCircumCircle(triangles[i], positions.AsArray());
}
}
}
Expand Down

0 comments on commit 65e8c68

Please sign in to comment.