fCraft.Drawing.BlockPalette.FindBestMatch C# (CSharp) Method

FindBestMatch() private method

private FindBestMatch ( System.Drawing.Color color ) : Block[]
color System.Drawing.Color
return Block[]
        public Block[] FindBestMatch( RgbColor color )
        {
            if( color.A < TransparencyThreshold*255 ) {
                return transparent;
            }
            LabColor pixelColor = RgbToLab( color, true );
            double closestDistance = double.MaxValue;
            Block[] bestMatch = null;
            foreach( var pair in palette ) {
                double distance = ColorDifference( pixelColor, pair.Key );
                if( distance < closestDistance ) {
                    bestMatch = pair.Value;
                    closestDistance = distance;
                }
            }
            if( bestMatch == null ) {
                throw new Exception( "Could not find match: palette is empty!" );
            }
            return bestMatch;
        }