Files
OpenNest/OpenNest.Engine/Jobs/NestJobResult.cs
T
aj 2b0b962c8f fix(engine): enforce whole-job safety invariants
Task 5 of the whole-job engine API: add a geometry safety gate that
validates every candidate trial before the runner commits accounting.

- NestJobPlacementValidator: closed-contour validity, rotation-policy
  compliance, work-area containment per quadrant, hole-aware material
  overlap, and required part spacing. Overlap is interior-only, so
  zero-clearance edge/corner contact remains a valid placement.
- NestJobValidator: route candidate validation through the geometry
  gate; reject unusable/unclosed/degenerate contours up front.
- NestJobRunner: wrap candidate evaluation in a progress bridge that
  tags legacy engine detail with the current candidate context.
- LegacyPlateNesterAdapter: forward IProgress to the legacy engine so
  its progress surfaces under the active candidate.
- Tests: geometry (quadrants, rotations, touching, containment, holes,
  empty stock, real Default/Strip smoke), validation, and cancellation
  suites; repaired test fakes that emitted out-of-bounds or overlapping
  placements the gate now correctly rejects.

Engine.Tests: 70 passed, 0 failed, 0 skipped in Debug and Release.
Windows-only OpenNest.Tests not run on Linux.
2026-09-18 05:56:37 -04:00

59 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
namespace OpenNest;
public enum NestJobStatus { Complete, Incomplete }
public enum NestJobStopReason { Completed, StockExhausted, NoPlacementFound, PlateLimitReached }
/// <summary>
/// Rotate about the snapshot origin, then translate by X/Y into the selected plate quadrant frame.
/// Rotation is in radians. InstanceIndex is zero-based and unique within a part requirement across the job.
/// The runner assigns final instance indices when committing a candidate.
/// </summary>
public sealed record NestJobPlacement(string PartId, int InstanceIndex, double X, double Y, double Rotation);
/// <summary>Requested = Placed + Unplaced for a requirement ID.</summary>
public sealed record PartFulfillment(string PartId, int Requested, int Placed, int Unplaced);
/// <summary>Used counts physical sheets; Remaining is null only for unlimited stock.</summary>
public sealed record StockUsage(string StockId, int Used, int? Remaining);
/// <summary>One physical sheet, with owned ordered placements and immutable stock/settings snapshot.</summary>
public sealed class NestJobPlateResult
{
public NestJobPlateResult(int plateIndex, NestPlateStock stock, IEnumerable<NestJobPlacement> placements)
{
ArgumentNullException.ThrowIfNull(stock);
PlateIndex = plateIndex;
Stock = stock;
Placements = NestJob.Own(placements);
}
public int PlateIndex { get; }
public string StockId => Stock.Id;
public NestPlateStock Stock { get; }
public IReadOnlyList<NestJobPlacement> Placements { get; }
}
/// <summary>Detached result values in commit/input order; no mutable Drawing, Plate, or NestItem escapes.</summary>
public sealed class NestJobResult
{
public NestJobResult(NestJobStatus status, NestJobStopReason stopReason,
IEnumerable<NestJobPlateResult> plates, IEnumerable<PartFulfillment> fulfillment,
IEnumerable<StockUsage> stockUsage)
{
Status = status;
StopReason = stopReason;
Plates = NestJob.Own(plates);
Fulfillment = NestJob.Own(fulfillment);
StockUsage = NestJob.Own(stockUsage);
}
public NestJobStatus Status { get; }
public NestJobStopReason StopReason { get; }
public IReadOnlyList<NestJobPlateResult> Plates { get; }
public IReadOnlyList<PartFulfillment> Fulfillment { get; }
public IReadOnlyList<StockUsage> StockUsage { get; }
}