feat: add ShrinkFiller.TrimToCount for axis-aware edge trimming

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-20 00:03:57 -04:00
parent f0a3547bd1
commit 85278bbb75
2 changed files with 82 additions and 0 deletions

View File

@@ -163,5 +163,20 @@ namespace OpenNest.Engine.Fill
? placedBox.Right - box.X
: placedBox.Top - box.Y;
}
/// <summary>
/// Keeps the <paramref name="targetCount"/> parts nearest to the origin
/// along the given axis, discarding parts farthest from the origin.
/// Returns the input list unchanged if count is already at or below target.
/// </summary>
internal static List<Part> TrimToCount(List<Part> parts, int targetCount, ShrinkAxis axis)
{
if (parts == null || parts.Count <= targetCount)
return parts;
return axis == ShrinkAxis.Width
? parts.OrderBy(p => p.BoundingBox.Right).Take(targetCount).ToList()
: parts.OrderBy(p => p.BoundingBox.Top).Take(targetCount).ToList();
}
}
}