fix: detect winding direction for correct part spacing offset

PolygonHelper.ExtractPerimeterPolygon always used OffsetSide.Right
assuming CCW winding, but DXF imports can produce CW winding. This
caused the spacing polygon to shrink inward instead of expanding
outward, making parts overlap during nesting.

Now detects winding direction via polygon signed area and selects
the correct OffsetSide accordingly.

Also adds save_nest MCP tool and a BOM-to-nest builder utility
(tools/NestBuilder) for batch-creating nest files from Excel BOMs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-23 21:57:23 -04:00
parent aeeb2e4074
commit 072915abf2
5 changed files with 299 additions and 2 deletions

View File

@@ -23,9 +23,17 @@ namespace OpenNest.Engine.BestFit
return new PolygonExtractionResult(null, Vector.Zero);
// Inflate by half-spacing if spacing is non-zero.
// OffsetSide.Right = outward for CCW perimeters (standard for outer contours).
// Detect winding direction to choose the correct outward offset side.
var outwardSide = OffsetSide.Right;
if (halfSpacing > 0)
{
var testPoly = perimeter.ToPolygon();
if (testPoly.Vertices.Count >= 3 && testPoly.RotationDirection() == RotationType.CW)
outwardSide = OffsetSide.Left;
}
var inflated = halfSpacing > 0
? (perimeter.OffsetEntity(halfSpacing, OffsetSide.Right) as Shape ?? perimeter)
? (perimeter.OffsetEntity(halfSpacing, outwardSide) as Shape ?? perimeter)
: perimeter;
// Convert to polygon with circumscribed arcs for tight nesting.