feat: add Bend domain model and BendDirection enum to OpenNest.Core
Introduces OpenNest.Core/Bending/ with Bend and BendDirection types as the foundation for bend line detection. Includes 6 passing unit tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
37
OpenNest.Core/Bending/Bend.cs
Normal file
37
OpenNest.Core/Bending/Bend.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using OpenNest.Geometry;
|
||||
using OpenNest.Math;
|
||||
|
||||
namespace OpenNest.Bending
|
||||
{
|
||||
public class Bend
|
||||
{
|
||||
public Vector StartPoint { get; set; }
|
||||
public Vector EndPoint { get; set; }
|
||||
public BendDirection Direction { get; set; }
|
||||
public double? Angle { get; set; }
|
||||
public double? Radius { get; set; }
|
||||
public string NoteText { get; set; }
|
||||
|
||||
public double Length => StartPoint.DistanceTo(EndPoint);
|
||||
|
||||
public double AngleRadians => Angle.HasValue
|
||||
? OpenNest.Math.Angle.ToRadians(Angle.Value)
|
||||
: 0;
|
||||
|
||||
public Line ToLine() => new Line(StartPoint, EndPoint);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the angle of the bend line itself (not the bend angle).
|
||||
/// Used for grain direction comparison.
|
||||
/// </summary>
|
||||
public double LineAngle => StartPoint.AngleTo(EndPoint);
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var dir = Direction.ToString();
|
||||
var angle = Angle?.ToString("0.##") ?? "?";
|
||||
var radius = Radius?.ToString("0.###") ?? "?";
|
||||
return $"{dir} {angle}° R{radius}";
|
||||
}
|
||||
}
|
||||
}
|
||||
9
OpenNest.Core/Bending/BendDirection.cs
Normal file
9
OpenNest.Core/Bending/BendDirection.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace OpenNest.Bending
|
||||
{
|
||||
public enum BendDirection
|
||||
{
|
||||
Unknown,
|
||||
Up,
|
||||
Down
|
||||
}
|
||||
}
|
||||
90
OpenNest.Tests/Bending/BendModelTests.cs
Normal file
90
OpenNest.Tests/Bending/BendModelTests.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
using OpenNest.Bending;
|
||||
using OpenNest.Geometry;
|
||||
|
||||
namespace OpenNest.Tests.Bending;
|
||||
|
||||
public class BendModelTests
|
||||
{
|
||||
[Fact]
|
||||
public void Bend_StoresStartAndEndPoints()
|
||||
{
|
||||
var bend = new Bend
|
||||
{
|
||||
StartPoint = new Vector(0, 5),
|
||||
EndPoint = new Vector(10, 5),
|
||||
Direction = BendDirection.Up,
|
||||
Angle = 90,
|
||||
Radius = 0.06,
|
||||
NoteText = "UP 90° R0.06"
|
||||
};
|
||||
|
||||
Assert.Equal(0, bend.StartPoint.X);
|
||||
Assert.Equal(10, bend.EndPoint.X);
|
||||
Assert.Equal(BendDirection.Up, bend.Direction);
|
||||
Assert.Equal(90, bend.Angle);
|
||||
Assert.Equal(0.06, bend.Radius);
|
||||
Assert.Equal("UP 90° R0.06", bend.NoteText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Bend_ToLine_ReturnsGeometryLine()
|
||||
{
|
||||
var bend = new Bend
|
||||
{
|
||||
StartPoint = new Vector(0, 5),
|
||||
EndPoint = new Vector(10, 5)
|
||||
};
|
||||
|
||||
var line = bend.ToLine();
|
||||
|
||||
Assert.Equal(0, line.StartPoint.X);
|
||||
Assert.Equal(5, line.StartPoint.Y);
|
||||
Assert.Equal(10, line.EndPoint.X);
|
||||
Assert.Equal(5, line.EndPoint.Y);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Bend_Length_ComputesCorrectly()
|
||||
{
|
||||
var bend = new Bend
|
||||
{
|
||||
StartPoint = new Vector(0, 0),
|
||||
EndPoint = new Vector(3, 4)
|
||||
};
|
||||
|
||||
Assert.Equal(5.0, bend.Length, 0.001);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Bend_BendAngleRadians_ConvertsDegreesToRadians()
|
||||
{
|
||||
var bend = new Bend { Angle = 90 };
|
||||
|
||||
Assert.Equal(System.Math.PI / 2, bend.AngleRadians, 0.001);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Bend_DefaultDirection_IsUnknown()
|
||||
{
|
||||
var bend = new Bend();
|
||||
|
||||
Assert.Equal(BendDirection.Unknown, bend.Direction);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Bend_ToString_FormatsNicely()
|
||||
{
|
||||
var bend = new Bend
|
||||
{
|
||||
Direction = BendDirection.Up,
|
||||
Angle = 90,
|
||||
Radius = 0.06
|
||||
};
|
||||
|
||||
var str = bend.ToString();
|
||||
|
||||
Assert.Contains("Up", str);
|
||||
Assert.Contains("90", str);
|
||||
Assert.Contains("0.06", str);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user