fix(engine): reject unrepresentable nesting output before geometry checks

This commit is contained in:
aj committed 2026-09-29 10:47:36 -04:00
1 parent ac901f7ee9
commit b8bded1b09
6 files changed
+335 -98

No files matched your search

@@ -7,8 +7,8 @@ namespace OpenNest.Engine.Jobs.Adapters;
/// <summary>
/// Binds one result sheet's poses to the caller's own drawings. The pose semantics match
/// <see cref="NestResultMaterializer"/>: rotate about the snapshot origin, then translate.
/// Placements whose requirement ID is not in the map are skipped here; the pipeline reports
/// them as violations instead of dropping them silently.
/// Every pose must be finite and refer to a mapped drawing. Malformed sheets are rejected
/// before binding any parts; the pipeline reports these violations without invoking binding.
/// </summary>
public static class NestResultBinder
{
@@ -19,12 +19,17 @@ public static class NestResultBinder
{
ArgumentNullException.ThrowIfNull(sheet);
ArgumentNullException.ThrowIfNull(drawingsByPartId);
foreach (var pose in sheet.Placements)
{
if (pose.PartId == null || !drawingsByPartId.TryGetValue(pose.PartId, out var drawing) || drawing == null)
throw new ArgumentException("Result contains a requirement not present in the drawing map.", nameof(sheet));
if (!double.IsFinite(pose.X) || !double.IsFinite(pose.Y) || !double.IsFinite(pose.Rotation))
throw new ArgumentException("Result contains a nonfinite placement pose.", nameof(sheet));
}
var parts = new List<Part>(sheet.Placements.Count);
foreach (var pose in sheet.Placements)
{
if (!drawingsByPartId.TryGetValue(pose.PartId, out var drawing))
continue;
var part = new Part(drawing);
var part = new Part(drawingsByPartId[pose.PartId]);
part.Rotate(pose.Rotation);
part.Location = new Vector(pose.X, pose.Y);
part.UpdateBounds();