wasSharp

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 5  →  ?path2? @ 6
/Numerics.cs
@@ -4,6 +4,9 @@
// rights of fair usage, the disclaimer and warranty conditions. //
///////////////////////////////////////////////////////////////////////////
 
using System;
using System.Linq.Expressions;
 
namespace wasSharp
{
public class Numerics
@@ -15,26 +18,28 @@
/// Given a value in a source value range and a target range, map
/// the value from the source range into the target range.
/// </summary>
/// <param name="value">the value to map</param>
/// <param name="xMin">the lower bound of the source range</param>
/// <param name="xMax">the upper bound of the source range</param>
/// <param name="yMin">the lower bound of the target range</param>
/// <param name="yMax">the upper bound of the target range</param>
public static double MapValueToRange(double value, double xMin, double xMax, double yMin, double yMax)
{
return yMin + (
(
yMax - yMin
)
*
(
value - xMin
)
/
(
xMax - xMin
)
);
}
/// <remarks>
/// value - the value to map
/// xMin - the lower bound of the source range
/// xMax - the upper bound of the source range
/// yMin - the lower bound of the target range
/// yMax - the upper bound of the target range
/// </remarks>
/// <returns>a value in x mapped in the range of y</returns>
public static Func<double, double, double, double, double, double> MapValueToRange =
((Expression<Func<double, double, double, double, double, double>>)
((value, xMin, xMax, yMin, yMax) => yMin + (
(
yMax - yMin
)
*
(
value - xMin
)
/
(
xMax - xMin
)
))).Compile();
}
}