Ejemplo n.º 1
0
        /// <summary>
        /// Scales a value by (max - min), then divides it by scale and adds it to min
        /// </summary>
        /// <param name="scale">An optional scale value for integer types (default 1)</param>
        public static T FractionToValue <T> (T fraction, T min, T max, T?scale = null)
            where T : struct
        {
            var range = OperatorCache <T> .Subtract(max, min);

            var global = OperatorCache <T> .Multiply(fraction, range);

            if (scale != null)
            {
                global = OperatorCache <T> .Divide(global, scale.Value);
            }
            return(OperatorCache <T> .Add(min, global));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Clamps a value to the range (min, max) then scales it to the range (0, scale)
        /// </summary>
        /// <param name="scale">An optional scale value for integer types (default 1)</param>
        public static T Fraction <T> (T value, T min, T max, T?scale = null)
            where T : struct
        {
            var range = OperatorCache <T> .Subtract(max, min);

            var relative = OperatorCache <T> .Subtract(value, min);

            if (scale != null)
            {
                relative = OperatorCache <T> .Multiply(relative, scale.Value);
            }
            return(OperatorCache <T> .Divide(relative, range));
        }
Ejemplo n.º 3
0
 public static T Multiply <T, TU>(T x, TU y)
 {
     return(OperatorCache <T, TU> .Multiply(x, y));
 }