//http://isotopescreencapture.codeplex.com/
//The MIT License (MIT)
namespace Isotope.Math
{
public static class MathUtil
{
///
/// Combines two input numbers in some proportion.
/// ratio=0.0 the first number is not used at all,
/// ratio=0.5 they are weight equally
/// ratio=1.0 the first number completely dominates the value
///
///
///
///
///
public static double Blend_0_1(double val0, double val1, double ratio)
{
var cratio = ClampToRange_0_1(ratio);
var v0 = val0*cratio;
var v1 = val1*(1.0 - cratio);
return v0 + v1;
}
///
/// Given an input value will force the value to fit within the range (min,max) inclusive
///
///
///
///
///
public static double ClampToRange(double v, double min, double max)
{
if (v < min)
{
v = min;
}
else if (v > max)
{
v = max;
}
return v;
}
///
/// Given an input value, will limit it to the range 0.0 and 1.0 inclusive
///
///
/// the clamped value
public static double ClampToRange_0_1(double v)
{
return ClampToRange(v, 0.0, 1.0);
}
}
}