fix: add overlap safety check and diagnostics to FillGrid Step 2
FillGrid had no overlap check after perpendicular tiling of the row pattern (Step 2), unlike Step 1 which had one. When geometry-aware FindPatternCopyDistance underestimated row spacing, overlapping parts were returned unchecked. Changes: - Make FillLinear.HasOverlappingParts shape-aware (bbox pre-filter + Part.Intersects) instead of bbox-only, preventing false positives on interlocking pairs while catching real overlaps - Add missing overlap safety check after Step 2 perpendicular tiling with bbox fallback - Add diagnostic Debug.WriteLine logging when overlap fallback triggers, including engine label, step, direction, work area, spacing, pattern details, and overlapping part locations/rotations for reproduction - Add FillLinear.Label property set at all callsites for log traceability - Refactor LinearFillStrategy and ExtentsFillStrategy to use shared FillHelpers.BestOverAngles helper for angle-sweep logic Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -19,45 +19,28 @@ namespace OpenNest.Engine.Strategies
|
||||
var workArea = context.WorkArea;
|
||||
var comparer = context.Policy?.Comparer ?? new DefaultFillComparer();
|
||||
var preferred = context.Policy?.PreferredDirection;
|
||||
List<Part> best = null;
|
||||
|
||||
for (var ai = 0; ai < angles.Count; ai++)
|
||||
{
|
||||
context.Token.ThrowIfCancellationRequested();
|
||||
|
||||
var angle = angles[ai];
|
||||
var engine = new FillLinear(workArea, context.Plate.PartSpacing);
|
||||
|
||||
var result = FillHelpers.FillWithDirectionPreference(
|
||||
dir => engine.Fill(context.Item.Drawing, angle, dir),
|
||||
preferred, comparer, workArea);
|
||||
|
||||
var angleDeg = Angle.ToDegrees(angle);
|
||||
|
||||
if (result != null && result.Count > 0)
|
||||
return FillHelpers.BestOverAngles(context, angles,
|
||||
angle =>
|
||||
{
|
||||
context.AngleResults.Add(new AngleResult
|
||||
var engine = new FillLinear(workArea, context.Plate.PartSpacing) { Label = "Linear" };
|
||||
var result = FillHelpers.FillWithDirectionPreference(
|
||||
dir => engine.Fill(context.Item.Drawing, angle, dir),
|
||||
preferred, comparer, workArea);
|
||||
|
||||
if (result != null && result.Count > 0)
|
||||
{
|
||||
AngleDeg = angleDeg,
|
||||
Direction = preferred ?? NestDirection.Horizontal,
|
||||
PartCount = result.Count
|
||||
});
|
||||
context.AngleResults.Add(new AngleResult
|
||||
{
|
||||
AngleDeg = Angle.ToDegrees(angle),
|
||||
Direction = preferred ?? NestDirection.Horizontal,
|
||||
PartCount = result.Count
|
||||
});
|
||||
}
|
||||
|
||||
if (best == null || comparer.IsBetter(result, best, workArea))
|
||||
best = result;
|
||||
}
|
||||
|
||||
NestEngineBase.ReportProgress(context.Progress, new ProgressReport
|
||||
{
|
||||
Phase = NestPhase.Linear,
|
||||
PlateNumber = context.PlateNumber,
|
||||
Parts = best,
|
||||
WorkArea = workArea,
|
||||
Description = $"Linear: {ai + 1}/{angles.Count} angles, {angleDeg:F0}° best = {best?.Count ?? 0} parts",
|
||||
});
|
||||
}
|
||||
|
||||
return best ?? new List<Part>();
|
||||
return result;
|
||||
},
|
||||
NestPhase.Linear, "Linear");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user