fix(core): color drawings from the classic palette when a scheme has no part colors

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
ajandClaude Fable 5.2 committed 2026-11-12 19:54:48 -05:00
1 parent 3b182b8b57
commit 32fc3cad97
2 files changed
+34 -4

No files matched your search

+9 -4
View File
@@ -38,7 +38,10 @@ namespace OpenNest
Color.FromArgb(215, 130, 130), // Light Coral
});
/// <summary>The explicit colors, cycled by <see cref="ColorAt"/> unless <see cref="UseGoldenAngle"/>.</summary>
/// <summary>
/// The explicit colors, cycled by <see cref="ColorAt"/> unless <see cref="UseGoldenAngle"/>.
/// When empty, <see cref="ColorAt"/> uses <see cref="Classic"/>.
/// </summary>
public IReadOnlyList<Color> Colors { get; }
/// <summary>When set, colors are generated by <see cref="PartColorPalette.GoldenAngle"/> instead of cycled.</summary>
@@ -47,9 +50,11 @@ namespace OpenNest
public Color ColorAt(int index)
{
ArgumentOutOfRangeException.ThrowIfNegative(index);
return UseGoldenAngle
? PartColorPalette.GoldenAngle(index)
: colors[index % colors.Length];
if (UseGoldenAngle)
return PartColorPalette.GoldenAngle(index);
// A scheme saved without part colors still has to color drawings.
return colors.Length == 0 ? Classic.ColorAt(index) : colors[index % colors.Length];
}
}
}
+25
View File
@@ -0,0 +1,25 @@
using System.Drawing;
namespace OpenNest.Tests;
public class PartPaletteTests
{
[Fact]
public void ColorAt_CyclesTheGivenColors()
{
var palette = new PartPalette(new[] { Color.Red, Color.Blue });
Assert.Equal(Color.Red, palette.ColorAt(0));
Assert.Equal(Color.Blue, palette.ColorAt(1));
Assert.Equal(Color.Red, palette.ColorAt(2));
}
[Fact]
public void ColorAt_WithNoColors_UsesTheClassicPalette()
{
var palette = new PartPalette(System.Array.Empty<Color>());
for (var i = 0; i < 14; i++)
Assert.Equal(PartPalette.Classic.ColorAt(i), palette.ColorAt(i));
}
}