From ba88ac253aef96136bcd1e05f4968fc7f6ffc619 Mon Sep 17 00:00:00 2001 From: AJ Isaacs Date: Mon, 6 Apr 2026 08:29:42 -0400 Subject: [PATCH] fix: Circle.ToPoints ignores Rotation, breaking reverse direction for circular perimeters Circle.ToPoints() always generated CCW points regardless of the Rotation property, so reversing a circle contour in the CAD converter had no effect. Now negates the step angle when Rotation is CW, matching Arc.ToPoints behavior. Co-Authored-By: Claude Opus 4.6 (1M context) --- OpenNest.Core/Geometry/Circle.cs | 4 +++- .../Geometry/ContourClassificationTests.cs | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/OpenNest.Core/Geometry/Circle.cs b/OpenNest.Core/Geometry/Circle.cs index dd0148f..05a03de 100644 --- a/OpenNest.Core/Geometry/Circle.cs +++ b/OpenNest.Core/Geometry/Circle.cs @@ -137,7 +137,9 @@ namespace OpenNest.Geometry public List ToPoints(int segments = 1000, bool circumscribe = false) { var points = new List(); - var stepAngle = Angle.TwoPI / segments; + var stepAngle = Rotation == RotationType.CW + ? -Angle.TwoPI / segments + : Angle.TwoPI / segments; var r = circumscribe && segments > 0 ? Radius / System.Math.Cos(stepAngle / 2.0) diff --git a/OpenNest.Tests/Geometry/ContourClassificationTests.cs b/OpenNest.Tests/Geometry/ContourClassificationTests.cs index 5dae382..593b46a 100644 --- a/OpenNest.Tests/Geometry/ContourClassificationTests.cs +++ b/OpenNest.Tests/Geometry/ContourClassificationTests.cs @@ -154,4 +154,18 @@ public class ContourClassificationTests Assert.NotEqual(originalDirection, newDirection); } + + [Fact] + public void Reverse_changes_direction_label_for_circle() + { + var shape = MakeCircleShape(0, 0, 10); + var contours = ContourInfo.Classify(new List { shape }); + var contour = contours[0]; + + var originalDirection = contour.DirectionLabel; + contour.Reverse(); + var newDirection = contour.DirectionLabel; + + Assert.NotEqual(originalDirection, newDirection); + } }