feat: add Offset property to SubProgramCall for hole positioning
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using OpenNest.Math;
|
||||
using OpenNest.Geometry;
|
||||
using OpenNest.Math;
|
||||
|
||||
namespace OpenNest.CNC
|
||||
{
|
||||
@@ -35,6 +36,12 @@ namespace OpenNest.CNC
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the offset (position) at which the sub-program is executed.
|
||||
/// For hole sub-programs, this is the hole center.
|
||||
/// </summary>
|
||||
public Vector Offset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the rotation of the program in degrees.
|
||||
/// </summary>
|
||||
@@ -78,11 +85,13 @@ namespace OpenNest.CNC
|
||||
/// <returns></returns>
|
||||
public ICode Clone()
|
||||
{
|
||||
return new SubProgramCall(program, Rotation);
|
||||
return new SubProgramCall(program, Rotation) { Id = Id, Offset = Offset };
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (Offset.X != 0 || Offset.Y != 0)
|
||||
return string.Format("G65 P{0} X{1} Y{2}", Id, Offset.X, Offset.Y);
|
||||
return string.Format("G65 P{0} R{1}", Id, Rotation);
|
||||
}
|
||||
}
|
||||
|
||||
43
OpenNest.Tests/CuttingStrategy/HoleSubProgramTests.cs
Normal file
43
OpenNest.Tests/CuttingStrategy/HoleSubProgramTests.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using OpenNest.CNC;
|
||||
using OpenNest.Geometry;
|
||||
|
||||
namespace OpenNest.Tests.CuttingStrategy;
|
||||
|
||||
public class HoleSubProgramTests
|
||||
{
|
||||
[Fact]
|
||||
public void SubProgramCall_Offset_DefaultsToZero()
|
||||
{
|
||||
var call = new SubProgramCall();
|
||||
Assert.Equal(0, call.Offset.X);
|
||||
Assert.Equal(0, call.Offset.Y);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SubProgramCall_Offset_StoresValue()
|
||||
{
|
||||
var call = new SubProgramCall { Offset = new Vector(1.5, 2.5) };
|
||||
Assert.Equal(1.5, call.Offset.X);
|
||||
Assert.Equal(2.5, call.Offset.Y);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SubProgramCall_Clone_CopiesOffset()
|
||||
{
|
||||
var call = new SubProgramCall { Id = 1, Offset = new Vector(3, 4) };
|
||||
var clone = (SubProgramCall)call.Clone();
|
||||
Assert.Equal(3, clone.Offset.X);
|
||||
Assert.Equal(4, clone.Offset.Y);
|
||||
Assert.Equal(1, clone.Id);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SubProgramCall_ToString_IncludesOffset()
|
||||
{
|
||||
var call = new SubProgramCall { Id = 1000, Offset = new Vector(1.5, 2.5) };
|
||||
var str = call.ToString();
|
||||
Assert.Contains("P1000", str);
|
||||
Assert.Contains("X1.5", str);
|
||||
Assert.Contains("Y2.5", str);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user