/// /// The smaller the number returned by this, the closer the colors are /// /// /// public float CompareTo(ColorFormulas oComparisionColor) { // Based upon the Delta-E (1976) formula at easyrgb.com (http://www.easyrgb.com/index.php?X=DELT&H=03#text3) double DeltaE = Math.Sqrt(Math.Pow((CieL - oComparisionColor.CieL), 2) + Math.Pow((CieA - oComparisionColor.CieA), 2) + Math.Pow((CieB - oComparisionColor.CieB), 2)); return(Mathf.Round((float)DeltaE)); }
public static float DoFullCompare(Color a, Color b) { ColorFormulas oColor1 = new ColorFormulas(a.r, a.g, a.b); ColorFormulas oColor2 = new ColorFormulas(b.r, b.g, b.b); return(oColor1.CompareTo(oColor2)); }
Tile findClosestTile(List <Tile> tilesList, Color c) { var smallestDifference = Double.MaxValue; Tile closestTile = null; // express the colour as a Delta-E colour to be used in the colour distance calculations ColorFormulas deltaEPixelcolor = new ColorFormulas(c.R, c.G, c.B); foreach (Tile tile in tilesList) { // ignore all tiles that have been disabled if (tile.enabled == false) { continue; } // calculate the colour difference using the Delta-E formulas var deltaEDifference = tile.colorFormulas.CompareTo(deltaEPixelcolor); if ((deltaEDifference < smallestDifference)) { smallestDifference = deltaEDifference; closestTile = tile; } } return(closestTile); }