Net.Bluewalk.DotNetUtils/Extensions/IntegerExtensions.cs
/// <summary>
/// Maps integer values to given constraints
/// </summary>
/// <param name="value">The value.</param>
/// <param name="oldFrom">The old from.</param>
/// <param name="oldTo">The old to.</param>
/// <param name="newFrom">The new from.</param>
/// <param name="newTo">The new to.</param>
/// <returns>System.Int32.</returns>
Maps integer values to given constraints
Maps integer values to given constraints
public static int Map(this int value, int oldFrom, int oldTo, int newFrom, int newTo)
        {
            var scale = (double) (newTo - newFrom) / (oldTo - oldFrom);
            return (int) Math.Ceiling(newFrom + (value - oldFrom) * scale);
        }
public static int Map ( this int value , int oldFrom , int oldTo , int newFrom , int newTo ) { var scale = ( double ) ( newTo - newFrom ) / ( oldTo - oldFrom ) ; return ( int ) Math . Ceiling ( newFrom + ( value - oldFrom ) * scale ) ; }
Maps integer values to given constraints
Maps integer values to given constraints
None
int
this
oldFrom
int
The old from.
The old from .
oldTo
int
The old to.
The old to .
newFrom
int
The new from.
The new from .
newTo
int
The new to.
The new to .
value
None