mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-23 17:57:43 -05:00
Add Core BendGrain (across / with / other, 5 degree tolerance, 15 degree buckets mod 180) and draw each bend line in the plate view by kind: yellow across the grain, orange with it, blue otherwise. Replaces the whole-part orange outline warning, which only said that some bend was off. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
65 lines
2.3 KiB
C#
65 lines
2.3 KiB
C#
using OpenNest.Bending;
|
|
using OpenNest.Controls;
|
|
using OpenNest.Geometry;
|
|
using OpenNest.Math;
|
|
|
|
namespace OpenNest.WinForms.Tests.Controls;
|
|
|
|
/// <summary>
|
|
/// Bends are kept in the drawing's source frame while its program starts at the origin, so a
|
|
/// placed part draws them with <c>Source.Offset</c> removed.
|
|
/// </summary>
|
|
public class BendLinePlacementTests
|
|
{
|
|
[Fact]
|
|
public void BendToWorld_RemovesSourceOffsetBeforePlacing()
|
|
{
|
|
var drawing = new Drawing("bent", new CNC.Program());
|
|
drawing.Source.Offset = new Vector(100, 50);
|
|
// In the source frame the bend runs across the part at local x = 5.
|
|
var bend = new Bend { StartPoint = new Vector(105, 50), EndPoint = new Vector(105, 60) };
|
|
var part = new Part(drawing, new Vector(10, 20));
|
|
|
|
Assert.Equal(new Vector(15, 20), PlateRenderer.BendToWorld(part, bend.StartPoint));
|
|
Assert.Equal(new Vector(15, 30), PlateRenderer.BendToWorld(part, bend.EndPoint));
|
|
}
|
|
|
|
[Fact]
|
|
public void BendToWorld_RotatesAboutTheProgramOrigin()
|
|
{
|
|
var drawing = new Drawing("bent", new CNC.Program());
|
|
drawing.Source.Offset = new Vector(100, 50);
|
|
var part = new Part(drawing, new Vector(10, 20));
|
|
part.Rotate(Angle.HalfPI, part.Location);
|
|
|
|
var world = PlateRenderer.BendToWorld(part, new Vector(105, 50));
|
|
|
|
Assert.Equal(10, world.X, 9);
|
|
Assert.Equal(25, world.Y, 9);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(BendGrainKind.AcrossGrain)]
|
|
[InlineData(BendGrainKind.WithGrain)]
|
|
[InlineData(BendGrainKind.Other)]
|
|
public void BendGrainColor_GivesEachKindItsOwnColor(BendGrainKind kind)
|
|
{
|
|
var colors = new[]
|
|
{
|
|
PlateRenderer.BendGrainColor(BendGrainKind.AcrossGrain),
|
|
PlateRenderer.BendGrainColor(BendGrainKind.WithGrain),
|
|
PlateRenderer.BendGrainColor(BendGrainKind.Other),
|
|
};
|
|
|
|
Assert.Equal(3, colors.Distinct().Count());
|
|
Assert.Equal(colors[(int)kind], PlateRenderer.BendGrainColor(kind));
|
|
}
|
|
|
|
[Fact]
|
|
public void BendGrainColor_KeepsTheBendColorAcrossTheGrainAndOrangeWithIt()
|
|
{
|
|
Assert.Equal(System.Drawing.Color.Yellow, PlateRenderer.BendGrainColor(BendGrainKind.AcrossGrain));
|
|
Assert.Equal(System.Drawing.Color.FromArgb(255, 140, 0), PlateRenderer.BendGrainColor(BendGrainKind.WithGrain));
|
|
}
|
|
}
|