diff --git a/OpenNest.Core/Bending/BendMath.cs b/OpenNest.Core/Bending/BendMath.cs
new file mode 100644
index 00000000..23192376
--- /dev/null
+++ b/OpenNest.Core/Bending/BendMath.cs
@@ -0,0 +1,13 @@
+namespace OpenNest.Bending
+{
+ public static class BendMath
+ {
+ ///
+ /// The length of the neutral axis through a bend: the arc at the inside radius plus
+ /// of the thickness.
+ ///
+ /// The bend angle in radians.
+ public static double Allowance(double angle, double insideRadius, double thickness, double kFactor) =>
+ angle * (insideRadius + kFactor * thickness);
+ }
+}
diff --git a/OpenNest.Core/Shapes/AngleShape.cs b/OpenNest.Core/Shapes/AngleShape.cs
new file mode 100644
index 00000000..1f162bd5
--- /dev/null
+++ b/OpenNest.Core/Shapes/AngleShape.cs
@@ -0,0 +1,73 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using OpenNest.Geometry;
+
+namespace OpenNest.Shapes
+{
+ ///
+ /// The flat blank of a formed angle: two legs and one 90° bend, sized from the outside
+ /// dimensions with the bend allowance at .
+ ///
+ public class AngleShape : ShapeDefinition
+ {
+ public double OutsideWidth { get; set; }
+ public double OutsideHeight { get; set; }
+ public double Thickness { get; set; }
+ public double InsideRadius { get; set; }
+
+ [Unitless]
+ [DisplayName("K-Factor")]
+ public double KFactor { get; set; }
+
+ public double Length { get; set; }
+
+ public double InsideWidth => OutsideWidth - Thickness;
+
+ public double InsideHeight => OutsideHeight - Thickness;
+
+ public double BendAllowance => SheetMetal.BendAllowance(InsideRadius, Thickness, KFactor);
+
+ /// The developed width of the blank: both legs' flats plus the bend.
+ public double FlatLength => InsideHeight - InsideRadius + InsideWidth - InsideRadius + BendAllowance;
+
+ /// The bend line's distance from the edge of the shorter leg.
+ public double BendLineDim => System.Math.Min(InsideWidth, InsideHeight) - InsideRadius + BendAllowance / 2;
+
+ public override string GenerateName() =>
+ $"Angle {Dim(OutsideWidth)}x{Dim(OutsideHeight)}x{Dim(Thickness)} x {Dim(Length)}";
+
+ public override void SetPreviewDefaults()
+ {
+ OutsideWidth = 4;
+ OutsideHeight = 2;
+ Thickness = 0.125;
+ InsideRadius = 0.3125;
+ KFactor = 0.42;
+ Length = 12;
+ }
+
+ public override IReadOnlyList GetDimensions() =>
+ new[]
+ {
+ ShapeDimension.Linear(nameof(Length), new Vector(0, 0), new Vector(Length, 0), ShapeDimension.Down),
+ };
+
+ public override ShapeSideView GetSideView() =>
+ SheetMetal.Section(false, OutsideWidth, OutsideHeight, Thickness, InsideRadius,
+ nameof(OutsideWidth), nameof(OutsideHeight), nameof(Thickness), nameof(InsideRadius));
+
+ public override Drawing GetDrawing()
+ {
+ SheetMetal.Validate(Thickness, Length, KFactor);
+ if (!(InsideHeight - InsideRadius > 0) || !(InsideWidth - InsideRadius > 0))
+ throw new InvalidOperationException("Each leg must be longer than the thickness plus the inside radius.");
+
+ // The shorter leg runs along the bottom edge, so the bend line sits BendLineDim up.
+ var entities = SheetMetal.Entities(Length, FlatLength, new[] { BendLineDim }, InsideRadius, out var bends);
+ var drawing = CreateDrawing(entities);
+ drawing.Bends.AddRange(bends);
+ return drawing;
+ }
+ }
+}
diff --git a/OpenNest.Core/Shapes/ChannelShape.cs b/OpenNest.Core/Shapes/ChannelShape.cs
new file mode 100644
index 00000000..0f93ab96
--- /dev/null
+++ b/OpenNest.Core/Shapes/ChannelShape.cs
@@ -0,0 +1,77 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using OpenNest.Geometry;
+
+namespace OpenNest.Shapes
+{
+ ///
+ /// The flat blank of a formed channel: two equal sides, a bottom and two 90° bends, sized
+ /// from the outside dimensions with the bend allowance at .
+ ///
+ public class ChannelShape : ShapeDefinition
+ {
+ public double OutsideWidth { get; set; }
+ public double OutsideHeight { get; set; }
+ public double Thickness { get; set; }
+ public double InsideRadius { get; set; }
+
+ [Unitless]
+ [DisplayName("K-Factor")]
+ public double KFactor { get; set; }
+
+ public double Length { get; set; }
+
+ public double InsideWidth => OutsideWidth - Thickness * 2;
+
+ public double InsideHeight => OutsideHeight - Thickness;
+
+ public double BendAllowance => SheetMetal.BendAllowance(InsideRadius, Thickness, KFactor);
+
+ /// The developed width of the blank: both sides' and the bottom's flats plus the bends.
+ public double FlatLength =>
+ (InsideHeight - InsideRadius) * 2 + InsideWidth - InsideRadius * 2 + BendAllowance * 2;
+
+ /// Each bend line's distance from its side's edge.
+ public double BendLineDim => InsideHeight - InsideRadius + BendAllowance / 2;
+
+ public override string GenerateName() =>
+ $"Channel {Dim(OutsideWidth)}x{Dim(OutsideHeight)}x{Dim(Thickness)} x {Dim(Length)}";
+
+ public override void SetPreviewDefaults()
+ {
+ OutsideWidth = 4;
+ OutsideHeight = 2;
+ Thickness = 0.125;
+ InsideRadius = 0.3125;
+ KFactor = 0.42;
+ Length = 12;
+ }
+
+ public override IReadOnlyList GetDimensions() =>
+ new[]
+ {
+ ShapeDimension.Linear(nameof(Length), new Vector(0, 0), new Vector(Length, 0), ShapeDimension.Down),
+ };
+
+ public override ShapeSideView GetSideView() =>
+ SheetMetal.Section(true, OutsideWidth, OutsideHeight, Thickness, InsideRadius,
+ nameof(OutsideWidth), nameof(OutsideHeight), nameof(Thickness), nameof(InsideRadius));
+
+ public override Drawing GetDrawing()
+ {
+ SheetMetal.Validate(Thickness, Length, KFactor);
+ if (!(InsideHeight - InsideRadius > 0))
+ throw new InvalidOperationException("The sides must be longer than the thickness plus the inside radius.");
+ if (InsideWidth - InsideRadius * 2 < 0)
+ throw new InvalidOperationException("The width must fit both sides' thickness and inside radius.");
+
+ var flat = FlatLength;
+ var bendLine = BendLineDim;
+ var entities = SheetMetal.Entities(Length, flat, new[] { bendLine, flat - bendLine }, InsideRadius, out var bends);
+ var drawing = CreateDrawing(entities);
+ drawing.Bends.AddRange(bends);
+ return drawing;
+ }
+ }
+}
diff --git a/OpenNest.Core/Shapes/RolledPlateShape.cs b/OpenNest.Core/Shapes/RolledPlateShape.cs
new file mode 100644
index 00000000..22224bab
--- /dev/null
+++ b/OpenNest.Core/Shapes/RolledPlateShape.cs
@@ -0,0 +1,72 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using OpenNest.Geometry;
+
+namespace OpenNest.Shapes
+{
+ ///
+ /// The flat blank of a plate rolled into a cylinder: by the
+ /// circumference of the neutral axis, of the thickness out from the
+ /// inside diameter.
+ ///
+ public class RolledPlateShape : ShapeDefinition
+ {
+ public double InsideDiameter { get; set; }
+ public double Thickness { get; set; }
+
+ [Unitless]
+ [DisplayName("K-Factor")]
+ public double KFactor { get; set; }
+
+ public double Length { get; set; }
+
+ public double InsideRadius => InsideDiameter / 2;
+
+ public double OutsideDiameter => InsideDiameter + Thickness * 2;
+
+ /// The developed width of the blank: the neutral axis's circumference.
+ public double FlatLength => System.Math.PI * 2 * (InsideRadius + Thickness * KFactor);
+
+ public override string GenerateName() =>
+ $"Rolled Plate {Dim(InsideDiameter)} ID x {Dim(Thickness)} x {Dim(Length)}";
+
+ public override void SetPreviewDefaults()
+ {
+ InsideDiameter = 10;
+ Thickness = 0.1875;
+ KFactor = 0.42;
+ Length = 12;
+ }
+
+ public override IReadOnlyList GetDimensions() =>
+ new[]
+ {
+ ShapeDimension.Linear(nameof(Length), new Vector(0, 0), new Vector(Length, 0), ShapeDimension.Down),
+ };
+
+ /// The rolled ring, with its inside diameter across the middle and a leader from its wall to the thickness.
+ public override ShapeSideView GetSideView()
+ {
+ var inside = InsideRadius;
+ var outside = InsideRadius + Thickness;
+ return new ShapeSideView(
+ new Entity[] { new Circle(0, 0, outside), new Circle(0, 0, inside) },
+ new[]
+ {
+ ShapeDimension.Inline(nameof(InsideDiameter), new Vector(-inside, 0), new Vector(inside, 0), "Ø"),
+ ShapeDimension.Leader(nameof(Thickness), new Vector(outside * System.Math.Sqrt(0.5), outside * System.Math.Sqrt(0.5)), new Vector(1, 1)),
+ });
+ }
+
+ public override Drawing GetDrawing()
+ {
+ SheetMetal.Validate(Thickness, Length, KFactor);
+ if (!(InsideDiameter > 0))
+ throw new InvalidOperationException("The inside diameter must be more than zero.");
+
+ var entities = SheetMetal.Entities(Length, FlatLength, Array.Empty(), 0, out _);
+ return CreateDrawing(entities);
+ }
+ }
+}
diff --git a/OpenNest.Core/Shapes/ShapeDefinition.cs b/OpenNest.Core/Shapes/ShapeDefinition.cs
index afd11c20..bdeafc07 100644
--- a/OpenNest.Core/Shapes/ShapeDefinition.cs
+++ b/OpenNest.Core/Shapes/ShapeDefinition.cs
@@ -42,6 +42,12 @@ namespace OpenNest.Shapes
///
public virtual IReadOnlyList GetDimensions() => Array.Empty();
+ ///
+ /// A sheet metal part's cross-section that the Shape Library draws beside the flat blank,
+ /// with the dimensions of parameters the blank cannot show; null for a flat shape.
+ ///
+ public virtual ShapeSideView GetSideView() => null;
+
public static List LoadFromJson(string path)
where T : ShapeDefinition
{
diff --git a/OpenNest.Core/Shapes/ShapeSideView.cs b/OpenNest.Core/Shapes/ShapeSideView.cs
new file mode 100644
index 00000000..0b48ba66
--- /dev/null
+++ b/OpenNest.Core/Shapes/ShapeSideView.cs
@@ -0,0 +1,24 @@
+using System.Collections.Generic;
+using OpenNest.Geometry;
+
+namespace OpenNest.Shapes
+{
+ ///
+ /// A sheet metal part's cross-section, which the Shape Library draws beside the flat blank with
+ /// its own dimensions. Annotation only: it never affects the drawing.
+ ///
+ public sealed class ShapeSideView
+ {
+ public ShapeSideView(IReadOnlyList entities, IReadOnlyList dimensions)
+ {
+ Entities = entities;
+ Dimensions = dimensions;
+ }
+
+ /// The section's closed outlines, in the view's own coordinates.
+ public IReadOnlyList Entities { get; }
+
+ /// The section's dimensions, in the same coordinates as .
+ public IReadOnlyList Dimensions { get; }
+ }
+}
diff --git a/OpenNest.Core/Shapes/SheetMetal.cs b/OpenNest.Core/Shapes/SheetMetal.cs
new file mode 100644
index 00000000..ca5c5189
--- /dev/null
+++ b/OpenNest.Core/Shapes/SheetMetal.cs
@@ -0,0 +1,119 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using OpenNest.Bending;
+using OpenNest.Geometry;
+
+namespace OpenNest.Shapes
+{
+ ///
+ /// Flat blanks and sections for the sheet metal shapes: parts bent or rolled along their
+ /// length, cut as a rectangle length along X by the developed width along Y.
+ ///
+ internal static class SheetMetal
+ {
+ public const double BendAngle = 90;
+
+ public static void Validate(double thickness, double length, double kFactor)
+ {
+ if (!(thickness > 0))
+ throw new InvalidOperationException("The thickness must be more than zero.");
+ if (!(length > 0))
+ throw new InvalidOperationException("The length must be more than zero.");
+ if (!(kFactor >= 0 && kFactor <= 1))
+ throw new InvalidOperationException("The K-factor must be from 0 to 1.");
+ }
+
+ public static double BendAllowance(double insideRadius, double thickness, double kFactor) =>
+ BendMath.Allowance(Math.Angle.ToRadians(BendAngle), insideRadius, thickness, kFactor);
+
+ /// The blank's outline, with a 90° up bend across it, etched, at each bend line.
+ /// Each bend line's distance from the blank's bottom edge.
+ public static List Entities(double length, double width, IReadOnlyList bendLines, double insideRadius, out List bends)
+ {
+ var entities = new List
+ {
+ new Line(0, 0, length, 0),
+ new Line(length, 0, length, width),
+ new Line(length, width, 0, width),
+ new Line(0, width, 0, 0),
+ };
+
+ bends = bendLines
+ .Select(y => new Bend
+ {
+ StartPoint = new Vector(0, y),
+ EndPoint = new Vector(length, y),
+ Direction = BendDirection.Up,
+ Angle = BendAngle,
+ Radius = insideRadius,
+ })
+ .ToList();
+ foreach (var bend in bends)
+ entities.AddRange(bend.GetEtchEntities());
+
+ return entities;
+ }
+
+ ///
+ /// The section of a part bent up 90° at its right end (an angle, "_|") or at both ends
+ /// (a channel, "U"): the bottom on Y = 0 from X = 0 to ,
+ /// the sides up to , every bend at
+ /// . Dimensioned with the outside sizes, the thickness
+ /// across the right side's top and the inside radius of its bend.
+ ///
+ public static ShapeSideView Section(
+ bool bothSides, double outsideWidth, double outsideHeight, double thickness, double insideRadius,
+ string widthProperty, string heightProperty, string thicknessProperty, string radiusProperty)
+ {
+ const double quarter = System.Math.PI / 2;
+ var outsideRadius = insideRadius + thickness;
+ var right = new Vector(outsideWidth - outsideRadius, outsideRadius);
+ var left = new Vector(outsideRadius, outsideRadius);
+ var w = outsideWidth;
+ var h = outsideHeight;
+ var t = thickness;
+
+ // Round the outside, counterclockwise from the bottom's left end, then back inside
+ // (a reversed arc runs clockwise from its start angle to its end angle).
+ var entities = new List();
+ if (bothSides)
+ {
+ entities.Add(new Line(0, h, 0, outsideRadius));
+ entities.Add(new Arc(left, outsideRadius, 2 * quarter, 3 * quarter));
+ entities.Add(new Line(outsideRadius, 0, right.X, 0));
+ }
+ else
+ {
+ entities.Add(new Line(0, 0, right.X, 0));
+ }
+ entities.Add(new Arc(right, outsideRadius, 3 * quarter, 4 * quarter));
+ entities.Add(new Line(w, outsideRadius, w, h));
+ entities.Add(new Line(w, h, w - t, h));
+ entities.Add(new Line(w - t, h, w - t, outsideRadius));
+ entities.Add(new Arc(right, insideRadius, 0, 3 * quarter, true));
+ if (bothSides)
+ {
+ entities.Add(new Line(right.X, t, outsideRadius, t));
+ entities.Add(new Arc(left, insideRadius, 3 * quarter, 2 * quarter, true));
+ entities.Add(new Line(t, outsideRadius, t, h));
+ entities.Add(new Line(t, h, 0, h));
+ }
+ else
+ {
+ entities.Add(new Line(right.X, t, 0, t));
+ entities.Add(new Line(0, t, 0, 0));
+ }
+
+ var dimensions = new[]
+ {
+ ShapeDimension.Linear(widthProperty, new Vector(0, 0), new Vector(w, 0), ShapeDimension.Down),
+ ShapeDimension.Linear(heightProperty, new Vector(w, 0), new Vector(w, h), ShapeDimension.Right),
+ ShapeDimension.Linear(thicknessProperty, new Vector(w - t, h), new Vector(w, h), ShapeDimension.Up),
+ ShapeDimension.ArcLeader(radiusProperty, right, insideRadius, 3 * quarter, 4 * quarter, "R"),
+ };
+
+ return new ShapeSideView(entities, dimensions);
+ }
+ }
+}
diff --git a/OpenNest.Core/Shapes/UnitlessAttribute.cs b/OpenNest.Core/Shapes/UnitlessAttribute.cs
new file mode 100644
index 00000000..abc862d5
--- /dev/null
+++ b/OpenNest.Core/Shapes/UnitlessAttribute.cs
@@ -0,0 +1,13 @@
+using System;
+
+namespace OpenNest.Shapes
+{
+ ///
+ /// Marks a shape parameter that is a plain number, such as a K-factor,
+ /// rather than a length: the Shape Library shows it without fractions or an inch mark.
+ ///
+ [AttributeUsage(AttributeTargets.Property)]
+ public sealed class UnitlessAttribute : Attribute
+ {
+ }
+}
diff --git a/OpenNest.Tests/Shapes/ShapeCutDirectionTests.cs b/OpenNest.Tests/Shapes/ShapeCutDirectionTests.cs
index deac5cf2..e2900e3d 100644
--- a/OpenNest.Tests/Shapes/ShapeCutDirectionTests.cs
+++ b/OpenNest.Tests/Shapes/ShapeCutDirectionTests.cs
@@ -17,6 +17,8 @@ public class ShapeCutDirectionTests
{
var shapes = new ShapeDefinition[]
{
+ new AngleShape(),
+ new ChannelShape(),
new CircleShape(),
new IsoscelesTriangleShape(),
new LShape(),
@@ -26,6 +28,7 @@ public class ShapeCutDirectionTests
new RectangleShape(),
new RightTriangleShape(),
new RingShape(),
+ new RolledPlateShape(),
new RoundedRectangleShape(),
new TShape(),
new TrapezoidShape(),
@@ -75,6 +78,9 @@ public class ShapeCutDirectionTests
Assert.True(perimeter >= 0, $"{name}: no perimeter");
for (var i = 0; i < contours.Count; i++)
{
+ // Marks such as etched bend lines are open: they have no winding.
+ if (contours[i].IsMark)
+ continue;
var area = ContourWinding.SignedArea(contours[i]);
if (i == perimeter)
Assert.True(area < 0, $"{name}: outside is not clockwise");
@@ -86,6 +92,7 @@ public class ShapeCutDirectionTests
/// Each contour's winding sign, in a stable order so reordering does not matter.
private static List Directions(Program program) =>
PostContours.Extract(program, Vector.Zero)
+ .Where(c => !c.IsMark)
.Select(c => System.Math.Sign(ContourWinding.SignedArea(c)))
.OrderBy(s => s)
.ToList();
diff --git a/OpenNest.Tests/Shapes/ShapeDimensionTests.cs b/OpenNest.Tests/Shapes/ShapeDimensionTests.cs
index 7a79bcba..6123272e 100644
--- a/OpenNest.Tests/Shapes/ShapeDimensionTests.cs
+++ b/OpenNest.Tests/Shapes/ShapeDimensionTests.cs
@@ -20,7 +20,10 @@ public class ShapeDimensionTests
{
var shape = (ShapeDefinition)Activator.CreateInstance(shapeType)!;
shape.SetPreviewDefaults();
- var dimensions = shape.GetDimensions();
+ // A side view's dimensions show parameters too, each once across both views.
+ var dimensions = shape.GetDimensions()
+ .Concat(shape.GetSideView()?.Dimensions ?? Array.Empty())
+ .ToList();
Assert.NotEmpty(dimensions);
Assert.Equal(dimensions.Count, dimensions.Select(d => d.Property).Distinct().Count());
diff --git a/OpenNest.Tests/Shapes/SheetMetalShapeTests.cs b/OpenNest.Tests/Shapes/SheetMetalShapeTests.cs
new file mode 100644
index 00000000..59b36497
--- /dev/null
+++ b/OpenNest.Tests/Shapes/SheetMetalShapeTests.cs
@@ -0,0 +1,182 @@
+using OpenNest.Bending;
+using OpenNest.CNC;
+using OpenNest.Geometry;
+using OpenNest.Shapes;
+
+namespace OpenNest.Tests.Shapes;
+
+public class SheetMetalShapeTests
+{
+ // 90° bend at 5/16 inside radius, 1/8 thick, K 0.42.
+ private static readonly double Allowance = System.Math.PI / 2 * (0.3125 + 0.42 * 0.125);
+
+ [Fact]
+ public void Angle_BlankIsTheDevelopedWidthByTheLength()
+ {
+ var shape = new AngleShape();
+ shape.SetPreviewDefaults();
+
+ var box = shape.GetDrawing().Program.BoundingBox();
+
+ // Legs' flats: 2 - 1/8 - 5/16 and 4 - 1/8 - 5/16.
+ var expected = 1.5625 + 3.5625 + Allowance;
+ Assert.Equal(expected, shape.FlatLength, 9);
+ Assert.Equal(12, box.Length, 6);
+ Assert.Equal(expected, box.Width, 6);
+ }
+
+ [Fact]
+ public void Angle_BendsUpAcrossTheBlankFromTheShorterLeg()
+ {
+ var shape = new AngleShape();
+ shape.SetPreviewDefaults();
+
+ var bend = Assert.Single(shape.GetDrawing().Bends);
+
+ var y = 1.5625 + Allowance / 2;
+ Assert.Equal(y, shape.BendLineDim, 9);
+ Assert.Equal(new Vector(0, y), bend.StartPoint);
+ Assert.Equal(new Vector(12, y), bend.EndPoint);
+ Assert.Equal(BendDirection.Up, bend.Direction);
+ Assert.Equal(90, bend.Angle);
+ Assert.Equal(0.3125, bend.Radius);
+ }
+
+ [Fact]
+ public void Channel_BlankHasTwoBendsInFromEachSide()
+ {
+ var shape = new ChannelShape();
+ shape.SetPreviewDefaults();
+
+ var drawing = shape.GetDrawing();
+ var box = drawing.Program.BoundingBox();
+
+ // Sides' flats: 2 - 1/8 - 5/16 each; bottom: 4 - 2(1/8) - 2(5/16).
+ var expected = 1.5625 * 2 + 3.125 + Allowance * 2;
+ Assert.Equal(expected, shape.FlatLength, 9);
+ Assert.Equal(expected, box.Width, 6);
+ var lines = drawing.Bends.Select(b => b.StartPoint.Y).OrderBy(y => y).ToList();
+ var inset = 1.5625 + Allowance / 2;
+ Assert.Equal(2, lines.Count);
+ Assert.Equal(inset, lines[0], 9);
+ Assert.Equal(expected - inset, lines[1], 9);
+ }
+
+ [Fact]
+ public void RolledPlate_BlankIsTheNeutralCircumference()
+ {
+ var shape = new RolledPlateShape { InsideDiameter = 10, Thickness = 0.25, KFactor = 0.5, Length = 24 };
+
+ var drawing = shape.GetDrawing();
+ var box = drawing.Program.BoundingBox();
+
+ var expected = System.Math.PI * 2 * (5 + 0.125);
+ Assert.Equal(expected, shape.FlatLength, 9);
+ Assert.Equal(24, box.Length, 6);
+ Assert.Equal(expected, box.Width, 6);
+ Assert.Empty(drawing.Bends);
+ Assert.Equal(10.5, shape.OutsideDiameter, 9);
+ }
+
+ [Fact]
+ public void BendLines_AreEtchedOnTheBlank()
+ {
+ var shape = new ChannelShape();
+ shape.SetPreviewDefaults();
+
+ var etches = shape.GetDrawing().Program.Codes
+ .OfType()
+ .Count(m => m.Layer == LayerType.Scribe);
+
+ // Each 12" bend line gets a 1" dash at either end.
+ Assert.Equal(4, etches);
+ }
+
+ [Fact]
+ public void Angle_LegNoLongerThanThicknessPlusRadius_DoesNotMakeAShape()
+ {
+ var shape = new AngleShape { OutsideWidth = 4, OutsideHeight = 0.4, Thickness = 0.125, InsideRadius = 0.3125, KFactor = 0.42, Length = 12 };
+
+ Assert.Throws(() => shape.GetDrawing());
+ }
+
+ [Fact]
+ public void KFactorAboveOne_DoesNotMakeAShape()
+ {
+ var shape = new ChannelShape();
+ shape.SetPreviewDefaults();
+ shape.KFactor = 1.5;
+
+ Assert.Throws(() => shape.GetDrawing());
+ }
+
+ [Fact]
+ public void AngleSideView_IsOneClosedSectionOfTheFormedAngle()
+ {
+ var shape = new AngleShape();
+ shape.SetPreviewDefaults();
+
+ var section = Assert.Single(ShapeBuilder.GetShapes(shape.GetSideView().Entities));
+
+ // Two legs' flats and a quarter annulus at the bend.
+ const double t = 0.125, ir = 0.3125, or = ir + t;
+ var expected = t * (4 - or) + t * (2 - or) + System.Math.PI / 4 * (or * or - ir * ir);
+ Assert.True(section.IsClosed());
+ Assert.Equal(expected, section.Area(), 1e-4);
+ var box = section.BoundingBox;
+ Assert.Equal(4, box.Length, 6);
+ Assert.Equal(2, box.Width, 6);
+ }
+
+ [Fact]
+ public void ChannelSideView_IsOneClosedSectionOfTheFormedChannel()
+ {
+ var shape = new ChannelShape();
+ shape.SetPreviewDefaults();
+
+ var section = Assert.Single(ShapeBuilder.GetShapes(shape.GetSideView().Entities));
+
+ // Two sides' and the bottom's flats and two quarter annuli at the bends.
+ const double t = 0.125, ir = 0.3125, or = ir + t;
+ var expected = t * (2 - or) * 2 + t * (4 - 2 * or) + System.Math.PI / 2 * (or * or - ir * ir);
+ Assert.True(section.IsClosed());
+ Assert.Equal(expected, section.Area(), 1e-4);
+ }
+
+ [Fact]
+ public void SideViews_DimensionTheSizesTheBlankCannotShow()
+ {
+ var angle = new AngleShape();
+ angle.SetPreviewDefaults();
+ var rolled = new RolledPlateShape();
+ rolled.SetPreviewDefaults();
+
+ Assert.Equal(
+ new[] { nameof(AngleShape.OutsideWidth), nameof(AngleShape.OutsideHeight), nameof(AngleShape.Thickness), nameof(AngleShape.InsideRadius) },
+ angle.GetSideView().Dimensions.Select(d => d.Property));
+ var radius = angle.GetSideView().Dimensions.Single(d => d.Property == nameof(AngleShape.InsideRadius));
+ Assert.Equal(0.3125, radius.ArcRadius, 9);
+ Assert.Equal("R", radius.Prefix);
+ Assert.Equal(
+ new[] { nameof(RolledPlateShape.InsideDiameter), nameof(RolledPlateShape.Thickness) },
+ rolled.GetSideView().Dimensions.Select(d => d.Property));
+ }
+
+ [Fact]
+ public void FlatShapes_HaveNoSideView()
+ {
+ Assert.Null(new RectangleShape { Length = 10, Width = 5 }.GetSideView());
+ }
+
+ [Fact]
+ public void GeneratedNames_DescribeThePart()
+ {
+ var angle = new AngleShape();
+ angle.SetPreviewDefaults();
+ var rolled = new RolledPlateShape();
+ rolled.SetPreviewDefaults();
+
+ Assert.Equal("Angle 4x2x0.125 x 12", angle.GenerateName());
+ Assert.Equal("Rolled Plate 10 ID x 0.188 x 12", rolled.GenerateName());
+ }
+}
diff --git a/OpenNest.WinForms.Tests/Forms/ShapeLibraryFormTests.cs b/OpenNest.WinForms.Tests/Forms/ShapeLibraryFormTests.cs
index 20b0a7df..378428d9 100644
--- a/OpenNest.WinForms.Tests/Forms/ShapeLibraryFormTests.cs
+++ b/OpenNest.WinForms.Tests/Forms/ShapeLibraryFormTests.cs
@@ -101,6 +101,52 @@ public class ShapeLibraryFormTests
Assert.True(Find