Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove edges to triangles mapping #70

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading