mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-27 18:31:34 -05:00
fix: track tool position through sub-programs in ConvertMode
ConvertMode.ToIncremental skipped SubProgramCall codes entirely when computing deltas, so parent motions after a sub-call were encoded as if the tool never moved. Several traversal sites (ConvertProgram, GraphicsHelper, PlateRenderer, CutDirectionArrows, Program.BoundingBox) worked around this with save/restore hacks that treated sub-calls as transparent — but DrawRapids legitimately tracks actual tool position, so after the last hole the first perimeter rapid was applied to the wrong base, drifting the rendered perimeter past the plate edge by roughly the distance to the last hole. Fix the root cause: ToIncremental and ToAbsolute now walk sub-programs to compute where they leave the tool, and advance pos accordingly. The other traversals capture a frameOrigin at entry and compute sub-call placement as frameOrigin + Offset, letting pos advance naturally through the sub recursion. All the save/restore workarounds are removed. Program.BoundingBox also picks up the same frame-origin treatment, which corrects a latent bug where absolute-mode endpoints and nested sub-calls dropped the parent's frame origin. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
a6c2235647
commit
572fa06a21
6 files changed
+127
-97
No files matched your search
@@ -98,6 +98,9 @@ namespace OpenNest
|
||||
private static void AddProgramSplit(GraphicsPath cutPath, GraphicsPath leadPath,
|
||||
Program pgm, Mode mode, ref Vector curpos)
|
||||
{
|
||||
// Capture the frame origin at entry. Sub-program Offsets are relative
|
||||
// to this fixed origin, not to the current tool position.
|
||||
var frameOrigin = curpos;
|
||||
mode = pgm.Mode;
|
||||
|
||||
for (var i = 0; i < pgm.Length; ++i)
|
||||
@@ -147,10 +150,8 @@ namespace OpenNest
|
||||
{
|
||||
cutPath.StartFigure();
|
||||
leadPath.StartFigure();
|
||||
var savedPos = curpos;
|
||||
curpos = new Vector(savedPos.X + subpgm.Offset.X, savedPos.Y + subpgm.Offset.Y);
|
||||
curpos = new Vector(frameOrigin.X + subpgm.Offset.X, frameOrigin.Y + subpgm.Offset.Y);
|
||||
AddProgramSplit(cutPath, leadPath, subpgm.Program, mode, ref curpos);
|
||||
curpos = savedPos;
|
||||
}
|
||||
mode = tmpmode;
|
||||
break;
|
||||
@@ -240,6 +241,9 @@ namespace OpenNest
|
||||
|
||||
private static void AddProgram(GraphicsPath path, Program pgm, Mode mode, ref Vector curpos)
|
||||
{
|
||||
// Capture the frame origin at entry. Sub-program Offsets are relative
|
||||
// to this fixed origin, not to the current tool position.
|
||||
var frameOrigin = curpos;
|
||||
mode = pgm.Mode;
|
||||
GraphicsPath currentFigure = null;
|
||||
|
||||
@@ -308,10 +312,8 @@ namespace OpenNest
|
||||
|
||||
if (subpgm.Program != null)
|
||||
{
|
||||
var savedPos = curpos;
|
||||
curpos = new Vector(savedPos.X + subpgm.Offset.X, savedPos.Y + subpgm.Offset.Y);
|
||||
curpos = new Vector(frameOrigin.X + subpgm.Offset.X, frameOrigin.Y + subpgm.Offset.Y);
|
||||
AddProgram(path, subpgm.Program, mode, ref curpos);
|
||||
curpos = savedPos;
|
||||
}
|
||||
|
||||
mode = tmpmode;
|
||||
|
||||
Reference in new issue
Block a user