mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-19 12:47:40 -05:00
Grain belongs to the physical sheet, so Rotate Plate CW/CCW must turn it too: a 60x120 sheet with side-to-side grain becomes a 120x60 sheet whose grain runs front to back. Rotate90 swapped the size and turned the parts but left GrainAngle alone, so bend-vs-grain warnings were wrong after a rotation. A 180-degree turn leaves the grain's line unchanged. Grain angles are lines, so they are kept in [0, pi). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
using OpenNest.Geometry;
|
|
using OpenNest.Math;
|
|
|
|
namespace OpenNest.Tests;
|
|
|
|
/// <summary>
|
|
/// The grain belongs to the sheet: turning the plate turns its grain, and grain angles are
|
|
/// lines, so angles π apart are the same grain.
|
|
/// </summary>
|
|
public class PlateGrainTests
|
|
{
|
|
[Theory]
|
|
[InlineData(RotationType.CW)]
|
|
[InlineData(RotationType.CCW)]
|
|
public void Rotate90_TurnsTheGrainWithTheSheet(RotationType direction)
|
|
{
|
|
// A 60 x 120 sheet whose grain runs side to side along its 120" length.
|
|
var plate = new Plate(new Size(60, 120)) { GrainAngle = 0 };
|
|
|
|
plate.Rotate90(direction);
|
|
|
|
Assert.Equal(new Size(120, 60), plate.Size);
|
|
Assert.Equal(Angle.HalfPI, plate.GrainAngle, 9);
|
|
|
|
plate.Rotate90(direction);
|
|
|
|
Assert.Equal(0, plate.GrainAngle, 9);
|
|
}
|
|
|
|
[Fact]
|
|
public void Rotate90_TurnsAnAngledGrainByAQuarterTurn()
|
|
{
|
|
var plate = new Plate(new Size(60, 120)) { GrainAngle = Angle.ToRadians(30) };
|
|
|
|
plate.Rotate90(RotationType.CCW);
|
|
|
|
Assert.Equal(Angle.ToRadians(120), plate.GrainAngle, 9);
|
|
}
|
|
|
|
[Fact]
|
|
public void Rotate180_LeavesTheGrainLineAlone()
|
|
{
|
|
var plate = new Plate(new Size(60, 120)) { GrainAngle = Angle.ToRadians(30) };
|
|
|
|
plate.Rotate180();
|
|
|
|
Assert.Equal(Angle.ToRadians(30), plate.GrainAngle, 9);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(0, 0)]
|
|
[InlineData(90, 90)]
|
|
[InlineData(180, 0)]
|
|
[InlineData(-90, 90)]
|
|
[InlineData(270, 90)]
|
|
[InlineData(210, 30)]
|
|
public void NormalizeGrainAngle_KeepsTheLineInZeroToPi(double degrees, double expected)
|
|
{
|
|
Assert.Equal(Angle.ToRadians(expected), Plate.NormalizeGrainAngle(Angle.ToRadians(degrees)), 9);
|
|
}
|
|
}
|