using System.Diagnostics;
namespace LibNoise.Operator
{
///
/// Provides a noise module that outputs a weighted blend of the output values from
/// two source modules given the output value supplied by a control module. [OPERATOR]
///
public class Blend : ModuleBase
{
#region Constructors
///
/// Initializes a new instance of Blend.
///
public Blend()
: base(3)
{
}
///
/// Initializes a new instance of Blend.
///
/// The left hand input module.
/// The right hand input module.
/// The controller of the operator.
public Blend(ModuleBase lhs, ModuleBase rhs, ModuleBase controller)
: base(3)
{
Modules[0] = lhs;
Modules[1] = rhs;
Modules[2] = controller;
}
#endregion
#region Properties
///
/// Gets or sets the controlling module.
///
public ModuleBase Controller
{
get { return Modules[2]; }
set
{
Debug.Assert(value != null);
Modules[2] = value;
}
}
#endregion
#region ModuleBase Members
///
/// Returns the output value for the given input coordinates.
///
/// The input coordinate on the x-axis.
/// The input coordinate on the y-axis.
/// The input coordinate on the z-axis.
/// The resulting output value.
public override double GetValue(double x, double y, double z)
{
Debug.Assert(Modules[0] != null);
Debug.Assert(Modules[1] != null);
Debug.Assert(Modules[2] != null);
var a = Modules[0].GetValue(x, y, z);
var b = Modules[1].GetValue(x, y, z);
var c = (Modules[2].GetValue(x, y, z) + 1.0) / 2.0;
return Utils.InterpolateLinear(a, b, c);
}
#endregion
}
}