mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-11 00:44:13 -04:00
70 lines
2.7 KiB
C#
70 lines
2.7 KiB
C#
using System;
|
|
using OpenNest.Geometry;
|
|
|
|
namespace OpenNest.Engine.Jobs;
|
|
|
|
/// <summary>Immutable stock settings. Size and spacing are copied value types, not caller-owned settings.</summary>
|
|
public sealed class NestPlateStock
|
|
{
|
|
private readonly Box workArea;
|
|
|
|
public NestPlateStock(
|
|
string id,
|
|
Size size,
|
|
int? quantity = null,
|
|
double partSpacing = 0,
|
|
Spacing edgeSpacing = default,
|
|
int quadrant = 1
|
|
)
|
|
: this(id, size, quantity, partSpacing, edgeSpacing, quadrant, null) { }
|
|
|
|
public NestPlateStock(string id, Size size, int? quantity, double partSpacing,
|
|
Spacing edgeSpacing, int quadrant, double? cost)
|
|
{
|
|
if (cost.HasValue && (!double.IsFinite(cost.Value) || cost.Value <= 0))
|
|
throw new ArgumentOutOfRangeException(nameof(cost), $"Stock {id}: cost must be finite and positive, or null.");
|
|
Cost = cost;
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(id);
|
|
if (quantity < 0)
|
|
throw new ArgumentOutOfRangeException(nameof(quantity));
|
|
Id = id;
|
|
Size = size;
|
|
Quantity = quantity;
|
|
PartSpacing = partSpacing;
|
|
EdgeSpacing = edgeSpacing;
|
|
Quadrant = quadrant;
|
|
var left = quadrant is 1 or 4 ? 0 : -size.Length;
|
|
var bottom = quadrant is 1 or 2 ? 0 : -size.Width;
|
|
workArea = new Box(
|
|
left + edgeSpacing.Left,
|
|
bottom + edgeSpacing.Bottom,
|
|
size.Length - edgeSpacing.Left - edgeSpacing.Right,
|
|
size.Width - edgeSpacing.Bottom - edgeSpacing.Top
|
|
);
|
|
}
|
|
|
|
/// <summary>Generic per-physical-sheet cost; null selects area scoring.</summary>
|
|
public double? Cost { get; }
|
|
public string Id { get; }
|
|
public Size Size { get; }
|
|
|
|
/// <summary>Available physical sheets: null is unlimited, zero is legal but unavailable.</summary>
|
|
public int? Quantity { get; }
|
|
public double PartSpacing { get; }
|
|
public Spacing EdgeSpacing { get; }
|
|
public int Quadrant { get; }
|
|
|
|
/// <summary>
|
|
/// Usable region in the placement frame (quadrant applied, edge spacing removed).
|
|
/// Box.Length is the X extent, Box.Width the Y extent. Returns a detached copy.
|
|
/// </summary>
|
|
public Box WorkArea => new(workArea.X, workArea.Y, workArea.Length, workArea.Width);
|
|
|
|
/// <summary>Full sheet area before edge spacing is removed.</summary>
|
|
public double Area => Size.Width * Size.Length;
|
|
|
|
/// <summary>True when a width (X) by height (Y) envelope fits the work area within epsilon.</summary>
|
|
public bool Fits(double width, double height, double epsilon = 1e-9) =>
|
|
width <= workArea.Length + epsilon && height <= workArea.Width + epsilon;
|
|
}
|