Files
OpenNest/OpenNest.Tests/Labels/LabelBoxRotationTests.cs
T
ajandClaude Opus 5.5 d52388bc57 feat(labels): place the label box by hand when it fits nowhere and let it turn
A part too small for the label (such as a bent 2 x 1 tab) told the user to
place the box by hand, but nothing let them: the button only ever ran the
finder. Now it places a full-size box on the roomiest flat spot a smaller
label fits (or the part's middle) and says to adjust it.

The box could be moved and resized but never turned, so a slanted placement
was stuck. A round handle above the box now turns it (5 degree steps, free
with Shift), and the Label Box menu adds Rotate 90 and Make Horizontal. The
angle stays within a quarter turn of horizontal so text never reads upside
down.

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

41 lines
1.3 KiB
C#

using OpenNest.Geometry;
using OpenNest.Labels;
namespace OpenNest.Tests.Labels;
public class LabelBoxRotationTests
{
[Theory]
[InlineData(0, 0)]
[InlineData(30, 30)]
[InlineData(90, 90)]
[InlineData(-90, 90)]
[InlineData(120, -60)]
[InlineData(180, 0)]
[InlineData(-135, 45)]
[InlineData(270, 90)]
[InlineData(405, 45)]
public void ReadableRotation_KeepsTextFromReadingUpsideDown(double degrees, double expected)
{
var turned = LabelBox.ReadableRotation(degrees * System.Math.PI / 180);
Assert.Equal(expected, turned * 180 / System.Math.PI, 9);
}
[Fact]
public void WithRotation_CoversTheSameRectangleAsTheHalfTurn()
{
var box = new LabelBox(new Vector(3, 4), 2, 0.5, 0);
var turned = box.WithRotation(System.Math.PI * 1.25);
Assert.Equal(System.Math.PI / 4, turned.Rotation, 9);
Assert.Equal(box.Center, turned.Center);
var halfTurn = new LabelBox(box.Center, 2, 0.5, System.Math.PI * 1.25).Corners();
foreach (var corner in turned.Corners())
Assert.Contains(halfTurn, c => c.DistanceTo(corner) < 1e-9);
}
[Fact]
public void ReadableRotation_PassesNonfiniteThrough() =>
Assert.True(double.IsNaN(LabelBox.ReadableRotation(double.NaN)));
}