feat(engine): expose NestPlateStock.WorkArea, Area and Fits
Every plugin engine re-derived the quadrant/edge-spacing work area by hand (Gpt6Astra, Opus55 and Qwen each had a copy, as did the placement validator). One definition on the stock removes that duplication and the chance of an engine disagreeing with the validator's bounds. Co-Authored-By: Codex <noreply@openai.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -271,7 +271,7 @@ internal static class NestJobPlacementValidator
|
||||
|
||||
private static bool FitsWorkArea(ShapeTopology shape, NestPlateStock stock)
|
||||
{
|
||||
var workArea = WorkArea(stock);
|
||||
var workArea = stock.WorkArea;
|
||||
if (!FitsWorkArea(shape.Perimeter, workArea))
|
||||
return false;
|
||||
foreach (var cutout in shape.Cutouts)
|
||||
@@ -280,18 +280,6 @@ internal static class NestJobPlacementValidator
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Box WorkArea(NestPlateStock stock)
|
||||
{
|
||||
var left = stock.Quadrant is 1 or 4 ? 0 : -stock.Size.Length;
|
||||
var bottom = stock.Quadrant is 1 or 2 ? 0 : -stock.Size.Width;
|
||||
return new Box(
|
||||
left + stock.EdgeSpacing.Left,
|
||||
bottom + stock.EdgeSpacing.Bottom,
|
||||
stock.Size.Length - stock.EdgeSpacing.Left - stock.EdgeSpacing.Right,
|
||||
stock.Size.Width - stock.EdgeSpacing.Bottom - stock.EdgeSpacing.Top
|
||||
);
|
||||
}
|
||||
|
||||
private static bool FitsWorkArea(Shape contour, Box workArea)
|
||||
{
|
||||
var bounds = contour.BoundingBox;
|
||||
|
||||
@@ -6,6 +6,8 @@ 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,
|
||||
@@ -24,6 +26,14 @@ public sealed class NestPlateStock
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
@@ -34,4 +44,17 @@ public sealed class NestPlateStock
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user