fix(core): read an absolute program's end point from its last code

Program.EndPoint started its backward search at Codes.Count, one past the
last code, so every absolute-mode program threw an
ArgumentOutOfRangeException, including through Timing.GetTimingInfo for
cut-time estimates. Start at Count - 1; an empty program still returns
the origin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Opus 5.5 committed 2026-11-30 20:13:30 -05:00
1 parent ebd0d4d9a9
commit 59f5a32754
2 files changed
+37 -1

No files matched your search

+1 -1
View File
@@ -255,7 +255,7 @@ namespace OpenNest.CNC
{
case Mode.Absolute:
{
for (int i = Codes.Count; i >= 0; --i)
for (int i = Codes.Count - 1; i >= 0; --i)
{
var code = Codes[i];
var motion = code as Motion;
@@ -0,0 +1,36 @@
using OpenNest.CNC;
using OpenNest.Geometry;
namespace OpenNest.Tests.CNC;
public class ProgramEndPointTests
{
[Fact]
public void Absolute_ReturnsTheLastMotionsEndPoint()
{
var program = new Program(Mode.Absolute);
program.MoveTo(1, 1);
program.LineTo(4, 5);
program.LineTo(7, 2);
Assert.Equal(new Vector(7, 2), program.EndPoint());
}
[Fact]
public void Absolute_Empty_ReturnsTheOrigin()
{
var program = new Program(Mode.Absolute);
Assert.Equal(new Vector(0, 0), program.EndPoint());
}
[Fact]
public void Incremental_SumsTheMotions()
{
var program = new Program(Mode.Incremental);
program.MoveTo(1, 1);
program.LineTo(3, 4);
Assert.Equal(new Vector(4, 5), program.EndPoint());
}
}