diff --git a/OpenNest.Core/PartPalette.cs b/OpenNest.Core/PartPalette.cs
index 62feef7a..96fe55c1 100644
--- a/OpenNest.Core/PartPalette.cs
+++ b/OpenNest.Core/PartPalette.cs
@@ -38,7 +38,10 @@ namespace OpenNest
Color.FromArgb(215, 130, 130), // Light Coral
});
- /// The explicit colors, cycled by unless .
+ ///
+ /// The explicit colors, cycled by unless .
+ /// When empty, uses .
+ ///
public IReadOnlyList Colors { get; }
/// When set, colors are generated by instead of cycled.
@@ -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];
}
}
}
diff --git a/OpenNest.Tests/PartPaletteTests.cs b/OpenNest.Tests/PartPaletteTests.cs
new file mode 100644
index 00000000..add673c5
--- /dev/null
+++ b/OpenNest.Tests/PartPaletteTests.cs
@@ -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());
+
+ for (var i = 0; i < 14; i++)
+ Assert.Equal(PartPalette.Classic.ColorAt(i), palette.ColorAt(i));
+ }
+}