using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
namespace OpenNest
{
///
/// The colors drawings are given by position. Immutable: it copies the colors it is given,
/// so a caller's later edits to its own array never change what drawings receive.
///
public sealed class PartPalette
{
private readonly Color[] colors;
public PartPalette(IEnumerable colors, bool useGoldenAngle = false)
{
ArgumentNullException.ThrowIfNull(colors);
this.colors = colors.ToArray();
Colors = Array.AsReadOnly(this.colors);
UseGoldenAngle = useGoldenAngle;
}
/// The default palette, also the fallback before a color scheme is applied.
public static PartPalette Classic { get; } = new PartPalette(new[]
{
Color.FromArgb(205, 92, 92), // Indian Red
Color.FromArgb(148, 103, 189), // Medium Purple
Color.FromArgb(75, 180, 175), // Teal
Color.FromArgb(210, 190, 75), // Goldenrod
Color.FromArgb(190, 85, 175), // Orchid
Color.FromArgb(185, 115, 85), // Sienna
Color.FromArgb(120, 100, 190), // Slate Blue
Color.FromArgb(200, 100, 140), // Rose
Color.FromArgb(80, 175, 155), // Sea Green
Color.FromArgb(195, 160, 85), // Dark Khaki
Color.FromArgb(175, 95, 160), // Plum
Color.FromArgb(215, 130, 130), // Light Coral
});
/// The explicit colors, cycled by unless .
public IReadOnlyList Colors { get; }
/// When set, colors are generated by instead of cycled.
public bool UseGoldenAngle { get; }
public Color ColorAt(int index)
{
ArgumentOutOfRangeException.ThrowIfNegative(index);
return UseGoldenAngle
? PartColorPalette.GoldenAngle(index)
: colors[index % colors.Length];
}
}
}