Beispiel #1
0
        public static Color ClosestColor(Color c, Color[] cs)
        {
            int num = ColorEx.ClosestColorIndex(c, cs);

            if (num > -1)
            {
                return(cs[num]);
            }
            return(default(Color));
        }
Beispiel #2
0
        public static int ClosestColorIndex(Color c, Color[] cs)
        {
            int   result = -1;
            float num    = float.MaxValue;

            for (int i = 0; i < cs.Length; i++)
            {
                float num2 = ColorEx.SqrEuclideanDistance(c, cs[i]);
                if (Mathf.Approximately(num2, 0f))
                {
                    result = i;
                    break;
                }
                if (num2 < num)
                {
                    num    = num2;
                    result = i;
                }
            }
            return(result);
        }