Files
@ ce4fe2190a12
Branch filter:
Location: ATITD-Tools/Desert-Paint-Lab/Palette.cs - annotation
ce4fe2190a12
2.6 KiB
text/x-csharp
Fix another bug in computing the swatch area
63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c 63ce80f17b8c | /*
* Copyright (c) 2010, Tess Snider
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
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 static List<PaintColor> Colors
{
get {
return colors;
}
}
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 int Count
{
get
{
return colors.Count;
}
}
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;
}
}
}
|