using System; using OpenNest.Geometry; namespace OpenNest.Engine.Jobs; /// Shared numerical contract for layout validation. public static class NestTolerances { /// Arc chord tolerance used by both validators. The layout check circumscribes /// perimeter arcs and inscribes cutouts; the placement validator uses inscribed arcs. public const double ValidationOutline = 0.001; /// Clipper decimal precision (a 1e-4 coordinate grid). public const int ClipperPrecision = ClipperBridge.Precision; /// Extra pair clearance for an engine whose outline error is bounded by t. /// Each of two boundaries contributes ValidationOutline from validator flattening, /// one Clipper grid unit from rounding, and t from engine flattening: therefore /// 2 * ValidationOutline + 2 * 10^(-ClipperPrecision) + 2 * t. /// This budget assumes valid material geometry and bounded chord error on both sides. /// Tolerance is negative or non-finite. public static double SafeClearanceMargin(double engineChordTolerance) { if (!double.IsFinite(engineChordTolerance) || engineChordTolerance < 0) throw new ArgumentOutOfRangeException(nameof(engineChordTolerance)); return 2 * ValidationOutline + 2 * System.Math.Pow(10, -ClipperPrecision) + 2 * engineChordTolerance; } }