Example #1
0
        private static Colour ConvertToColor(IEnumerable <ColourPointValueMapping> points, int?x)
        {
            var hue = new Colour();

            if (x.HasValue)
            {
                var enumerated = points.ToList();
                x = FixValue(enumerated, x);

                ColourPointValueMapping smaller = GetSmallerValue(enumerated, x);
                if (smaller.Value == x)
                {
                    return(smaller.Colour);
                }
                ColourPointValueMapping larger = GetLargerValue(enumerated, x);
                if (larger.Value == x)
                {
                    return(larger.Colour);
                }

                hue.A = (byte)((larger.Colour.A - smaller.Colour.A) * (x.Value - smaller.Value) / (larger.Value - smaller.Value) + smaller.Colour.A);
                hue.R = (byte)((larger.Colour.R - smaller.Colour.R) * (x.Value - smaller.Value) / (larger.Value - smaller.Value) + smaller.Colour.R);
                hue.G = (byte)((larger.Colour.G - smaller.Colour.G) * (x.Value - smaller.Value) / (larger.Value - smaller.Value) + smaller.Colour.G);
                hue.B = (byte)((larger.Colour.B - smaller.Colour.B) * (x.Value - smaller.Value) / (larger.Value - smaller.Value) + smaller.Colour.B);
            }

            return(hue);
        }
Example #2
0
        private static int?ConvertToValue(IEnumerable <ColourPointValueMapping> points, double?x)
        {
            if (x.HasValue)
            {
                var enumerated = points.ToList();
                x = FixPoint(enumerated, x);

                ColourPointValueMapping smaller = GetSmallerPoint(enumerated, x);
                if (smaller.Point == x)
                {
                    return(smaller.Value);
                }
                ColourPointValueMapping larger = GetLargerPoint(enumerated, x);
                if (smaller.Point == x)
                {
                    return(larger.Value);
                }

                return((int)((larger.Value - smaller.Value) * (x.Value - smaller.Point) / (larger.Point - smaller.Point)) + smaller.Value);
            }
            return(null);
        }