Files
OpenNest/OpenNest.Tests/Labels/LabelPreviewTests.cs
T
ajandClaude Opus 5.5 75f7444aab feat(labels): etch each bend group letter inside a circle
A dash and letter after the part number (4980A01PT09-A) reads like a
revision, and many part numbers already end that way, so the shop could
not tell where the number stops and the bend group starts. Each group
letter is now etched at 0.6 of the text height inside its own circle the
text height across, clear of the name: 1234 (A)(B). One shape for every
group keeps the shape itself from seeming to mean something.

The circles take more room than "-AB", so the default label box grows
from seven characters to eight to keep a four-digit number and two groups
at full height. The gusset finder test is pinned to the seven-character
size it was written for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 17:53:23 -05:00

64 lines
2.0 KiB
C#

using OpenNest.Bending;
using OpenNest.Geometry;
using OpenNest.Labels;
namespace OpenNest.Tests.Labels;
public class LabelPreviewTests
{
[Fact]
public void PreviewText_IsTheFullLabelForTheUnrotatedPart()
{
var bends = new List<Bend>
{
new() { StartPoint = new Vector(1, 0), EndPoint = new Vector(1, 1) },
new() { StartPoint = new Vector(0, 2), EndPoint = new Vector(3, 2) },
};
Assert.Equal("4980A01PT103 AB", PartLabels.PreviewText("4980 A01 pt103", bends));
Assert.Equal("1234", PartLabels.PreviewText("1234", null));
Assert.Equal("", PartLabels.PreviewText(null, null));
}
[Fact]
public void Layout_FitsTextInAWideBox_AndKeepsItInside()
{
var box = new LabelBox(new Vector(5, 5), 4, 0.5, System.Math.PI / 6);
var strokes = PartLabels.Layout(box, "1234", out var fits);
Assert.True(fits);
Assert.NotEmpty(strokes!);
foreach (var point in strokes!.SelectMany(s => s.Points()))
{
var local = box.ToLocal(point);
Assert.InRange(local.X, -2 - 1e-9, 2 + 1e-9);
Assert.InRange(local.Y, -0.25 - 1e-9, 0.25 + 1e-9);
}
}
[Fact]
public void Layout_InATallSkinnyBox_ShrinksTheTextAndSaysItWillNotEtch()
{
var box = new LabelBox(new Vector(0, 0), 0.25, 2, 0);
var strokes = PartLabels.Layout(box, "4980A01PT103", out var fits);
Assert.False(fits);
Assert.NotEmpty(strokes!);
var height = strokes!.SelectMany(s => s.Points()).Max(p => p.Y) - strokes.SelectMany(s => s.Points()).Min(p => p.Y);
Assert.True(height < 1, $"Text {height} tall was not shrunk.");
}
[Fact]
public void Layout_AgreesWithWhatPlanCuttingEtches()
{
var drawing = new Drawing("12345") { LabelBox = new LabelBox(new Vector(1, 1), 0.3, 0.25, 0) };
PartLabels.Layout(drawing.LabelBox, PartLabels.Text(drawing, 0, 0), out var fits);
Assert.False(fits);
Assert.Null(PartLabels.Strokes(drawing, 0, 0));
}
}