fix(desktop): paint the utilization bar when its fill is a sliver

A one-pixel fill (about 2% on the Nesting Progress bar) asked GDI+ for a
zero-size corner arc, which threw "Parameter is not valid" mid-nest. Clamp
the corner radius to the rectangle and fall back to a plain rectangle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Opus 5.5 committed 2026-10-25 12:56:51 -04:00
1 parent 0d369c9a51
commit 4b982e8eeb
2 files changed
+41

No files matched your search

@@ -0,0 +1,33 @@
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using OpenNest.Controls;
namespace OpenNest.WinForms.Tests.Controls;
/// <summary>
/// The Nesting Progress utilization bar paints at every value and size: a sliver of fill
/// (about 1% on the default bar) once threw from a zero-size corner arc.
/// </summary>
public class DensityBarTests
{
[Theory]
[InlineData(60, 8, 0.0)]
[InlineData(60, 8, 0.01)]
[InlineData(60, 8, 0.02)]
[InlineData(60, 8, 0.05)]
[InlineData(60, 8, 0.5)]
[InlineData(60, 8, 1.0)]
[InlineData(60, 4, 0.5)]
[InlineData(3, 2, 1.0)]
[InlineData(1, 1, 1.0)]
public void Paints_without_throwing(int width, int height, double value)
{
using var bar = new DensityBar { Size = new Size(width, height), Value = value };
using var bitmap = new Bitmap(System.Math.Max(width, 1), System.Math.Max(height, 1));
using var g = Graphics.FromImage(bitmap);
typeof(DensityBar).GetMethod("OnPaint", BindingFlags.Instance | BindingFlags.NonPublic)!
.Invoke(bar, new object[] { new PaintEventArgs(g, bar.ClientRectangle) });
}
}
+8
View File
@@ -67,6 +67,14 @@ namespace OpenNest.Controls
private static GraphicsPath CreateRoundedRect(Rectangle rect, int radius)
{
var path = new GraphicsPath();
// GDI+ refuses a zero-size arc, which a sliver of fill would need.
radius = System.Math.Min(radius, System.Math.Min(rect.Width, rect.Height) / 2);
if (radius <= 0)
{
path.AddRectangle(rect);
return path;
}
var d = radius * 2;
path.AddArc(rect.X, rect.Y, d, d, 180, 90);
path.AddArc(rect.Right - d, rect.Y, d, d, 270, 90);