public int GetPairNumberFromColor(ColorPair pair)
        {
            // Find the major color in the array and get the index
            int            majorIndex = -1;
            DrivingProgram dp         = new DrivingProgram();

            for (int i = 0; i < dp.colorMapMajor.Length; i++)
            {
                if (dp.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 < dp.colorMapMinor.Length; i++)
            {
                if (dp.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 * dp.colorMapMinor.Length) + (minorIndex + 1));
        }
Beispiel #2
0
        /// <summary>
        /// Given a pair number function returns the major and minor colors in that order
        /// </summary>
        /// <param name="pairNumber">Pair number of the color to be fetched</param>
        /// <returns></returns>
        private static ColorPair GetColorFromPairNumber(int pairNumber)
        {
            // The function supports only 1 based index. Pair numbers valid are from 1 to 25
            int minorSize = colorMapMinor.Length;
            int majorSize = colorMapMajor.Length;

            if (pairNumber < 1 || pairNumber > minorSize * majorSize)
            {
                throw new ArgumentOutOfRangeException(
                          string.Format("Argument PairNumber:{0} is outside the allowed range", pairNumber));
            }

            // Find index of major and minor color from pair number
            int zeroBasedPairNumber = pairNumber - 1;
            int majorIndex          = zeroBasedPairNumber / minorSize;
            int minorIndex          = zeroBasedPairNumber % minorSize;

            // Construct the return val from the arrays
            ColorPair pair = new ColorPair()
            {
                majorColor = colorMapMajor[majorIndex],
                minorColor = colorMapMinor[minorIndex]
            };

            // return the value
            return(pair);
        }
Beispiel #3
0
        internal ColorPair(int number)
        {
            ColorPair temp = GetMethods.GetColorFromPairNumber(number);

            this.majorColor = temp.majorColor;
            this.minorColor = temp.minorColor;
        }
Beispiel #4
0
        internal static void TestByPairNumber(ColorPair pair, int actual_number)
        {
            int pairNumber_calulated;

            pairNumber_calulated = GetMethods.GetPairNumberFromColor(pair);
            Debug.Assert(pairNumber_calulated == actual_number);
        }
Beispiel #5
0
        internal void changeByNumber(int pairNumber)
        {
            ColorPair temp = GetMethods.GetColorFromPairNumber(pairNumber);

            this.majorColor = temp.majorColor;
            this.minorColor = temp.minorColor;
        }
Beispiel #6
0
        public int GetPairNumberFromColor(ColorPair pair)
        {
            int majorIndex = -1;

            for (int i = 0; i < space.getColorMapMajor().Length; i++)
            {
                if ((Color)space.getColorMapMajor().GetValue(i) == pair.majorColor)
                {
                    majorIndex = i;
                    break;
                }
            }

            int minorIndex = -1;

            for (int i = 0; i < space.getColorMapMinor().Length; i++)
            {
                if ((Color)space.getColorMapMinor().GetValue(i) == pair.minorColor)
                {
                    minorIndex = i;
                    break;
                }
            }
            if (majorIndex == -1 || minorIndex == -1)
            {
                throw new ArgumentException(
                          string.Format("Unknown Colors: {0}", pair.ToString()));
            }


            return((majorIndex * space.getColorMapMinor().Length) + (minorIndex + 1));
        }
        /// <summary>
        /// Test code for the class
        /// </summary>
        /// <param name="args"></param>
        private static void Main(string[] args)
        {
            int       pairNumber = 4;
            ColorPair testPair1  = Program.GetColorFromPairNumber(pairNumber);

            Console.WriteLine("[In]Pair Number: {0},[Out] Colors: {1}\n", pairNumber, testPair1);
            Debug.Assert(testPair1.majorColor == Color.White);
            Debug.Assert(testPair1.minorColor == Color.Brown);

            pairNumber = 23;
            testPair1  = Program.GetColorFromPairNumber(pairNumber);
            Console.WriteLine("[In]Pair Number: {0},[Out] Colors: {1}\n", pairNumber, testPair1);
            Debug.Assert(testPair1.majorColor == Color.Violet);
            Debug.Assert(testPair1.minorColor == Color.Green);

            ColorPair testPair2 = new ColorPair()
            {
                majorColor = Color.Yellow, minorColor = Color.Green
            };

            pairNumber = Program.GetPairNumberFromColor(testPair2);
            Console.WriteLine("[In]Colors: {0}, [Out] PairNumber: {1}\n", testPair2, pairNumber);
            Debug.Assert(pairNumber == 18);

            testPair2 = new ColorPair()
            {
                majorColor = Color.Red, minorColor = Color.Blue
            };
            pairNumber = Program.GetPairNumberFromColor(testPair2);
            Console.WriteLine("[In]Colors: {0}, [Out] PairNumber: {1}", testPair2, pairNumber);
            Debug.Assert(pairNumber == 6);
        }
        public static int GetPairNumberFromColor(ColorPair pair)
        {
            int majorIndex = -1;

            for (int i = 0; i < ColorCodeConstant.colorMapMajor.Length; i++)
            {
                if (ColorCodeConstant.colorMapMajor[i] == pair.majorColor)
                {
                    majorIndex = i;
                    break;
                }
            }
            int minorIndex = -1;

            for (int i = 0; i < ColorCodeConstant.colorMapMinor.Length; i++)
            {
                if (ColorCodeConstant.colorMapMinor[i] == pair.minorColor)
                {
                    minorIndex = i;
                    break;
                }
            }
            if (majorIndex == -1 || minorIndex == -1)
            {
                throw new ArgumentException(
                          string.Format("Unknown Colors: {0}", pair.ToString()));
            }
            return((majorIndex * ColorCodeConstant.colorMapMinor.Length) + (minorIndex + 1));
        }
        /// <summary>
        /// Test code for the class
        /// </summary>
        /// <param name="args"></param>
        private static void Main(string[] args)
        {
            int       pairNumber = 4;
            ColorPair testPair1  = new ColorPair(pairNumber);

            Console.WriteLine("[In]Pair Number: {0},[Out] Colors: {1}\n", pairNumber, testPair1);
            Test.TestByColorCode(testPair1, Color.White, Color.Brown);

            pairNumber = 5;
            testPair1.changeByNumber(pairNumber);
            Console.WriteLine("[In]Pair Number: {0},[Out] Colors: {1}\n", pairNumber, testPair1);
            Test.TestByColorCode(testPair1, Color.White, Color.SlateGray);

            pairNumber = 23;
            testPair1.changeByNumber(pairNumber);
            Console.WriteLine("[In]Pair Number: {0},[Out] Colors: {1}\n", pairNumber, testPair1);
            Test.TestByColorCode(testPair1, Color.Violet, Color.Green);

            ColorPair testPair2 = new ColorPair(Color.Yellow, Color.Green);

            pairNumber = GetMethods.GetPairNumberFromColor(testPair2);
            Console.WriteLine("[In]Colors: {0}, [Out] PairNumber: {1}\n", testPair2, pairNumber);
            Test.TestByPairNumber(testPair2, 18);

            testPair2.changeByColor(Color.Red, Color.Blue);
            pairNumber = GetMethods.GetPairNumberFromColor(testPair2);
            Console.WriteLine("[In]Colors: {0}, [Out] PairNumber: {1}\n", testPair2, pairNumber);
            Test.TestByPairNumber(testPair2, 6);

            string manual = ColorCodeData.manualToString();

            Console.WriteLine(manual);
        }
        //This function will give some input and Test
        public void Test()
        {
            int       pairNumber = 4;
            ColorPair testPair1  = ColorMapper.GetColorFromPairNumber(pairNumber);

            Console.WriteLine("[In]Pair Number: {0},[Out] Colors: {1}\n", pairNumber, testPair1);
            Debug.Assert(testPair1.MajorColor == Color.White);
            Debug.Assert(testPair1.MinorColor == Color.Brown);
            Debug.Assert(testPair1.ToString() == "MajorColor:White, MinorColor:Brown");


            pairNumber = 5;
            testPair1  = ColorMapper.GetColorFromPairNumber(pairNumber);
            Console.WriteLine("[In]Pair Number: {0},[Out] Colors: {1}\n", pairNumber, testPair1);
            Debug.Assert(testPair1.MajorColor == System.Drawing.Color.White);
            Debug.Assert(testPair1.MinorColor == System.Drawing.Color.SlateGray);
            Debug.Assert(testPair1.ToString() == "MajorColor:White, MinorColor:SlateGray");


            pairNumber = 23;
            testPair1  = ColorMapper.GetColorFromPairNumber(pairNumber);
            Console.WriteLine("[In]Pair Number: {0},[Out] Colors: {1}\n", pairNumber, testPair1);
            Debug.Assert(testPair1.MajorColor == System.Drawing.Color.Violet);
            Debug.Assert(testPair1.MinorColor == System.Drawing.Color.Green);
            Debug.Assert(testPair1.ToString() == "MajorColor:Violet, MinorColor:Green");
        }
Beispiel #11
0
        internal static void TestNumbertoPair(int pairNumber, Color expectedMajor, Color expectedminor)
        {
            ColorPair testPair = ColorMap.GetColorFromPairNumber(pairNumber);

            Console.WriteLine("[In]Pair Number: {0},[Out] Colors: {1}\n", pairNumber, testPair);
            Debug.Assert(testPair.MajorColor == expectedMajor);
            Debug.Assert(testPair.MinorColor == expectedminor);
        }
Beispiel #12
0
        internal static void TestPairtoNumber(Color major, Color minor, int expectedPairNumber)
        {
            ColorPair testPair2  = new ColorPair(major, minor);
            int       pairNumber = ColorMap.GetPairNumberFromColor(testPair2);

            Console.WriteLine("[In]Colors: {0}, [Out] PairNumber: {1}\n", testPair2, pairNumber);
            Debug.Assert(pairNumber == expectedPairNumber);
        }
        public override string ToString()
        {
            string colorCodes = "";

            for (int i = 1; i < 26; i++)
            {
                ColorPair pair = ColorCodingPairNumber.GetColorFromPairNumber(i);
                colorCodes = colorCodes + "PAIR NUMBER = " + i + " " + "MAJOR COLOR = " + " " + pair.majorColor + "MINOR COLOR = " + " " + pair.minorColor + "\n";
            }
            return(colorCodes);
        }
        /// <summary>
        ///  Given the inbuilt colors and pair number the function return the mapping using TOString method implimentation.
        /// </summary>

        public override string  ToString()
        {
            string colorPairMapping = " ";

            for (int pairNumber = 1; pairNumber <= 25; pairNumber++)
            {
                ColorPair colorPair = GetColorPair.GetColorFromPairNumber(pairNumber);
                colorPairMapping += pairNumber + "\t" + colorPair + "\n";
            }
            return(colorPairMapping);
        }
Beispiel #15
0
        public override string ToString()
        {
            string mapOfPairNumberToColor = "";

            for (int i = 1; i <= colorMapMajor.Length * colorMapMinor.Length; i++)
            {
                ColorPair pair = GetColorFromPairNumber(i);
                mapOfPairNumberToColor += string.Format("PairNumber:{0}, {1}\n", i, pair.ToString());
            }
            return(mapOfPairNumberToColor);
        }
        public override string ToString()
        {
            string colorCodes = "";

            for (int pairNo = 1; pairNo <= colorMapMinor.Length * colorMapMajor.Length; pairNo++)
            {
                ColorPair pair = NumToColor.GetColorFromPairNumber(pairNo);
                colorCodes += "Pair Num: " + pairNo + "  Colors: " + pair + "\n";
            }
            return(colorCodes);
        }
Beispiel #17
0
        public override string ToString() //overrides the ToString() in ColorLists
        {
            string colorCodeWithColors = "";

            for (int pairNo = 1; pairNo <= ColorMapMinor.Length * ColorMapMajor.Length; pairNo++)
            {
                ColorPair pair = NumberToColor.GetColorFromPairNumber(pairNo);
                colorCodeWithColors += "Pair Number : " + pairNo + "   Colors : " + pair + "\n";
            }

            return(colorCodeWithColors);
        }
        //prints the manual for the given range of codes
        public string ToString(int fromCode, int toCode)
        {
            string colorCodeWithColors = "";

            for (int pairNumber = fromCode; pairNumber <= toCode; pairNumber++)
            {
                ColorPair pair = ColorPair.GetColorFromPairNumber(pairNumber);
                colorCodeWithColors += "Pair Number : " + pairNumber + "   Colors : " + pair + "\n";
            }

            return(colorCodeWithColors);
        }
        private static void GenerateManual()
        {
            int numberOfColors = ColorMaps.colorMapMajor.Length * ColorMaps.colorMapMinor.Length;

            OutputToFile = "Welcome to Number - colorPair mapping file...\n";
            for (int i = 1; i <= numberOfColors; i++)
            {
                ColorPair colorPair         = DriverMethods.GetColorFromPairNumber(i);
                string    colorPairInString = colorPair.ToString();
                OutputToFile += i + ": " + colorPairInString + "\n";
            }
        }
Beispiel #20
0
        internal static int GetPairNumberFromColor(ColorPair pair)
        {
            int majorIndex = IndexHelper.getColorIndex(pair.MajorColor, colorMapMajor);
            int minorIndex = IndexHelper.getColorIndex(pair.MinorColor, colorMapMinor);

            if (majorIndex == -1 || minorIndex == -1)
            {
                throw new ArgumentException(
                          string.Format("Unknown Colors: {0}", pair.ToString()));
            }
            return((majorIndex * colorMapMinor.Length) + (minorIndex + 1));
        }
        public override string ToString()
        {
            int    totalCombinations = CopyOfColorMapMajor.Length * CopyOfColorMapMinor.Length;
            String Result            = null;

            for (int pairno = 1; pairno <= totalCombinations; pairno++)
            {
                ColorPair pair = ColorFromPair.GetColorFromPairNumber(pairno);
                Result += "Pair number: " + pairno.ToString() + " " + "Color Pair: " + pair.ToString() + '\n';
            }
            return(Result);
        }
Beispiel #22
0
        /// <summary>
        /// Test code for the class
        /// </summary>
        /// <param name="args"></param>
        private static void Main()
        {
            int       pairNumber = 4;
            ColorPair testPair1  = ColorPair.GetColorFromPairNumber(pairNumber);

            Console.WriteLine("[In]Pair Number: {0},[Out] Colors: {1}\n", pairNumber, testPair1);
            Debug.Assert(testPair1.majorColor == Color.White);
            Debug.Assert(testPair1.minorColor == Color.Brown);

            pairNumber = 5;
            testPair1  = ColorPair.GetColorFromPairNumber(pairNumber);
            Console.WriteLine("[In]Pair Number: {0},[Out] Colors: {1}\n", pairNumber, testPair1);
            Debug.Assert(testPair1.majorColor == Color.White);
            Debug.Assert(testPair1.minorColor == Color.SlateGray);

            pairNumber = 23;
            testPair1  = ColorPair.GetColorFromPairNumber(pairNumber);
            Console.WriteLine("[In]Pair Number: {0},[Out] Colors: {1}\n", pairNumber, testPair1);
            Debug.Assert(testPair1.majorColor == Color.Violet);
            Debug.Assert(testPair1.minorColor == Color.Green);

            ColorPair testPair2 = new ColorPair()
            {
                majorColor = Color.Yellow, minorColor = Color.Green
            };

            pairNumber = PairNumber.GetPairNumberFromColor(testPair2);
            Console.WriteLine("[In]Colors: {0}, [Out] PairNumber: {1}\n", testPair2, pairNumber);
            Debug.Assert(pairNumber == 18);

            testPair2 = new ColorPair()
            {
                majorColor = Color.Red, minorColor = Color.Blue
            };
            pairNumber = PairNumber.GetPairNumberFromColor(testPair2);
            Console.WriteLine("[In]Colors: {0}, [Out] PairNumber: {1}\n\n", testPair2, pairNumber);
            Debug.Assert(pairNumber == 6);

            CodeManual codeManual = new CodeManual();

            Console.WriteLine(codeManual.ToString());

            string testString1 = codeManual.ToString(20);

            Console.WriteLine(testString1);
            Debug.Assert(testString1.Equals("Pair Number : 20   Colors : MajorColor:Yellow, MinorColor:SlateGray\n"));

            string testString2 = codeManual.ToString(2, 3);

            Console.WriteLine(testString2);
            Debug.Assert(testString2.Equals("Pair Number : 2   Colors : MajorColor:White, MinorColor:Orange\nPair Number : 3   Colors : MajorColor:White, MinorColor:Green\n"));
        }
Beispiel #23
0
        /// <summary>
        /// Gives a big string containing the pair number corresponding to their major and minor colors
        /// </summary>
        /// <returns></returns>

        private static string showAllPairsInString()
        {
            Console.WriteLine("\n-----REFERENCE MANUAL-----\n");
            string refManual      = "";
            int    noOfColorPairs = colorMapMinor.Length * colorMapMajor.Length;

            for (int pairNo = 1; pairNo <= noOfColorPairs; pairNo++)
            {
                ColorPair majorMinorColorPair = GetColorFromPairNumber(pairNo);
                refManual += "(" + pairNo.ToString() + "->" + majorMinorColorPair.ToString() + ")" + "\n";
            }
            return(refManual);
        }
 public static int GetPairNumberFromColor(ColorPair pair)
 {
     int majorIndex = -1;
     majorIndex = CheckColorandReturnIndex(ColourSpace.getColorMapMajor(), pair.majorColor);
     int minorIndex = -1;
     minorIndex = CheckColorandReturnIndex(ColourSpace.getColorMapMinor(), pair.minorColor);
     if (majorIndex == -1 || minorIndex == -1)
     {
         throw new ArgumentException(
             string.Format("Unknown Colors: {0}", pair.ToString()));
     }
     return (majorIndex * ColourSpace.getColorMapMinor().Length) + (minorIndex + 1);
 }
        internal void PrintReferenceManual()
        {
            Console.WriteLine("REFERENCE MANUAL");
            int minorSize = ListOfColors.MinorMapColor.Length;
            int majorSize = ListOfColors.MajorMapColor.Length;
            int totalSize = minorSize * majorSize;

            for (int i = 1; i <= totalSize; i++)
            {
                ColorPair pair = ColorFromPairNumber.GetColorFromPairNumber(i);
                Console.WriteLine("Pair No : " + i + " " + pair.ToString());
            }
        }
        public static int GetPairNumberFromColor(ColorPair pair)
        {
            int majorIndex = MajorIndexGet(pair);
            int minorIndex = MinorIndexGet(pair);

            // If colors can not be found throw an exception
            if (majorIndex == -1 || minorIndex == -1)
            {
                throw new ArgumentException(
                          string.Format("Unknown Colors: {0}", pair.ToString()));
            }

            return((majorIndex * colorMapMinor.Length) + (minorIndex + 1));
        }
        // Find the minor color in the array and get the index
        public static int CalculateMajorIndex(ColorPair pair)
        {
            int majorIndex = -1;

            for (int i = 0; i < colorMapMajor.Length; i++)
            {
                if (colorMapMajor[i] == pair.majorColor)
                {
                    majorIndex = i;
                    break;
                }
            }
            return(majorIndex);
        }
Beispiel #28
0
        public static int GetMinorIndex(ColorPair pair)
        {
            int minorIndex = -1;

            for (int i = 0; i < ColorMapMinor.Length; i++)
            {
                if (ColorMapMinor[i] == pair.minorColor)
                {
                    minorIndex = i;
                    break;
                }
            }
            return(minorIndex);
        }
Beispiel #29
0
        // Find the major color in the array and get the index
        public static int CalculateMajorColorIndex(ColorPair pair)
        {
            int calculateMajorIndex = -1;

            for (int i = 0; i < Program.returnLengthOfColorMapMajor(); i++)
            {
                if (Program.returnMajorColorFromColorMapMajor(i) == pair.majorColor)
                {
                    calculateMajorIndex = i;
                    break;
                }
            }
            return(calculateMajorIndex);
        }
Beispiel #30
0
        public override string ToString()
        {
            string majorminorcolorwithpairnumber = "";
            int    majorcolorlength = colorMapMajor.Length;
            int    minorcolorlength = colorMapMinor.Length;

            for (int pairNumber = 1; pairNumber <= majorcolorlength * minorcolorlength; pairNumber++)
            {
                ColorPair majorminorcolorpair = GetColor.GetColorFromPairNumber(pairNumber);
                Console.WriteLine("Pair Number: , Colors: \n", pairNumber, majorminorcolorpair);
                majorminorcolorwithpairnumber += "Pair Number : " + pairNumber + "   Colors : " + majorminorcolorpair + "\n";
            }
            return(majorminorcolorwithpairnumber);
        }