using System; using System.Collections.Generic; using OpenNest.Geometry; namespace OpenNest.Support { /// /// What a cut part rests on: the machine's support bed, fixed to the machine and measured /// from the plate origin into the sheet, so its position on any sheet follows from the /// sheet's quadrant alone. A layout only reports where it touches material; the /// decides from those contacts whether a part stays level. /// The laser grid () is the built-in layout; straight or curved /// slats imported from a CAD layout can follow as further subclasses. /// /// /// A line a support bed's slugs are sliced along: along X at Y = when /// , else along Y at X = (world coordinates). /// public readonly record struct SliceLine(bool AlongX, double At); public abstract class SupportBed : IEquatable { protected SupportBed(double registrationTolerance, double stabilityMargin) { if (!double.IsFinite(registrationTolerance) || registrationTolerance < 0) throw new ArgumentOutOfRangeException(nameof(registrationTolerance), "Registration tolerance must be finite and zero or more."); if (!double.IsFinite(stabilityMargin) || stabilityMargin < 0) throw new ArgumentOutOfRangeException(nameof(stabilityMargin), "Stability margin must be finite and zero or more."); RegistrationTolerance = registrationTolerance; StabilityMargin = stabilityMargin; } /// /// How far a sheet may sit from its nominal place on the bed, along each axis. The /// analyzer checks the bed shifted by up to this much and keeps the worst result. /// public double RegistrationTolerance { get; } /// /// How far inside its contacts a part's center of gravity must lie for the part to count /// as supported; it allows for slag, gas pressure and a contact that is worn low. /// public double StabilityMargin { get; } /// /// The contacts under (world coordinates) on a sheet in /// , with the bed moved by . With /// , a layout may omit contacts that cannot be corners of /// their convex hull; the analyzer needs no others. /// public abstract IReadOnlyList Contacts(SupportMaterial material, int quadrant, Vector shift, bool extremesOnly = false); /// /// The straight lines a slug is sliced along across (world /// coordinates) on a sheet in (see ): /// a grid's lines midway between its rows and columns of points, so no slice cuts over a /// point, or a slat's center line. /// public abstract IReadOnlyList SliceLines(Box region, int quadrant); /// /// How far every contact stays from a slice line along X () or Y, /// wherever the sheet is registered within its tolerance: material nearer a line than this /// rests on nothing. 0 when a contact may lie on the line (a slat's center line). /// public virtual double SliceLineClearance(bool alongX) => 0; /// This layout with every length multiplied by (a unit change). public abstract SupportBed Scaled(double factor); public abstract bool Equals(SupportBed other); public override bool Equals(object obj) => obj is SupportBed other && Equals(other); public abstract override int GetHashCode(); /// -1 where a sheet in lies on the negative side of the origin along X. protected static double SignX(int quadrant) => quadrant is 2 or 3 ? -1 : 1; /// -1 where a sheet in lies on the negative side of the origin along Y. protected static double SignY(int quadrant) => quadrant is 3 or 4 ? -1 : 1; } }