Beispiel #1
0
        /// <summary>
        /// Given the two colors the function returns the pair number corresponding to them
        /// </summary>
        /// <param name="pair">Color pair with major and minor color</param>
        /// <returns></returns>
        internal static int GetPairNumberFromColor(ColorMap.ColorPair pair)
        {
            ColorMap obj = new ColorMap();
            // Find the major color in the array and get the index
            int majorIndex = -1;

            for (int i = 0; i < obj.ColorMapMajor.Length; i++)
            {
                if (obj.ColorMapMajor[i] == pair.majorColor)
                {
                    majorIndex = i;
                    break;
                }
            }

            // Find the minor color in the array and get the index
            int minorIndex = -1;

            for (int i = 0; i < obj.ColorMapMinor.Length; i++)
            {
                if (obj.ColorMapMinor[i] == pair.minorColor)
                {
                    minorIndex = i;
                    break;
                }
            }
            // If colors can not be found throw an exception
            if (majorIndex == -1 || minorIndex == -1)
            {
                throw new ArgumentException(
                          string.Format("Unknown Colors: {0}", pair.ToString()));
            }

            // Compute pair number and Return
            // (Note: +1 in compute is because pair number is 1 based, not zero)
            return((majorIndex * obj.ColorMapMinor.Length) + (minorIndex + 1));
        }