perf(core): optimize geometry with edge pruning and vertex dedup
Vector implements IEquatable<Vector> with proper GetHashCode for HashSet usage. Polygon.FindCrossing uses bounding-box pruning to skip non-overlapping edge pairs. Helper.DirectionalDistance deduplicates vertices via HashSet, sorts edges for early-exit pruning, and adds a new array-based overload that avoids allocations. PartBoundary sorts directional edges and exposes GetEdges for zero-alloc access. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -93,10 +93,10 @@ namespace OpenNest
|
||||
}
|
||||
}
|
||||
|
||||
leftEdges = left.ToArray();
|
||||
rightEdges = right.ToArray();
|
||||
upEdges = up.ToArray();
|
||||
downEdges = down.ToArray();
|
||||
leftEdges = left.OrderBy(e => System.Math.Min(e.Item1.Y, e.Item2.Y)).ToArray();
|
||||
rightEdges = right.OrderBy(e => System.Math.Min(e.Item1.Y, e.Item2.Y)).ToArray();
|
||||
upEdges = up.OrderBy(e => System.Math.Min(e.Item1.X, e.Item2.X)).ToArray();
|
||||
downEdges = down.OrderBy(e => System.Math.Min(e.Item1.X, e.Item2.X)).ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -152,5 +152,14 @@ namespace OpenNest
|
||||
default: return _leftEdges;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the pre-computed edge arrays for the given direction.
|
||||
/// These are in part-local coordinates (no translation applied).
|
||||
/// </summary>
|
||||
public (Vector start, Vector end)[] GetEdges(PushDirection direction)
|
||||
{
|
||||
return GetDirectionalEdges(direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user