From d7f9f25265633e8715c818bf0f0c78ebb50eb7c6 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Sat, 7 Nov 2026 21:26:30 -0500 Subject: [PATCH] feat(ui): aim the flange hole callout through its center and dot the bolt circle The Shape Library's hole diameter leader now crosses its hole through the center to the far edge, arrows pointing out onto both edges, wherever the label is dragged. The hole pattern dimension measures a dotted bolt circle through the hole centers. Co-Authored-By: Claude Opus 5.5 --- OpenNest.Core/Shapes/PipeFlangeShape.cs | 9 ++-- OpenNest.Core/Shapes/ShapeDimension.cs | 51 +++++++++++++++++++- OpenNest.Tests/Shapes/ShapeDimensionTests.cs | 29 +++++++++++ OpenNest/Controls/ShapePreviewControl.cs | 44 ++++++++++++++++- 4 files changed, 126 insertions(+), 7 deletions(-) diff --git a/OpenNest.Core/Shapes/PipeFlangeShape.cs b/OpenNest.Core/Shapes/PipeFlangeShape.cs index d5da7afc..01d11e89 100644 --- a/OpenNest.Core/Shapes/PipeFlangeShape.cs +++ b/OpenNest.Core/Shapes/PipeFlangeShape.cs @@ -37,19 +37,20 @@ namespace OpenNest.Shapes var dimensions = new List { ShapeDimension.Linear(nameof(OD), new Vector(-OD / 2, 0), new Vector(OD / 2, 0), ShapeDimension.Up, "Ø"), + // Measures the dotted bolt circle through the hole centers. ShapeDimension.Linear(nameof(HolePatternDiameter), new Vector(-HolePatternDiameter / 2, 0), - new Vector(HolePatternDiameter / 2, 0), ShapeDimension.Down, "Ø"), + new Vector(HolePatternDiameter / 2, 0), ShapeDimension.Down, "Ø").WithCircle(), }; - // The leader starts on the hole nearest 45 degrees, at its edge facing out that way. + // The leader crosses the hole nearest 45 degrees through its center, out that way. if (HoleCount > 0) { var step = 2.0 * System.Math.PI / HoleCount; var angle = System.Math.Round(System.Math.PI / 4 / step) * step; var out45 = new Vector(System.Math.Sqrt(0.5), System.Math.Sqrt(0.5)); var center = new Vector(HolePatternDiameter / 2 * System.Math.Cos(angle), HolePatternDiameter / 2 * System.Math.Sin(angle)); - var edge = new Vector(center.X + out45.X * HoleDiameter / 2, center.Y + out45.Y * HoleDiameter / 2); - dimensions.Add(ShapeDimension.Leader(nameof(HoleDiameter), edge, out45, "Ø").WithCount(nameof(HoleCount), "holes")); + dimensions.Add(ShapeDimension.HoleLeader(nameof(HoleDiameter), center, HoleDiameter / 2, out45, "Ø") + .WithCount(nameof(HoleCount), "holes")); } return dimensions; diff --git a/OpenNest.Core/Shapes/ShapeDimension.cs b/OpenNest.Core/Shapes/ShapeDimension.cs index cc6292e2..3008ec49 100644 --- a/OpenNest.Core/Shapes/ShapeDimension.cs +++ b/OpenNest.Core/Shapes/ShapeDimension.cs @@ -56,9 +56,42 @@ namespace OpenNest.Shapes /// The plural noun after the count, such as "holes". public string CountNoun { get; private init; } + /// + /// The center of the hole a diameter leader calls out; null for other dimensions. + /// The leader's line crosses the hole through it, whichever way the label is dragged. + /// + public Vector? HoleCenter { get; private init; } + + /// The radius of the hole at . + public double HoleRadius { get; private init; } + + /// + /// True when and span the diameter of a reference + /// circle (such as a flange's bolt circle) that the preview draws dotted. + /// + public bool DrawsCircle { get; private init; } + /// This dimension with "x {count} {noun}" after its value. public ShapeDimension WithCount(string countProperty, string noun) => - new(Property, Kind, Start, End, Side, Prefix) { CountProperty = countProperty, CountNoun = noun }; + new(Property, Kind, Start, End, Side, Prefix) + { + CountProperty = countProperty, + CountNoun = noun, + HoleCenter = HoleCenter, + HoleRadius = HoleRadius, + DrawsCircle = DrawsCircle, + }; + + /// This dimension measuring a dotted circle whose diameter runs from to . + public ShapeDimension WithCircle() => + new(Property, Kind, Start, End, Side, Prefix) + { + CountProperty = CountProperty, + CountNoun = CountNoun, + HoleCenter = HoleCenter, + HoleRadius = HoleRadius, + DrawsCircle = true, + }; /// /// Measures from to across @@ -77,6 +110,22 @@ namespace OpenNest.Shapes new Vector(direction.X / length, direction.Y / length), prefix); } + /// + /// A diameter leader on the hole at : it starts on the hole's + /// edge facing , and its line runs across the hole through the center. + /// + public static ShapeDimension HoleLeader(string property, Vector center, double radius, Vector direction, string prefix = "") + { + var length = System.Math.Sqrt(direction.X * direction.X + direction.Y * direction.Y); + var unit = new Vector(direction.X / length, direction.Y / length); + var edge = new Vector(center.X + unit.X * radius, center.Y + unit.Y * radius); + return new(property, ShapeDimensionKind.Leader, edge, edge, unit, prefix) + { + HoleCenter = center, + HoleRadius = radius, + }; + } + /// The distance the dimension shows between its points (zero for a leader). public double Measured => Kind switch diff --git a/OpenNest.Tests/Shapes/ShapeDimensionTests.cs b/OpenNest.Tests/Shapes/ShapeDimensionTests.cs index 2aace7b7..a8878ae2 100644 --- a/OpenNest.Tests/Shapes/ShapeDimensionTests.cs +++ b/OpenNest.Tests/Shapes/ShapeDimensionTests.cs @@ -49,6 +49,35 @@ public class ShapeDimensionTests Assert.Equal("holes", holes.CountNoun); } + [Theory] + [InlineData(4)] + [InlineData(8)] + public void FlangeHoleLeaderCrossesAHoleThroughItsCenter(int holeCount) + { + var flange = new PipeFlangeShape { OD = 7.5, HoleDiameter = 0.875, HolePatternDiameter = 5.5, HoleCount = holeCount }; + + var holes = flange.GetDimensions().Single(d => d.Property == nameof(PipeFlangeShape.HoleDiameter)); + + Assert.NotNull(holes.HoleCenter); + var center = holes.HoleCenter!.Value; + Assert.Equal(5.5 / 2, center.DistanceTo(new OpenNest.Geometry.Vector(0, 0)), 6); + Assert.Equal(0.875 / 2, holes.HoleRadius, 6); + Assert.Equal(holes.HoleRadius, holes.Start.DistanceTo(center), 6); + Assert.Equal(nameof(PipeFlangeShape.HoleCount), holes.CountProperty); + } + + [Fact] + public void FlangeHolePatternMeasuresADottedBoltCircle() + { + var flange = new PipeFlangeShape(); + flange.SetPreviewDefaults(); + + var pattern = flange.GetDimensions().Single(d => d.Property == nameof(PipeFlangeShape.HolePatternDiameter)); + + Assert.True(pattern.DrawsCircle); + Assert.Equal(flange.HolePatternDiameter, pattern.Start.DistanceTo(pattern.End), 6); + } + [Fact] public void RoundedRectangleRadiusLeaderStartsOnTheCornerArc() { diff --git a/OpenNest/Controls/ShapePreviewControl.cs b/OpenNest/Controls/ShapePreviewControl.cs index 62e565e7..6ddd67be 100644 --- a/OpenNest/Controls/ShapePreviewControl.cs +++ b/OpenNest/Controls/ShapePreviewControl.cs @@ -421,6 +421,9 @@ namespace OpenNest.Controls { public readonly List<(PointF A, PointF B)> Lines = new(); public readonly List<(PointF Tip, PointF From)> Arrows = new(); + + /// Dotted reference circles, such as a flange's bolt circle. + public readonly List<(PointF Center, float Radius)> Circles = new(); public readonly List