public void Math_Interp_SCurve3_Somewhere_Test_2() { double v = 0.9; double expected = 0.972; Assert.AreEqual(expected, NoiseMath.SCurve3(v)); }
public void Math_Interp_SCurve3_Somewhere_Test_1() { double v = 0.333; double expected = 0.258815; Assert.AreEqual(expected, Math.Round(NoiseMath.SCurve3(v), 6)); }
public void Math_Interp_SCurve3_Middle_Test() { double v = 0.5; double expected = 0.5; Assert.AreEqual(expected, NoiseMath.SCurve3(v)); }
public void Math_Interp_SCurve3_Upper_Test() { double v = 1; double expected = 1; Assert.AreEqual(expected, NoiseMath.SCurve3(v)); }
internal static double GradientCoherentNoise(double x, double y, double z, int seed, NoiseQuality noiseQuality) { int x0 = (x > 0.0 ? (int)x : (int)x - 1); int x1 = x0 + 1; int y0 = (y > 0.0 ? (int)y : (int)y - 1); int y1 = y0 + 1; int z0 = (z > 0.0 ? (int)z : (int)z - 1); int z1 = z0 + 1; double xs = 0, ys = 0, zs = 0; switch (noiseQuality) { case NoiseQuality.Low: xs = (x - x0); ys = (y - y0); zs = (z - z0); break; case NoiseQuality.Standard: xs = NoiseMath.SCurve3(x - x0); ys = NoiseMath.SCurve3(y - y0); zs = NoiseMath.SCurve3(z - z0); break; case NoiseQuality.High: xs = NoiseMath.SCurve5(x - x0); ys = NoiseMath.SCurve5(y - y0); zs = NoiseMath.SCurve5(z - z0); break; } double n0 = GradientNoise(x, y, z, x0, y0, z0, seed); double n1 = GradientNoise(x, y, z, x1, y0, z0, seed); double ix0 = NoiseMath.LinearInterpolate(n0, n1, xs); n0 = GradientNoise(x, y, z, x0, y1, z0, seed); n1 = GradientNoise(x, y, z, x1, y1, z0, seed); double ix1 = NoiseMath.LinearInterpolate(n0, n1, xs); double iy0 = NoiseMath.LinearInterpolate(ix0, ix1, ys); n0 = GradientNoise(x, y, z, x0, y0, z1, seed); n1 = GradientNoise(x, y, z, x1, y0, z1, seed); ix0 = NoiseMath.LinearInterpolate(n0, n1, xs); n0 = GradientNoise(x, y, z, x0, y1, z1, seed); n1 = GradientNoise(x, y, z, x1, y1, z1, seed); ix1 = NoiseMath.LinearInterpolate(n0, n1, xs); double iy1 = NoiseMath.LinearInterpolate(ix0, ix1, ys); return(NoiseMath.LinearInterpolate(iy0, iy1, zs)); }
/// <summary> /// See the documentation on the base class. /// <seealso cref="Module"/> /// </summary> /// <param name="x">X coordinate</param> /// <param name="y">Y coordinate</param> /// <param name="z">Z coordinate</param> /// <returns>Returns the computed value</returns> public override double GetValue(double x, double y, double z) { var controlValue = SourceModules[2].GetValue(x, y, z); double alpha; if (EdgeFalloff > 0.0) { if (controlValue < (LowerBound - EdgeFalloff)) { // The output value from the control module is below the selector // threshold; return the output value from the first source module. return(SourceModules[0].GetValue(x, y, z)); } else if (controlValue < (LowerBound + EdgeFalloff)) { // The output value from the control module is near the lower end of the // selector threshold and within the smooth curve. Interpolate between // the output values from the first and second source modules. double lowerCurve = (LowerBound - EdgeFalloff); double upperCurve = (LowerBound + EdgeFalloff); alpha = NoiseMath.SCurve3((controlValue - lowerCurve) / (upperCurve - lowerCurve)); return(NoiseMath.Linear(SourceModules[0].GetValue(x, y, z), SourceModules[1].GetValue(x, y, z), alpha)); } else if (controlValue < (UpperBound - EdgeFalloff)) { // The output value from the control module is within the selector // threshold; return the output value from the second source module. return(SourceModules[1].GetValue(x, y, z)); } else if (controlValue < (UpperBound + EdgeFalloff)) { // The output value from the control module is near the upper end of the // selector threshold and within the smooth curve. Interpolate between // the output values from the first and second source modules. double lowerCurve = (UpperBound - EdgeFalloff); double upperCurve = (UpperBound + EdgeFalloff); alpha = NoiseMath.SCurve3((controlValue - lowerCurve) / (upperCurve - lowerCurve)); return(NoiseMath.Linear(SourceModules[1].GetValue(x, y, z), SourceModules[0].GetValue(x, y, z), alpha)); } else { // Output value from the control module is above the selector threshold; // return the output value from the first source module. return(SourceModules[0].GetValue(x, y, z)); } } else { if (controlValue < LowerBound || controlValue > UpperBound) { return(SourceModules[0].GetValue(x, y, z)); } else { return(SourceModules[1].GetValue(x, y, z)); } } }
public override double GetValue(double x, double y, double z) { if (ModuleA == null) { throw new InvalidOperationException("ModuleA cannot be null"); } if (ModuleB == null) { throw new InvalidOperationException("ModuleB cannot be null"); } if (ControlModule == null) { throw new InvalidOperationException("Control cannot be null"); } double controlValue = ControlModule.GetValue(x, y, z); if (edgeFalloff > 0.0) { if (controlValue < (LowerBound - edgeFalloff)) { // The output value from the control module is below the selector // threshold; return the output value from the first source module. return(ModuleA.GetValue(x, y, z)); } double alpha; if (controlValue < (LowerBound + edgeFalloff)) { // The output value from the control module is near the lower end of the // selector threshold and within the smooth curve. Interpolate between // the output values from the first and second source modules. double lowerCurve = (LowerBound - edgeFalloff); double upperCurve = (LowerBound + edgeFalloff); alpha = NoiseMath.SCurve3((controlValue - lowerCurve) / (upperCurve - lowerCurve)); return(NoiseMath.LinearInterpolate(ModuleA.GetValue(x, y, z), ModuleB.GetValue(x, y, z), alpha)); } if (controlValue < (UpperBound - edgeFalloff)) { // The output value from the control module is within the selector // threshold; return the output value from the second source module. return(ModuleB.GetValue(x, y, z)); } if (controlValue < (UpperBound + edgeFalloff)) { // The output value from the control module is near the upper end of the // selector threshold and within the smooth curve. Interpolate between // the output values from the first and second source modules. double lowerCurve = (UpperBound - edgeFalloff); double upperCurve = (UpperBound + edgeFalloff); alpha = NoiseMath.SCurve3((controlValue - lowerCurve) / (upperCurve - lowerCurve)); return(NoiseMath.LinearInterpolate(ModuleB.GetValue(x, y, z), ModuleA.GetValue(x, y, z), alpha)); } // Output value from the control module is above the selector threshold; // return the output value from the first source module. return(ModuleA.GetValue(x, y, z)); } if (controlValue < LowerBound || controlValue > UpperBound) { return(ModuleA.GetValue(x, y, z)); } return(ModuleB.GetValue(x, y, z)); }
public void SCurve3Test(double a, double expected) { Assert.Equal(expected, NoiseMath.SCurve3(a), 6); }