SuperMap.Web.Mapping.HeatMapLayer.InterpolateColor C# (CSharp) Method

InterpolateColor() private static method

private static InterpolateColor ( float value, List stops ) : Color
value float
stops List
return Color
        private static Color InterpolateColor(float value, List<ThreadSafeGradientStop> stops)
        {
            if (value < 1 / 255f)
            {
                return Colors.Transparent;
            }
            if (stops == null || stops.Count == 0)
            {
                return Colors.Black;
            }
            if (stops.Count == 1)
            {
                return stops[0].Color;
            }

            if (stops[0].Offset >= value) //clip to bottom
            {
                return stops[0].Color;
            }
            else if (stops[stops.Count - 1].Offset <= value) //clip to top
            {
                return stops[stops.Count - 1].Color;
            }

            int i = 0;
            for (i = 1; i < stops.Count; i++)
            {
                if (stops[i].Offset > value)
                {
                    Color start = stops[i - 1].Color;
                    Color end = stops[i].Color;

                    double frac = (value - stops[i - 1].Offset) / (stops[i].Offset - stops[i - 1].Offset);
                    byte R = (byte)Math.Round((start.R * (1 - frac) + end.R * frac));
                    byte G = (byte)Math.Round((start.G * (1 - frac) + end.G * frac));
                    byte B = (byte)Math.Round((start.B * (1 - frac) + end.B * frac));
                    byte A = (byte)Math.Round((start.A * (1 - frac) + end.A * frac));
                    return Color.FromArgb(A, R, G, B);
                }
            }
            return stops[stops.Count - 1].Color;
        }