/// <summary>
        /// Splits this cube's color list at median index, and returns two newly created cubes.
        /// </summary>
        /// <param name="componentIndex">Index of the component (red = 0, green = 1, blue = 2).</param>
        /// <param name="firstMedianCutCube">The first created cube.</param>
        /// <param name="secondMedianCutCube">The second created cube.</param>
        public void SplitAtMedian(Byte componentIndex, out MedianCutCube firstMedianCutCube, out MedianCutCube secondMedianCutCube)
        {
            List <Int32> colors;

            switch (componentIndex)
            {
            // red colors
            case 0:
                colors = colorList.OrderBy(argb => ColorModelHelper.GetComponentA(ColorModel, TextureBitmap.Color.FromARGB(argb))).ToList();
                break;

            // green colors
            case 1:
                colors = colorList.OrderBy(argb => ColorModelHelper.GetComponentB(ColorModel, TextureBitmap.Color.FromARGB(argb))).ToList();
                break;

            // blue colors
            case 2:
                colors = colorList.OrderBy(argb => ColorModelHelper.GetComponentC(ColorModel, TextureBitmap.Color.FromARGB(argb))).ToList();
                break;

            default:
                throw new NotSupportedException("Only three color components are supported (R, G and B).");
            }

            // retrieves the median index (a half point)
            Int32 medianIndex = colorList.Count >> 1;

            // creates the two half-cubes
            firstMedianCutCube  = new MedianCutCube(colors.GetRange(0, medianIndex));
            secondMedianCutCube = new MedianCutCube(colors.GetRange(medianIndex, colors.Count - medianIndex));
        }
        /// <summary>
        /// Determines whether the color is in the space of this cube.
        /// </summary>
        /// <param name="color">The color to be checked, if it's contained in this cube.</param>
        /// <returns>if true a color is in the space of this cube, otherwise returns false.</returns>
        public Boolean IsColorIn(TextureBitmap.Color color)
        {
            Int32 red   = ColorModelHelper.GetComponentA(ColorModel, color);
            Int32 green = ColorModelHelper.GetComponentB(ColorModel, color);
            Int32 blue  = ColorModelHelper.GetComponentC(ColorModel, color);

            return((red >= redLowBound && red <= redHighBound) &&
                   (green >= greenLowBound && green <= greenHighBound) &&
                   (blue >= blueLowBound && blue <= blueHighBound));
        }
        /// <summary>
        /// Shrinks this cube to the least dimensions that covers all the colors in the RGB space.
        /// </summary>
        private void Shrink()
        {
            redLowBound  = greenLowBound = blueLowBound = 255;
            redHighBound = greenHighBound = blueHighBound = 0;

            foreach (Int32 argb in colorList)
            {
                TextureBitmap.Color color = TextureBitmap.Color.FromARGB(argb);

                Int32 red   = ColorModelHelper.GetComponentA(ColorModel, color);
                Int32 green = ColorModelHelper.GetComponentB(ColorModel, color);
                Int32 blue  = ColorModelHelper.GetComponentC(ColorModel, color);

                if (red < redLowBound)
                {
                    redLowBound = red;
                }
                if (red > redHighBound)
                {
                    redHighBound = red;
                }
                if (green < greenLowBound)
                {
                    greenLowBound = green;
                }
                if (green > greenHighBound)
                {
                    greenHighBound = green;
                }
                if (blue < blueLowBound)
                {
                    blueLowBound = blue;
                }
                if (blue > blueHighBound)
                {
                    blueHighBound = blue;
                }
            }
        }