Skip to content

Commit

Permalink
refactor: small constrain step cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
andywiecko committed Jan 30, 2025
1 parent 53685db commit 9af9dc8
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions Runtime/Triangulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2724,16 +2724,16 @@ public void Execute(Allocator allocator)
inputConstraintEdges[2 * index + 1]
);
c = c.x < c.y ? c.xy : c.yx; // Backward compatibility. To remove in the future.
TryApplyConstraint(c, index);
TryApplyConstraint(c, ignoreForPlantingSeeds: ignoreConstraintForPlantingSeeds.IsCreated && ignoreConstraintForPlantingSeeds[index]);
}
}

private void TryApplyConstraint(int2 c, int index)
private void TryApplyConstraint(int2 c, bool ignoreForPlantingSeeds)
{
intersections.Clear();
unresolvedIntersections.Clear();

CollectIntersections(c, index);
CollectIntersections(c, ignoreForPlantingSeeds);

var iter = 0;
do
Expand All @@ -2744,11 +2744,11 @@ private void TryApplyConstraint(int2 c, int index)
}

(intersections, unresolvedIntersections) = (unresolvedIntersections, intersections);
TryResolveIntersections(c, index, ref iter);
TryResolveIntersections(c, ignoreForPlantingSeeds, ref iter);
} while (!unresolvedIntersections.IsEmpty);
}

private void TryResolveIntersections(int2 c, int index, ref int iter)
private void TryResolveIntersections(int2 c, bool ignoreForPlantingSeeds, ref int iter)
{
for (int i = 0; i < intersections.Length; i++)
{
Expand Down Expand Up @@ -2847,8 +2847,8 @@ private void TryResolveIntersections(int2 c, int index, ref int iter)
{
constrainedHalfedges[h2] = true;
constrainedHalfedges[h5] = true;
ignoredHalfedgesForPlantingSeeds[h2] = IsConstraintIgnoredForPlanting(index);
ignoredHalfedgesForPlantingSeeds[h5] = IsConstraintIgnoredForPlanting(index);
ignoredHalfedgesForPlantingSeeds[h2] = ignoreForPlantingSeeds;
ignoredHalfedgesForPlantingSeeds[h5] = ignoreForPlantingSeeds;
}
if (EdgeEdgeIntersection(c, swapped))
{
Expand All @@ -2859,8 +2859,6 @@ private void TryResolveIntersections(int2 c, int index, ref int iter)
intersections.Clear();
}

private bool IsConstraintIgnoredForPlanting(int index) => ignoreConstraintForPlantingSeeds.IsCreated && ignoreConstraintForPlantingSeeds[index];

/// <summary>
/// Replaces <paramref name="h0"/> with <paramref name="h1"/>.
/// </summary>
Expand All @@ -2886,7 +2884,7 @@ private bool EdgeEdgeIntersection(int2 e1, int2 e2)
return !(math.any(e1.xy == e2.xy | e1.xy == e2.yx)) && UnsafeTriangulator<T, T2, TBig, TTransform, TUtils>.EdgeEdgeIntersection(a0, a1, b0, b1);
}

private void CollectIntersections(int2 edge, int index)
private void CollectIntersections(int2 edge, bool ignoreForPlantingSeeds)
{
// 1. Check if h1 is cj
// 2. Check if h1-h2 intersects with ci-cj
Expand All @@ -2912,12 +2910,12 @@ private void CollectIntersections(int2 edge, int index)
if (triangles[h1] == cj)
{
constrainedHalfedges[h0] = true;
ignoredHalfedgesForPlantingSeeds[h0] = IsConstraintIgnoredForPlanting(index);
ignoredHalfedgesForPlantingSeeds[h0] = ignoreForPlantingSeeds;
var oh0 = halfedges[h0];
if (oh0 != -1)
{
constrainedHalfedges[oh0] = true;
ignoredHalfedgesForPlantingSeeds[oh0] = IsConstraintIgnoredForPlanting(index);
ignoredHalfedgesForPlantingSeeds[oh0] = ignoreForPlantingSeeds;
}
break;
}
Expand All @@ -2937,7 +2935,7 @@ private void CollectIntersections(int2 edge, int index)
if (triangles[h2] == cj)
{
constrainedHalfedges[h2] = true;
ignoredHalfedgesForPlantingSeeds[h2] = IsConstraintIgnoredForPlanting(index);
ignoredHalfedgesForPlantingSeeds[h2] = ignoreForPlantingSeeds;
}

// possible that triangles[h2] == cj, not need to check
Expand All @@ -2956,12 +2954,12 @@ private void CollectIntersections(int2 edge, int index)
if (triangles[h1] == cj)
{
constrainedHalfedges[h0] = true;
ignoredHalfedgesForPlantingSeeds[h0] = IsConstraintIgnoredForPlanting(index);
ignoredHalfedgesForPlantingSeeds[h0] = ignoreForPlantingSeeds;
var oh0 = halfedges[h0];
if (oh0 != -1)
{
constrainedHalfedges[oh0] = true;
ignoredHalfedgesForPlantingSeeds[oh0] = IsConstraintIgnoredForPlanting(index);
ignoredHalfedgesForPlantingSeeds[oh0] = ignoreForPlantingSeeds;
}
break;
}
Expand Down

0 comments on commit 9af9dc8

Please sign in to comment.