Files
@ 4ddfeff50454
Branch filter:
Location: ATITD-Tools/Desert-Paint-Lab/Palette.cs - annotation
4ddfeff50454
1.3 KiB
text/x-csharp
Fixed error that was causing upward-clipped colors to not properly trigger the error-checking for that case. Also, corrected warning message for that condition.
b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 b9934660c784 | using System;
using System.IO;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace DesertPaintLab
{
public class Palette
{
static List<PaintColor> colors = new List<PaintColor>();
static Regex colorEntry = new Regex(@"\#(?<red>\w\w)(?<green>\w\w)(?<blue>\w\w)\s*(?<name>\w+)");
public Palette ()
{
}
public static void Load(string file)
{
string line;
Match match;
using (StreamReader reader = new StreamReader(file))
{
while ((line = reader.ReadLine()) != null)
{
match = colorEntry.Match(line);
if (match.Success)
{
colors.Add(new PaintColor(match.Groups["name"].Value,
match.Groups["red"].Value,
match.Groups["green"].Value,
match.Groups["blue"].Value));
}
}
}
}
public static string FindNearest(PaintColor color)
{
int bestDistSq = int.MaxValue;
PaintColor bestColor = null;
foreach (PaintColor paintColor in colors)
{
int distSq = paintColor.GetDistanceSquared(color);
if (distSq < bestDistSq)
{
bestDistSq = distSq;
bestColor = paintColor;
}
}
return bestColor.Name;
}
}
}
|