From 5553fe6386dbed78b3acdae799eb54fd63406204 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Mon, 16 Mar 2026 20:55:29 -0400 Subject: [PATCH] fix(ui): compute polylabel once from unrotated drawing Compute the label point from the base drawing's unrotated program and rotate the cached point instead of recomputing on each rotation. Prevents label jitter caused by arc discretization differences. Co-Authored-By: Claude Opus 4.6 (1M context) --- OpenNest/LayoutPart.cs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/OpenNest/LayoutPart.cs b/OpenNest/LayoutPart.cs index adb4748..d737bb3 100644 --- a/OpenNest/LayoutPart.cs +++ b/OpenNest/LayoutPart.cs @@ -46,16 +46,7 @@ namespace OpenNest Color = part.BaseDrawing.Color; } - private bool _isDirty; - internal bool IsDirty - { - get => _isDirty; - set - { - _isDirty = value; - if (value) _labelPoint = null; - } - } + internal bool IsDirty { get; set; } public bool IsSelected { get; set; } @@ -119,14 +110,14 @@ namespace OpenNest private Vector ComputeLabelPoint() { - var entities = ConvertProgram.ToGeometry(BasePart.Program); + var entities = ConvertProgram.ToGeometry(BasePart.BaseDrawing.Program); var nonRapid = entities.Where(e => e.Layer != SpecialLayers.Rapid).ToList(); var shapes = ShapeBuilder.GetShapes(nonRapid); if (shapes.Count == 0) { - var bbox = BasePart.Program.BoundingBox(); + var bbox = BasePart.BaseDrawing.Program.BoundingBox(); return new Vector(bbox.Location.X + bbox.Width / 2, bbox.Location.Y + bbox.Length / 2); } @@ -151,9 +142,10 @@ namespace OpenNest Path.Transform(plateView.Matrix); _labelPoint ??= ComputeLabelPoint(); + var rotatedLabel = _labelPoint.Value.Rotate(BasePart.Rotation); var labelPt = new PointF( - (float)(_labelPoint.Value.X + BasePart.Location.X), - (float)(_labelPoint.Value.Y + BasePart.Location.Y)); + (float)(rotatedLabel.X + BasePart.Location.X), + (float)(rotatedLabel.Y + BasePart.Location.Y)); var pts = new[] { labelPt }; plateView.Matrix.TransformPoints(pts); _labelScreenPoint = pts[0];