mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-27 02:41:06 -04:00
perf(geometry): flatten Shape.ToPolygon by chord tolerance by default
ToPolygon() used 1000 segments for every arc and circle regardless of size: no more accurate for large arcs and needlessly dense for small ones, which made every Drawing area and canonical-angle computation on an arc-heavy part handle hundreds of thousands of vertices. The parameterless overload now delegates to ToPolygonWithTolerance with DefaultChordTolerance = 0.0001. That is ten times tighter than the spacing and overlap checks' 0.001 because callers use this polygon for area, which an inscribed polygon always under-reads: at 0.001, seven area-sensitive cut-off, splitter and circle-packing tests drifted past their precision; at 0.0001 all pass. ToPolygon(int) keeps the fixed segment count for any caller that wants it. With the one-pass Cleanup, a 300-nest PEP archive import on the forge server went from 46.1 s to 15.5 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9ab6fbbeaf
commit
0eb6d5886a
2 files changed
+19
-5
No files matched your search
@@ -264,10 +264,24 @@ namespace OpenNest.Geometry
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts the shape to a polygon.
|
||||
/// Maximum chord error, in drawing units, when <see cref="ToPolygon()"/> flattens arcs
|
||||
/// and circles. Ten times tighter than the spacing/overlap checks' 0.001 because callers
|
||||
/// use this polygon for area, and an inscribed polygon always reads low.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Polygon ToPolygon(int arcSegments = 1000)
|
||||
public const double DefaultChordTolerance = 0.0001;
|
||||
|
||||
/// <summary>
|
||||
/// Converts the shape to a polygon, flattening arcs to within
|
||||
/// <see cref="DefaultChordTolerance"/>. A fixed segment count per arc (formerly 1000)
|
||||
/// made large arcs no more accurate and small ones needlessly dense: arc-heavy drawings
|
||||
/// produced hundreds of thousands of vertices every time their area was computed.
|
||||
/// </summary>
|
||||
public Polygon ToPolygon() => ToPolygonWithTolerance(DefaultChordTolerance);
|
||||
|
||||
/// <summary>
|
||||
/// Converts the shape to a polygon with a fixed number of segments per arc and circle.
|
||||
/// </summary>
|
||||
public Polygon ToPolygon(int arcSegments)
|
||||
{
|
||||
var polygon = new Polygon();
|
||||
|
||||
|
||||
@@ -64,8 +64,8 @@ namespace OpenNest.Geometry
|
||||
public static SpacingOutline Build(ShapeProfile profile, Vector location, double inflateBy)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(profile);
|
||||
// Adaptive tolerance instead of Shape.ToPolygon()'s default (up to 1000 segments per
|
||||
// arc): arc-heavy real parts otherwise produce thousands of vertices.
|
||||
// Flatten by chord tolerance, not a fixed segment count: arc-heavy real parts
|
||||
// otherwise produce thousands of vertices.
|
||||
var region = ClipperBridge.OffsetForValidation(
|
||||
profile,
|
||||
inflateBy > Tolerance.Epsilon ? inflateBy : 0,
|
||||
|
||||
Reference in new issue
Block a user