mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-25 11:17:40 -05:00
A slice whose strip beside the cutout is nearer its line than the grid's points ever come (half a pitch less the registration tolerance) separates no contacts; it only cuts close alongside the part's edge. Leave it out so the strip joins the piece beside it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
87 lines
4.4 KiB
C#
87 lines
4.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using OpenNest.Geometry;
|
|
|
|
namespace OpenNest.Support
|
|
{
|
|
/// <summary>
|
|
/// 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
|
|
/// <see cref="SupportAnalyzer"/> decides from those contacts whether a part stays level.
|
|
/// The laser grid (<see cref="SupportGrid"/>) is the built-in layout; straight or curved
|
|
/// slats imported from a CAD layout can follow as further subclasses.
|
|
/// </summary>
|
|
/// <summary>
|
|
/// A line a support bed's slugs are sliced along: along X at Y = <see cref="At"/> when
|
|
/// <see cref="AlongX"/>, else along Y at X = <see cref="At"/> (world coordinates).
|
|
/// </summary>
|
|
public readonly record struct SliceLine(bool AlongX, double At);
|
|
|
|
public abstract class SupportBed : IEquatable<SupportBed>
|
|
{
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
public double RegistrationTolerance { get; }
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
public double StabilityMargin { get; }
|
|
|
|
/// <summary>
|
|
/// The contacts under <paramref name="material"/> (world coordinates) on a sheet in
|
|
/// <paramref name="quadrant"/>, with the bed moved by <paramref name="shift"/>. With
|
|
/// <paramref name="extremesOnly"/>, a layout may omit contacts that cannot be corners of
|
|
/// their convex hull; the analyzer needs no others.
|
|
/// </summary>
|
|
public abstract IReadOnlyList<Vector> Contacts(SupportMaterial material, int quadrant, Vector shift,
|
|
bool extremesOnly = false);
|
|
|
|
/// <summary>
|
|
/// The straight lines a slug is sliced along across <paramref name="region"/> (world
|
|
/// coordinates) on a sheet in <paramref name="quadrant"/> (see <see cref="SlugSlicer"/>):
|
|
/// 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.
|
|
/// </summary>
|
|
public abstract IReadOnlyList<SliceLine> SliceLines(Box region, int quadrant);
|
|
|
|
/// <summary>
|
|
/// How far every contact stays from a slice line along X (<paramref name="alongX"/>) 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).
|
|
/// </summary>
|
|
public virtual double SliceLineClearance(bool alongX) => 0;
|
|
|
|
/// <summary>This layout with every length multiplied by <paramref name="factor"/> (a unit change).</summary>
|
|
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();
|
|
|
|
/// <summary>-1 where a sheet in <paramref name="quadrant"/> lies on the negative side of the origin along X.</summary>
|
|
protected static double SignX(int quadrant) => quadrant is 2 or 3 ? -1 : 1;
|
|
|
|
/// <summary>-1 where a sheet in <paramref name="quadrant"/> lies on the negative side of the origin along Y.</summary>
|
|
protected static double SignY(int quadrant) => quadrant is 3 or 4 ? -1 : 1;
|
|
}
|
|
}
|