"Length" is more natural than "height" for flat plate materials.
Renames the field on OpenNest.Geometry.Size, Box.Height property,
and all references across 38 files.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Rename SizeDto.Height to SizeDto.Length so the serialized JSON
uses "width"/"length" which is more natural for plate materials.
The core Size struct still uses Height internally.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace three separate XML metadata files (info, drawing-info,
plate-info) and per-plate G-code placement files with a single
nest.json inside the ZIP archive. Programs remain as G-code text
under a programs/ folder.
This eliminates ~400 lines of hand-written XML read/write code
and fragile ID-based dictionary linking. Now uses System.Text.Json
with DTO records for clean serialization. Also adds Priority and
Constraints fields to drawing serialization (previously omitted).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Console app for running the nesting engine from the command line.
Supports plate size/spacing overrides, quantity limits, overlap
checking with exit codes, and benchmark-friendly flags (--no-save,
--no-log). The MCP test_engine tool shells out to this project.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The push algorithm's copy distance formula (bboxDim - slideDistance)
produced distances smaller than the part width when inflated boundary
arc vertices interacted spuriously, causing ~0.05 unit overlaps between
all adjacent grid parts.
Two fixes applied:
- Clamp ComputeCopyDistance to bboxDim + PartSpacing minimum
- Use circumscribed polygons (R/cos(halfStep)) for PartBoundary arc
discretization so chord segments never cut inside the true arc,
eliminating the ChordTolerance offset workaround
Also parallelized three sequential fill loops using Parallel.ForEach:
- FindBestFill angle sweep (up to 38 angles x 2 directions)
- FillPattern angle sweep for group/pair fills
- FillRemainingStrip rotation loop
Added diagnostic logging to HasOverlaps, FindCopyDistance, and
FillRecursive for debugging fill issues.
Test result: 45 parts @ 79.6% -> 47 parts @ 83.1%, zero overlaps.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When the greedy maximum-row tiling leaves a thin remainder, tries removing
the last row and re-filling the larger strip. Picks whichever total is
higher. Fixes cases where e.g. 4 rows + 11 remainder = 47 beats 5 rows = 45.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The GPU pair evaluator reported false-positive overlaps for all
candidates because the bitmap coordinate system didn't account for
Part.CreateAtOrigin's Location offset. When rotation produced negative
coordinates, CreateAtOrigin sets Location = -bbox.Location (non-zero),
but the offset formula assumed Location was always (0,0).
Two fixes:
- Rasterize bitmaps from Part.CreateAtOrigin directly (new FromPart
method) instead of separately rotating polygons and computing bbox,
eliminating any Polygon.Rotate vs Program.Rotate mismatch
- Correct offset formula to include the Location shift:
(Part2Offset - partB.Location) instead of raw Part2Offset
Also optimized post-kernel bounding computation: pre-compute vertices
once per rotation group and process results with Parallel.For, matching
the CPU evaluator's concurrency.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Pre-size TilePattern result list from estimated copy count to avoid
resizing. Remove redundant Program.BoundingBox() call and UpdateBounds()
in MakeSeedPattern — the Part's BoundingBox is already correct.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
max(aUpper_i - bLower_j) across all pairs simplifies to
max(aUpper) - min(bLower), computed in a single pass.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
FindCopyDistance and FindPatternCopyDistance were cloning entire Parts
(including deep Program copies) just to get offset locations for
GetLines. Compute offset locations directly instead. Also skip the
Pattern wrapper in TilePattern — clone parts directly.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
RotationDirection and direction filtering were recomputed on every
GetLines call. Pre-compute edges per PushDirection once in the
constructor so GetLines only translates cached edges.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Part.Clone() re-clones from the drawing's unrotated program, re-rotates,
and walks all CNC codes twice for bounding box — 4 O(c) passes per clone.
CloneAtOffset clones from the already-rotated program and computes the
bounding box arithmetically, reducing to 1 O(c) pass per clone.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Opposite hull edges (180° apart) produce identical bounding rectangles
(width/height swapped), so only half the edges need to be checked to
find the minimum area. Applied to the unconstrained overload only.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add bounding box rejection in HasOverlaps to skip expensive
Part.Intersects (CNC→geometry conversion) for non-adjacent parts.
Eliminates ~35% CPU in IsBetterValidFill for grid layouts.
- Optimize RayEdgeDistance: access Line fields directly instead of
property getters (avoids Vector struct copies), inline IsEqualTo
with direct range comparison (avoids Math.Abs), and precompute
deltas for reuse in interpolation.
- Cache line endpoints in DirectionalDistance outer loop to avoid
repeated struct copies in the inner loop.
- Add fill timer to ActionClone.Fill, displayed in PlateView status
bar as "Fill: N parts in M ms".
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Test code and fixture data now live together in the OpenNest.Test repo
at git.thecozycat.net/aj/OpenNest.Test.git.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
After the main fill, detect if the last column/row is an "oddball"
with fewer parts than the main grid. If so, remove those parts and
re-fill the remainder strip independently using all strategies
(linear, rect best-fit, pairs). Improves 30→32 parts on the test
case (96x48 plate with 30x7.5 interlocking parts).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Documents both issues found (narrow pair selection, incomplete pattern tiling)
and their fixes with before/after results.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Narrow remnant strips now get more parts by:
- Sweeping rotations every 5° when the strip is narrower than the part
- Including all pairs that fit the strip width (not just top 50 by area)
- Placing individual parts from incomplete pattern copies that still fit
- Using finer polygon tolerance (0.01) for hull edge angle detection
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- F key triggers ZoomToFit; Ctrl+F passes through for ActionClone fill
- Middle-button double-click ZoomToFit skipped when parts are selected
to avoid conflicting with middle-click 90° rotation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace hardcoded PushChordTolerance constant with a configurable
OffsetTolerance property on PlateView (default 0.001), giving smoother
arc profiles in offset drawing and push-to-part collision detection.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The engine gets 7 parts where manual nesting gets 9, all at the same
rotation. The fix is trying more rotations across all fill strategies.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
MCP fill_remnants gets 7 parts vs UI Ctrl+F gets 9 in the same strip.
Documents root cause analysis and files to investigate.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add OpenNest.IO class library and OpenNest.Mcp server for Claude Code
integration. Extract IO classes from WinForms project, add
Plate.GetRemnants(), and expose 12 MCP tools for loading nests,
running nesting algorithms, and inspecting results.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Without this attribute, WithToolsFromAssembly does not discover
the tool methods and the server reports no tools capability.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move DxfImporter, DxfExporter, NestReader, NestWriter, ProgramReader,
and Extensions into a new OpenNest.IO class library. The WinForms project
now references OpenNest.IO instead of ACadSharp directly.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract MakeSeedPattern for shared part creation, and replace the
two-step primary/perpendicular tiling with a single FillRecursive
method that tiles along one axis then recurses perpendicular.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The GPU bitmap evaluator produces false overlap detections due to
discretization errors at cell boundaries. Use the CPU PairEvaluator
(exact geometric intersection) for now. Also remove the double-counted
spacing dilation from GpuPairEvaluator for when GPU is revisited.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add PushDirection.Right and PushDirection.Up to RotationSlideStrategy so
parts can approach from all four directions. This discovers concave
interlocking arrangements (e.g. L-shaped parts nesting into each other's
cavities) that the original Left/Down-only slides could never reach.
Introduce BestFitCache so best-fit results are computed once at step size
0.25 and shared between the viewer and nesting engine. The GPU evaluator
factory is configured once at startup instead of being wired per call
site, and NestEngine.CreateEvaluator is removed.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extract offset polygon computation into PartBoundary, which builds
and caches inflated boundary polygons per unique part geometry.
FillLinear now uses symmetric half-spacing and reuses boundaries
across tiling passes, avoiding redundant offset calculations.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>