using System; using OpenNest.Diagnostics; using OpenNest.Geometry; namespace OpenNest.CNC.CuttingPlanning; /// Automatic start preference, ordered: a lower value is more preferred. internal enum AutomaticEntryKind { /// A convex turn of the contour's own travel, classified exactly as emission classifies it. ConvexCorner = 0, /// The midpoint of a straight edge. StraightMidpoint = 1, /// A tangent line/arc joint. A collinear line/line split is not a joint and never appears. TangentJoint = 2, /// /// Tier 3 (fallback): a point on a straight edge meeting a convex corner, back from the /// corner by about twice the applicable lead-in length, strictly inside the edge. /// NearCorner = 3, /// /// Tier 3 (fallback): the exact native closest point facing the caller's look-ahead /// position (pass the arrival there when there is no next cut). Never a reflex/cusp vertex. /// TargetFacing = 4, /// Tier 3 (fallback): the native midpoint of an arc entity. ArcMidpoint = 5, /// Tier 3 (fallback): one of the eight compass points of a whole circle. CircleCompass = 6, /// A drawing pin's own entry: the one and only candidate of a pinned contour. Pinned = 7, /// /// The perimeter point where a tab best keeps the part level on its support bed; only a /// perimeter tabbed for support has it (see ). /// SupportTab = 8, /// /// A cutout entry pierced where eroding the cutout leaves room (see /// ): only offered once no configured /// lead-in of the cutout fits. /// ErodedPierce = 9, } /// /// Which automatic entries a perimeter tabbed for support offers (see /// ); every other contour offers its whole catalog. /// internal enum SupportEntries { /// Entries whose tab steadies the part, clear of inside corners, plus its best tab point. Steadying, /// Every entry clear of inside corners: the fallback when no steadying entry fits. ClearOfInsideCorners, /// Every entry: the last fallback, when nothing clear of inside corners fits. Any, } /// /// One automatic start candidate: the owned contour choice plus its preference kind and a /// stable geometry tie key for deterministic ranking. The choice keeps this preparation as /// owner; nothing here exposes or mutates the underlying shape. /// is how far a corner fillet's joint lies from the sharp corner it rounds (0 otherwise), so /// ranking can count it on both of that corner's sides. /// internal sealed record ContourEntryCandidate(ContourChoice Choice, AutomaticEntryKind Kind, double CornerReach = 0) { /// /// Stable geometric tie key: the point quantized to the preparation epsilon grid, so /// equal points rank together regardless of the entity that produced them. /// internal (long X, long Y) GeometryKey => (Quantize(Choice.Point.X), Quantize(Choice.Point.Y)); private static long Quantize(double value) => (long)System.Math.Round(value / PostVerificationGeometry.Epsilon); }