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.
This commit is contained in:
@@ -25,23 +25,21 @@ public static class NestJobValidator
|
||||
!double.IsFinite(m.X) || !double.IsFinite(m.Y) ||
|
||||
!double.IsFinite(m.CenterX) || !double.IsFinite(m.CenterY)))
|
||||
throw new ArgumentException($"Geometry must contain finite motions: {part.Id}.", nameof(job));
|
||||
try
|
||||
{
|
||||
NestJobPlacementValidator.ValidateGeometry(part.Geometry);
|
||||
}
|
||||
catch (ArgumentException exception)
|
||||
{
|
||||
throw new ArgumentException($"Geometry must contain usable closed edges: {part.Id}.", nameof(job), exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void ValidateCandidate(PlateCandidate candidate, IReadOnlyDictionary<string, int> remaining)
|
||||
internal static void ValidateCandidate(PlateCandidate candidate, NestPlateStock stock,
|
||||
IReadOnlyDictionary<string, int> remaining, IReadOnlyDictionary<string, NestJobPart> parts)
|
||||
{
|
||||
if (candidate == null) throw new InvalidOperationException("The plate nester returned a null candidate.");
|
||||
var counts = new Dictionary<string, int>(StringComparer.Ordinal);
|
||||
foreach (var placement in candidate.Placements)
|
||||
{
|
||||
if (placement.PartId == null || !remaining.TryGetValue(placement.PartId, out var available))
|
||||
throw new InvalidOperationException("Candidate references an unknown requirement ID.");
|
||||
if (!double.IsFinite(placement.X) || !double.IsFinite(placement.Y) || !double.IsFinite(placement.Rotation))
|
||||
throw new InvalidOperationException("Candidate poses must be finite.");
|
||||
counts.TryGetValue(placement.PartId, out var count);
|
||||
if (count >= available) throw new InvalidOperationException("Candidate overproduces a requirement.");
|
||||
counts[placement.PartId] = count + 1;
|
||||
}
|
||||
NestJobPlacementValidator.ValidateCandidate(candidate, stock, remaining, parts);
|
||||
}
|
||||
|
||||
private static bool Positive(double value) => double.IsFinite(value) && value > 0;
|
||||
|
||||
Reference in New Issue
Block a user