fix(auto-nest): keep layout thumbnails full height when captions overflow

A card whose sheet captions alone were wider than the strip shrank its
sheets to a third of full height and scrolled anyway, so cards with more
distinct sheets drew much smaller than the rest. They now keep full height
and scroll.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Opus 5.5 committed 2026-11-23 00:19:04 -05:00
1 parent b6a9cea93f
commit 5aa2c45536
2 files changed
+25 -3

No files matched your search

@@ -73,6 +73,24 @@ public class NestReviewFormTests
Assert.Equal(200.0 / outline.Area, strip.Utilization, 6);
}, TimeSpan.FromMinutes(1), "The STA test did not complete.");
[Fact]
public void SheetsKeepFullHeightWhenTheCaptionsAloneOverflowTheWidth() => StaTestThread.Run(() =>
{
var stock = new NestPlateStock("sheet", new Size(48, 96), quantity: null, partSpacing: 0.25);
using var strip = new OpenNest.Controls.SheetStripControl { Size = new System.Drawing.Size(600, 300), ShowRemnant = true };
strip.SetSheets(new[] { new ProposedPlate(0, stock, Array.Empty<Part>()) });
var one = strip.PixelsPerUnit;
// Twelve captions cannot fit 600 pixels at any scale.
strip.SetSheets(Enumerable.Range(0, 12)
.Select(i => new ProposedPlate(i, stock, Array.Empty<Part>()))
.ToArray());
Assert.True(one > 0);
Assert.Equal(one, strip.PixelsPerUnit, 3);
Assert.True(strip.AutoScrollMinSize.Width > strip.ClientSize.Width);
}, TimeSpan.FromMinutes(1), "The STA test did not complete.");
private static int SheetPixels(OpenNest.Controls.SheetStripControl strip)
{
using var bitmap = new System.Drawing.Bitmap(strip.Width, strip.Height);
+7 -3
View File
@@ -115,9 +115,11 @@ namespace OpenNest.Controls
/// <summary>
/// Pixels per world unit, shared by every sheet. All sheets fit the width when they can;
/// otherwise they shrink to a third of full height and the strip scrolls.
/// otherwise they shrink to a third of full height and the strip scrolls. When the
/// captions alone are wider than the strip, shrinking cannot avoid the scroll, so the
/// sheets keep full height and the strip scrolls.
/// </summary>
private float PixelsPerUnit
internal float PixelsPerUnit
{
get
{
@@ -128,8 +130,10 @@ namespace OpenNest.Controls
if (tallest <= 0 || height <= 0)
return 0;
var full = (float)(height / tallest);
// Largest scale whose tiles, captions included, fit the width (tile widths grow with scale).
var width = ClientSize.Width - Edge * 2 - Gap * (tiles.Count - 1);
if (tiles.Sum(t => TileWidth(t, 0)) > width)
return full;
// Largest scale whose tiles, captions included, fit the width (tile widths grow with scale).
float low = 0, high = full;
for (var i = 0; i < 24; i++)
{