From 75042f1deb0309bcaa797c53c15c9f52c80c0b2a Mon Sep 17 00:00:00 2001 From: "Ricardo J. Mendez" Date: Thu, 17 Jul 2014 06:18:39 +0300 Subject: [PATCH 1/7] Code clean-up via ReSharper --- Generator/Billow.cs | 76 ++++---- Generator/Checker.cs | 12 +- Generator/Const.cs | 12 +- Generator/Cylinders.cs | 24 +-- Generator/Perlin.cs | 75 ++++---- Generator/RidgedMultifractal.cs | 93 +++++----- Generator/Spheres.cs | 26 +-- Generator/Voronoi.cs | 82 ++++----- GradientPresets.cs | 36 ++-- ModuleBase.cs | 58 ++++--- Noise2D.cs | 299 +++++++++++++++++--------------- Operator/Abs.cs | 13 +- Operator/Add.cs | 16 +- Operator/Blend.cs | 30 ++-- Operator/Cache.cs | 36 ++-- Operator/Clamp.cs | 48 ++--- Operator/Curve.cs | 67 +++---- Operator/Displace.cs | 50 +++--- Operator/Exponent.cs | 23 +-- Operator/Invert.cs | 12 +- Operator/Max.cs | 19 +- Operator/Min.cs | 19 +- Operator/Multiply.cs | 16 +- Operator/Power.cs | 17 +- Operator/Rotate.cs | 296 +++++++++++++++---------------- Operator/Scale.cs | 32 ++-- Operator/ScaleBias.cs | 28 +-- Operator/Select.cs | 109 ++++++------ Operator/Subtract.cs | 16 +- Operator/Terrace.cs | 74 ++++---- Operator/Translate.cs | 32 ++-- Operator/Turbulence.cs | 77 ++++---- Properties/AssemblyInfo.cs | 15 +- Utils.cs | 145 ++++++++-------- 34 files changed, 999 insertions(+), 984 deletions(-) diff --git a/Generator/Billow.cs b/Generator/Billow.cs index 20f5b95..e1295f6 100755 --- a/Generator/Billow.cs +++ b/Generator/Billow.cs @@ -1,9 +1,8 @@ -namespace LibNoise.Unity.Generator -{ - using System; - - using UnityEngine; +using System; +using UnityEngine; +namespace LibNoise.Unity.Generator +{ /// /// Provides a noise module that outputs a three-dimensional billowy noise. [GENERATOR] /// @@ -16,7 +15,7 @@ public class Billow : ModuleBase private QualityMode m_quality = QualityMode.Medium; private int m_octaveCount = 6; private double m_persistence = 0.5; - private int m_seed = 0; + private int m_seed; #endregion @@ -39,15 +38,16 @@ public Billow() /// The number of octaves of the billowy noise. /// The seed of the billowy noise. /// The quality of the billowy noise. - public Billow(double frequency, double lacunarity, double persistence, int octaves, int seed, QualityMode quality) + public Billow(double frequency, double lacunarity, double persistence, int octaves, int seed, + QualityMode quality) : base(0) { - this.Frequency = frequency; - this.Lacunarity = lacunarity; - this.OctaveCount = octaves; - this.Persistence = persistence; - this.Seed = seed; - this.Quality = quality; + Frequency = frequency; + Lacunarity = lacunarity; + OctaveCount = octaves; + Persistence = persistence; + Seed = seed; + Quality = quality; } #endregion @@ -59,8 +59,8 @@ public Billow(double frequency, double lacunarity, double persistence, int octav /// public double Frequency { - get { return this.m_frequency; } - set { this.m_frequency = value; } + get { return m_frequency; } + set { m_frequency = value; } } /// @@ -68,8 +68,8 @@ public double Frequency /// public double Lacunarity { - get { return this.m_lacunarity; } - set { this.m_lacunarity = value; } + get { return m_lacunarity; } + set { m_lacunarity = value; } } /// @@ -77,8 +77,8 @@ public double Lacunarity /// public QualityMode Quality { - get { return this.m_quality; } - set { this.m_quality = value; } + get { return m_quality; } + set { m_quality = value; } } /// @@ -86,8 +86,8 @@ public QualityMode Quality /// public int OctaveCount { - get { return this.m_octaveCount; } - set { this.m_octaveCount = (int)Mathf.Clamp(value, 1, Utils.OctavesMaximum); } + get { return m_octaveCount; } + set { m_octaveCount = Mathf.Clamp(value, 1, Utils.OctavesMaximum); } } /// @@ -95,8 +95,8 @@ public int OctaveCount /// public double Persistence { - get { return this.m_persistence; } - set { this.m_persistence = value; } + get { return m_persistence; } + set { m_persistence = value; } } /// @@ -104,8 +104,8 @@ public double Persistence /// public int Seed { - get { return this.m_seed; } - set { this.m_seed = value; } + get { return m_seed; } + set { m_seed = value; } } #endregion @@ -121,27 +121,27 @@ public int Seed /// The resulting output value. public override double GetValue(double x, double y, double z) { - double value = 0.0; - double signal = 0.0; - double curp = 1.0; + var value = 0.0; + var signal = 0.0; + var curp = 1.0; double nx, ny, nz; long seed; - x *= this.m_frequency; - y *= this.m_frequency; - z *= this.m_frequency; - for (int i = 0; i < this.m_octaveCount; i++) + x *= m_frequency; + y *= m_frequency; + z *= m_frequency; + for (var i = 0; i < m_octaveCount; i++) { nx = Utils.MakeInt32Range(x); ny = Utils.MakeInt32Range(y); nz = Utils.MakeInt32Range(z); - seed = (this.m_seed + i) & 0xffffffff; - signal = Utils.GradientCoherentNoise3D(nx, ny, nz, seed, this.m_quality); + seed = (m_seed + i) & 0xffffffff; + signal = Utils.GradientCoherentNoise3D(nx, ny, nz, seed, m_quality); signal = 2.0 * Math.Abs(signal) - 1.0; value += signal * curp; - x *= this.m_lacunarity; - y *= this.m_lacunarity; - z *= this.m_lacunarity; - curp *= this.m_persistence; + x *= m_lacunarity; + y *= m_lacunarity; + z *= m_lacunarity; + curp *= m_persistence; } return value + 0.5; } diff --git a/Generator/Checker.cs b/Generator/Checker.cs index 04661e6..29c1641 100755 --- a/Generator/Checker.cs +++ b/Generator/Checker.cs @@ -1,7 +1,7 @@ -namespace LibNoise.Unity.Generator +using System; + +namespace LibNoise.Unity.Generator { - using System; - /// /// Provides a noise module that outputs a checkerboard pattern. [GENERATOR] /// @@ -30,9 +30,9 @@ public Checker() /// The resulting output value. public override double GetValue(double x, double y, double z) { - int ix = (int)(Math.Floor(Utils.MakeInt32Range(x))); - int iy = (int)(Math.Floor(Utils.MakeInt32Range(y))); - int iz = (int)(Math.Floor(Utils.MakeInt32Range(z))); + var ix = (int) (Math.Floor(Utils.MakeInt32Range(x))); + var iy = (int) (Math.Floor(Utils.MakeInt32Range(y))); + var iz = (int) (Math.Floor(Utils.MakeInt32Range(z))); return (ix & 1 ^ iy & 1 ^ iz & 1) != 0 ? -1.0 : 1.0; } diff --git a/Generator/Const.cs b/Generator/Const.cs index 0bfe292..45f5116 100755 --- a/Generator/Const.cs +++ b/Generator/Const.cs @@ -1,7 +1,5 @@ namespace LibNoise.Unity.Generator { - using System; - /// /// Provides a noise module that outputs a constant value. [GENERATOR] /// @@ -9,7 +7,7 @@ public class Const : ModuleBase { #region Fields - private double m_value = 0.0; + private double m_value; #endregion @@ -30,7 +28,7 @@ public Const() public Const(double value) : base(0) { - this.Value = value; + Value = value; } #endregion @@ -42,8 +40,8 @@ public Const(double value) /// public double Value { - get { return this.m_value; } - set { this.m_value = value; } + get { return m_value; } + set { m_value = value; } } #endregion @@ -59,7 +57,7 @@ public double Value /// The resulting output value. public override double GetValue(double x, double y, double z) { - return this.m_value; + return m_value; } #endregion diff --git a/Generator/Cylinders.cs b/Generator/Cylinders.cs index c72ced6..c720674 100755 --- a/Generator/Cylinders.cs +++ b/Generator/Cylinders.cs @@ -1,7 +1,7 @@ -namespace LibNoise.Unity.Generator +using System; + +namespace LibNoise.Unity.Generator { - using System; - /// /// Provides a noise module that outputs concentric cylinders. [GENERATOR] /// @@ -30,7 +30,7 @@ public Cylinders() public Cylinders(double frequency) : base(0) { - this.Frequency = frequency; + Frequency = frequency; } #endregion @@ -42,8 +42,8 @@ public Cylinders(double frequency) /// public double Frequency { - get { return this.m_frequency; } - set { this.m_frequency = value; } + get { return m_frequency; } + set { m_frequency = value; } } #endregion @@ -59,12 +59,12 @@ public double Frequency /// The resulting output value. public override double GetValue(double x, double y, double z) { - x *= this.m_frequency; - z *= this.m_frequency; - double dfc = Math.Sqrt(x * x + z * z); - double dfss = dfc - Math.Floor(dfc); - double dfls = 1.0 - dfss; - double nd = Math.Min(dfss, dfls); + x *= m_frequency; + z *= m_frequency; + var dfc = Math.Sqrt(x * x + z * z); + var dfss = dfc - Math.Floor(dfc); + var dfls = 1.0 - dfss; + var nd = Math.Min(dfss, dfls); return 1.0 - (nd * 4.0); } diff --git a/Generator/Perlin.cs b/Generator/Perlin.cs index a337e95..28a4b5b 100755 --- a/Generator/Perlin.cs +++ b/Generator/Perlin.cs @@ -1,9 +1,7 @@ -namespace LibNoise.Unity.Generator -{ - using System; - - using UnityEngine; +using UnityEngine; +namespace LibNoise.Unity.Generator +{ /// /// Provides a noise module that outputs a three-dimensional perlin noise. [GENERATOR] /// @@ -16,7 +14,7 @@ public class Perlin : ModuleBase private QualityMode m_quality = QualityMode.Medium; private int m_octaveCount = 6; private double m_persistence = 0.5; - private int m_seed = 0; + private int m_seed; #endregion @@ -39,15 +37,16 @@ public Perlin() /// The number of octaves of the perlin noise. /// The seed of the perlin noise. /// The quality of the perlin noise. - public Perlin(double frequency, double lacunarity, double persistence, int octaves, int seed, QualityMode quality) + public Perlin(double frequency, double lacunarity, double persistence, int octaves, int seed, + QualityMode quality) : base(0) { - this.Frequency = frequency; - this.Lacunarity = lacunarity; - this.OctaveCount = octaves; - this.Persistence = persistence; - this.Seed = seed; - this.Quality = quality; + Frequency = frequency; + Lacunarity = lacunarity; + OctaveCount = octaves; + Persistence = persistence; + Seed = seed; + Quality = quality; } #endregion @@ -59,8 +58,8 @@ public Perlin(double frequency, double lacunarity, double persistence, int octav /// public double Frequency { - get { return this.m_frequency; } - set { this.m_frequency = value; } + get { return m_frequency; } + set { m_frequency = value; } } /// @@ -68,8 +67,8 @@ public double Frequency /// public double Lacunarity { - get { return this.m_lacunarity; } - set { this.m_lacunarity = value; } + get { return m_lacunarity; } + set { m_lacunarity = value; } } /// @@ -77,8 +76,8 @@ public double Lacunarity /// public QualityMode Quality { - get { return this.m_quality; } - set { this.m_quality = value; } + get { return m_quality; } + set { m_quality = value; } } /// @@ -86,8 +85,8 @@ public QualityMode Quality /// public int OctaveCount { - get { return this.m_octaveCount; } - set { this.m_octaveCount = (int)Mathf.Clamp(value, 1, Utils.OctavesMaximum); } + get { return m_octaveCount; } + set { m_octaveCount = Mathf.Clamp(value, 1, Utils.OctavesMaximum); } } /// @@ -95,8 +94,8 @@ public int OctaveCount /// public double Persistence { - get { return this.m_persistence; } - set { this.m_persistence = value; } + get { return m_persistence; } + set { m_persistence = value; } } /// @@ -104,8 +103,8 @@ public double Persistence /// public int Seed { - get { return this.m_seed; } - set { this.m_seed = value; } + get { return m_seed; } + set { m_seed = value; } } #endregion @@ -121,26 +120,26 @@ public int Seed /// The resulting output value. public override double GetValue(double x, double y, double z) { - double value = 0.0; - double signal = 0.0; - double cp = 1.0; + var value = 0.0; + var signal = 0.0; + var cp = 1.0; double nx, ny, nz; long seed; - x *= this.m_frequency; - y *= this.m_frequency; - z *= this.m_frequency; - for (int i = 0; i < this.m_octaveCount; i++) + x *= m_frequency; + y *= m_frequency; + z *= m_frequency; + for (var i = 0; i < m_octaveCount; i++) { nx = Utils.MakeInt32Range(x); ny = Utils.MakeInt32Range(y); nz = Utils.MakeInt32Range(z); - seed = (this.m_seed + i) & 0xffffffff; - signal = Utils.GradientCoherentNoise3D(nx, ny, nz, seed, this.m_quality); + seed = (m_seed + i) & 0xffffffff; + signal = Utils.GradientCoherentNoise3D(nx, ny, nz, seed, m_quality); value += signal * cp; - x *= this.m_lacunarity; - y *= this.m_lacunarity; - z *= this.m_lacunarity; - cp *= this.m_persistence; + x *= m_lacunarity; + y *= m_lacunarity; + z *= m_lacunarity; + cp *= m_persistence; } return value; } diff --git a/Generator/RidgedMultifractal.cs b/Generator/RidgedMultifractal.cs index f3823de..6d618a9 100755 --- a/Generator/RidgedMultifractal.cs +++ b/Generator/RidgedMultifractal.cs @@ -1,9 +1,8 @@ -namespace LibNoise.Unity.Generator -{ - using System; - - using UnityEngine; +using System; +using UnityEngine; +namespace LibNoise.Unity.Generator +{ /// /// Provides a noise module that outputs 3-dimensional ridged-multifractal noise. [GENERATOR] /// @@ -15,8 +14,8 @@ public class RidgedMultifractal : ModuleBase private double m_lacunarity = 2.0; private QualityMode m_quality = QualityMode.Medium; private int m_octaveCount = 6; - private int m_seed = 0; - private double[] m_weights = new double[Utils.OctavesMaximum]; + private int m_seed; + private readonly double[] m_weights = new double[Utils.OctavesMaximum]; #endregion @@ -28,7 +27,7 @@ public class RidgedMultifractal : ModuleBase public RidgedMultifractal() : base(0) { - this.UpdateWeights(); + UpdateWeights(); } /// @@ -42,11 +41,11 @@ public RidgedMultifractal() public RidgedMultifractal(double frequency, double lacunarity, int octaves, int seed, QualityMode quality) : base(0) { - this.Frequency = frequency; - this.Lacunarity = lacunarity; - this.OctaveCount = octaves; - this.Seed = seed; - this.Quality = quality; + Frequency = frequency; + Lacunarity = lacunarity; + OctaveCount = octaves; + Seed = seed; + Quality = quality; } #endregion @@ -58,8 +57,8 @@ public RidgedMultifractal(double frequency, double lacunarity, int octaves, int /// public double Frequency { - get { return this.m_frequency; } - set { this.m_frequency = value; } + get { return m_frequency; } + set { m_frequency = value; } } /// @@ -67,11 +66,11 @@ public double Frequency /// public double Lacunarity { - get { return this.m_lacunarity; } + get { return m_lacunarity; } set { - this.m_lacunarity = value; - this.UpdateWeights(); + m_lacunarity = value; + UpdateWeights(); } } @@ -80,8 +79,8 @@ public double Lacunarity /// public QualityMode Quality { - get { return this.m_quality; } - set { this.m_quality = value; } + get { return m_quality; } + set { m_quality = value; } } /// @@ -89,8 +88,8 @@ public QualityMode Quality /// public int OctaveCount { - get { return this.m_octaveCount; } - set { this.m_octaveCount = (int)Mathf.Clamp(value, 1, Utils.OctavesMaximum); } + get { return m_octaveCount; } + set { m_octaveCount = Mathf.Clamp(value, 1, Utils.OctavesMaximum); } } /// @@ -98,8 +97,8 @@ public int OctaveCount /// public int Seed { - get { return this.m_seed; } - set { this.m_seed = value; } + get { return m_seed; } + set { m_seed = value; } } #endregion @@ -111,11 +110,11 @@ public int Seed /// private void UpdateWeights() { - double f = 1.0; - for (int i = 0; i < Utils.OctavesMaximum; i++) + var f = 1.0; + for (var i = 0; i < Utils.OctavesMaximum; i++) { - this.m_weights[i] = Math.Pow(f, -1.0); - f *= this.m_lacunarity; + m_weights[i] = Math.Pow(f, -1.0); + f *= m_lacunarity; } } @@ -132,31 +131,31 @@ private void UpdateWeights() /// The resulting output value. public override double GetValue(double x, double y, double z) { - x *= this.m_frequency; - y *= this.m_frequency; - z *= this.m_frequency; - double signal = 0.0; - double value = 0.0; - double weight = 1.0; - double offset = 1.0; - double gain = 2.0; - for (int i = 0; i < this.m_octaveCount; i++) + x *= m_frequency; + y *= m_frequency; + z *= m_frequency; + var signal = 0.0; + var value = 0.0; + var weight = 1.0; + var offset = 1.0; + var gain = 2.0; + for (var i = 0; i < m_octaveCount; i++) { - double nx = Utils.MakeInt32Range(x); - double ny = Utils.MakeInt32Range(y); - double nz = Utils.MakeInt32Range(z); - long seed = (this.m_seed + i) & 0x7fffffff; - signal = Utils.GradientCoherentNoise3D(nx, ny, nz, seed, this.m_quality); + var nx = Utils.MakeInt32Range(x); + var ny = Utils.MakeInt32Range(y); + var nz = Utils.MakeInt32Range(z); + long seed = (m_seed + i) & 0x7fffffff; + signal = Utils.GradientCoherentNoise3D(nx, ny, nz, seed, m_quality); signal = Math.Abs(signal); signal = offset - signal; signal *= signal; signal *= weight; weight = signal * gain; - weight = Mathf.Clamp01((float)weight); - value += (signal * this.m_weights[i]); - x *= this.m_lacunarity; - y *= this.m_lacunarity; - z *= this.m_lacunarity; + weight = Mathf.Clamp01((float) weight); + value += (signal * m_weights[i]); + x *= m_lacunarity; + y *= m_lacunarity; + z *= m_lacunarity; } return (value * 1.25) - 1.0; } diff --git a/Generator/Spheres.cs b/Generator/Spheres.cs index 7ec7f1c..28de68f 100755 --- a/Generator/Spheres.cs +++ b/Generator/Spheres.cs @@ -1,7 +1,7 @@ -namespace LibNoise.Unity.Generator +using System; + +namespace LibNoise.Unity.Generator { - using System; - /// /// Provides a noise module that outputs concentric spheres. [GENERATOR] /// @@ -30,7 +30,7 @@ public Spheres() public Spheres(double frequency) : base(0) { - this.Frequency = frequency; + Frequency = frequency; } #endregion @@ -42,8 +42,8 @@ public Spheres(double frequency) /// public double Frequency { - get { return this.m_frequency; } - set { this.m_frequency = value; } + get { return m_frequency; } + set { m_frequency = value; } } #endregion @@ -59,13 +59,13 @@ public double Frequency /// The resulting output value. public override double GetValue(double x, double y, double z) { - x *= this.m_frequency; - y *= this.m_frequency; - z *= this.m_frequency; - double dfc = Math.Sqrt(x * x + y * y + z * z); - double dfss = dfc - Math.Floor(dfc); - double dfls = 1.0 - dfss; - double nd = Math.Min(dfss, dfls); + x *= m_frequency; + y *= m_frequency; + z *= m_frequency; + var dfc = Math.Sqrt(x * x + y * y + z * z); + var dfss = dfc - Math.Floor(dfc); + var dfls = 1.0 - dfss; + var nd = Math.Min(dfss, dfls); return 1.0 - (nd * 4.0); } diff --git a/Generator/Voronoi.cs b/Generator/Voronoi.cs index f03d660..5e9de07 100755 --- a/Generator/Voronoi.cs +++ b/Generator/Voronoi.cs @@ -1,7 +1,7 @@ -namespace LibNoise.Unity.Generator +using System; + +namespace LibNoise.Unity.Generator { - using System; - /// /// Provides a noise module that outputs Voronoi cells. [GENERATOR] /// @@ -11,8 +11,8 @@ public class Voronoi : ModuleBase private double m_displacement = 1.0; private double m_frequency = 1.0; - private int m_seed = 0; - private bool m_distance = false; + private int m_seed; + private bool m_distance; #endregion @@ -37,11 +37,11 @@ public Voronoi() public Voronoi(double frequency, double displacement, int seed, bool distance) : base(0) { - this.Frequency = frequency; - this.Displacement = displacement; - this.Seed = seed; - this.UseDistance = distance; - this.Seed = seed; + Frequency = frequency; + Displacement = displacement; + Seed = seed; + UseDistance = distance; + Seed = seed; } #endregion @@ -53,8 +53,8 @@ public Voronoi(double frequency, double displacement, int seed, bool distance) /// public double Displacement { - get { return this.m_displacement; } - set { this.m_displacement = value; } + get { return m_displacement; } + set { m_displacement = value; } } /// @@ -62,8 +62,8 @@ public double Displacement /// public double Frequency { - get { return this.m_frequency; } - set { this.m_frequency = value; } + get { return m_frequency; } + set { m_frequency = value; } } /// @@ -71,8 +71,8 @@ public double Frequency /// public int Seed { - get { return this.m_seed; } - set { this.m_seed = value; } + get { return m_seed; } + set { m_seed = value; } } /// @@ -80,8 +80,8 @@ public int Seed /// public bool UseDistance { - get { return this.m_distance; } - set { this.m_distance = value; } + get { return m_distance; } + set { m_distance = value; } } #endregion @@ -97,29 +97,29 @@ public bool UseDistance /// The resulting output value. public override double GetValue(double x, double y, double z) { - x *= this.m_frequency; - y *= this.m_frequency; - z *= this.m_frequency; - int xi = (x > 0.0 ? (int)x : (int)x - 1); - int iy = (y > 0.0 ? (int)y : (int)y - 1); - int iz = (z > 0.0 ? (int)z : (int)z - 1); - double md = 2147483647.0; + x *= m_frequency; + y *= m_frequency; + z *= m_frequency; + var xi = (x > 0.0 ? (int) x : (int) x - 1); + var iy = (y > 0.0 ? (int) y : (int) y - 1); + var iz = (z > 0.0 ? (int) z : (int) z - 1); + var md = 2147483647.0; double xc = 0; double yc = 0; double zc = 0; - for (int zcu = iz - 2; zcu <= iz + 2; zcu++) + for (var zcu = iz - 2; zcu <= iz + 2; zcu++) { - for (int ycu = iy - 2; ycu <= iy + 2; ycu++) + for (var ycu = iy - 2; ycu <= iy + 2; ycu++) { - for (int xcu = xi - 2; xcu <= xi + 2; xcu++) + for (var xcu = xi - 2; xcu <= xi + 2; xcu++) { - double xp = xcu + Utils.ValueNoise3D(xcu, ycu, zcu, this.m_seed); - double yp = ycu + Utils.ValueNoise3D(xcu, ycu, zcu, this.m_seed + 1); - double zp = zcu + Utils.ValueNoise3D(xcu, ycu, zcu, this.m_seed + 2); - double xd = xp - x; - double yd = yp - y; - double zd = zp - z; - double d = xd * xd + yd * yd + zd * zd; + var xp = xcu + Utils.ValueNoise3D(xcu, ycu, zcu, m_seed); + var yp = ycu + Utils.ValueNoise3D(xcu, ycu, zcu, m_seed + 1); + var zp = zcu + Utils.ValueNoise3D(xcu, ycu, zcu, m_seed + 2); + var xd = xp - x; + var yd = yp - y; + var zd = zp - z; + var d = xd * xd + yd * yd + zd * zd; if (d < md) { md = d; @@ -131,19 +131,19 @@ public override double GetValue(double x, double y, double z) } } double v; - if (this.m_distance) + if (m_distance) { - double xd = xc - x; - double yd = yc - y; - double zd = zc - z; + var xd = xc - x; + var yd = yc - y; + var zd = zc - z; v = (Math.Sqrt(xd * xd + yd * yd + zd * zd)) * Utils.Sqrt3 - 1.0; } else { v = 0.0; } - return v + (this.m_displacement * (double)Utils.ValueNoise3D((int)(Math.Floor(xc)), (int)(Math.Floor(yc)), - (int)(Math.Floor(zc)), 0)); + return v + (m_displacement * Utils.ValueNoise3D((int) (Math.Floor(xc)), (int) (Math.Floor(yc)), + (int) (Math.Floor(zc)), 0)); } #endregion diff --git a/GradientPresets.cs b/GradientPresets.cs index 85548af..d713d5a 100755 --- a/GradientPresets.cs +++ b/GradientPresets.cs @@ -1,10 +1,8 @@ +using System.Collections.Generic; +using UnityEngine; + namespace LibNoise.Unity { - using System; - using System.Collections.Generic; - - using UnityEngine; - /// /// Provides a series of gradient presets /// @@ -12,11 +10,11 @@ public static class GradientPresets { #region Fields - private static Gradient _empty; - private static Gradient _grayscale; - private static Gradient _rgb; - private static Gradient _rgba; - private static Gradient _terrain; + private static readonly Gradient _empty; + private static readonly Gradient _grayscale; + private static readonly Gradient _rgb; + private static readonly Gradient _rgba; + private static readonly Gradient _terrain; #endregion @@ -28,30 +26,30 @@ public static class GradientPresets static GradientPresets() { // Grayscale gradient color keys - List grayscaleColorKeys = new List(); + var grayscaleColorKeys = new List(); grayscaleColorKeys.Add(new GradientColorKey(Color.black, 0)); grayscaleColorKeys.Add(new GradientColorKey(Color.white, 1)); // RGB gradient color keys - List rgbColorKeys = new List(); + var rgbColorKeys = new List(); rgbColorKeys.Add(new GradientColorKey(Color.red, 0)); rgbColorKeys.Add(new GradientColorKey(Color.green, 0.5f)); rgbColorKeys.Add(new GradientColorKey(Color.blue, 1)); // RGBA gradient color keys - List rgbaColorKeys = new List(); + var rgbaColorKeys = new List(); rgbaColorKeys.Add(new GradientColorKey(Color.red, 0)); - rgbaColorKeys.Add(new GradientColorKey(Color.green, 1/3f)); - rgbaColorKeys.Add(new GradientColorKey(Color.blue, 2/3f)); + rgbaColorKeys.Add(new GradientColorKey(Color.green, 1 / 3f)); + rgbaColorKeys.Add(new GradientColorKey(Color.blue, 2 / 3f)); rgbaColorKeys.Add(new GradientColorKey(Color.black, 1)); // RGBA gradient alpha keys - List rgbaAlphaKeys = new List(); - rgbaAlphaKeys.Add(new GradientAlphaKey(0, 2/3f)); + var rgbaAlphaKeys = new List(); + rgbaAlphaKeys.Add(new GradientAlphaKey(0, 2 / 3f)); rgbaAlphaKeys.Add(new GradientAlphaKey(1, 1)); // Terrain gradient color keys - List terrainColorKeys = new List(); + var terrainColorKeys = new List(); terrainColorKeys.Add(new GradientColorKey(new Color(0, 0, 0.5f), 0)); terrainColorKeys.Add(new GradientColorKey(new Color(0.125f, 0.25f, 0.5f), 0.4f)); terrainColorKeys.Add(new GradientColorKey(new Color(0.25f, 0.375f, 0.75f), 0.48f)); @@ -62,7 +60,7 @@ static GradientPresets() terrainColorKeys.Add(new GradientColorKey(Color.white, 1)); // Generic gradient alpha keys - List alphaKeys = new List(); + var alphaKeys = new List(); alphaKeys.Add(new GradientAlphaKey(1, 0)); alphaKeys.Add(new GradientAlphaKey(1, 1)); diff --git a/ModuleBase.cs b/ModuleBase.cs index 8b5ebf2..749241d 100755 --- a/ModuleBase.cs +++ b/ModuleBase.cs @@ -1,8 +1,10 @@ -namespace LibNoise.Unity +using System; +using System.Xml.Serialization; +using UnityEngine; +using Debug = System.Diagnostics.Debug; + +namespace LibNoise.Unity { - using System; - - using UnityEngine; #region Enumerations @@ -39,7 +41,7 @@ protected ModuleBase(int count) { if (count > 0) { - this.m_modules = new ModuleBase[count]; + m_modules = new ModuleBase[count]; } } @@ -56,22 +58,22 @@ public virtual ModuleBase this[int index] { get { - System.Diagnostics.Debug.Assert(this.m_modules != null); - System.Diagnostics.Debug.Assert(this.m_modules.Length > 0); - if (index < 0 || index >= this.m_modules.Length) + Debug.Assert(m_modules != null); + Debug.Assert(m_modules.Length > 0); + if (index < 0 || index >= m_modules.Length) { throw new ArgumentOutOfRangeException("Index out of valid module range"); } - if (this.m_modules[index] == null) + if (m_modules[index] == null) { throw new ArgumentNullException("Desired element is null"); } - return this.m_modules[index]; + return m_modules[index]; } set { - System.Diagnostics.Debug.Assert(this.m_modules.Length > 0); - if (index < 0 || index >= this.m_modules.Length) + Debug.Assert(m_modules.Length > 0); + if (index < 0 || index >= m_modules.Length) { throw new ArgumentOutOfRangeException("Index out of valid module range"); } @@ -79,7 +81,7 @@ public virtual ModuleBase this[int index] { throw new ArgumentNullException("Value should not be null"); } - this.m_modules[index] = value; + m_modules[index] = value; } } @@ -92,7 +94,7 @@ public virtual ModuleBase this[int index] /// public int SourceModuleCount { - get { return (this.m_modules == null) ? 0 : this.m_modules.Length; } + get { return (m_modules == null) ? 0 : m_modules.Length; } } #endregion @@ -115,7 +117,7 @@ public int SourceModuleCount /// The resulting output value. public double GetValue(Vector3 coordinate) { - return this.GetValue(coordinate.x, coordinate.y, coordinate.z); + return GetValue(coordinate.x, coordinate.y, coordinate.z); } /// @@ -125,25 +127,25 @@ public double GetValue(Vector3 coordinate) /// The resulting output value. public double GetValue(ref Vector3 coordinate) { - return this.GetValue(coordinate.x, coordinate.y, coordinate.z); + return GetValue(coordinate.x, coordinate.y, coordinate.z); } #endregion #region IDisposable Members - [System.Xml.Serialization.XmlIgnore] - #if !XBOX360 && !ZUNE + [XmlIgnore] +#if !XBOX360 && !ZUNE [NonSerialized] - #endif - private bool m_disposed = false; +#endif + private bool m_disposed; /// /// Gets a value whether the object is disposed. /// public bool IsDisposed { - get { return this.m_disposed; } + get { return m_disposed; } } /// @@ -151,9 +153,9 @@ public bool IsDisposed /// public void Dispose() { - if (!this.m_disposed) + if (!m_disposed) { - this.m_disposed = this.Disposing(); + m_disposed = Disposing(); } GC.SuppressFinalize(this); } @@ -164,14 +166,14 @@ public void Dispose() /// True if the object is completely disposed. protected virtual bool Disposing() { - if (this.m_modules != null) + if (m_modules != null) { - for (int i = 0; i < this.m_modules.Length; i++) + for (var i = 0; i < m_modules.Length; i++) { - this.m_modules[i].Dispose(); - this.m_modules[i] = null; + m_modules[i].Dispose(); + m_modules[i] = null; } - this.m_modules = null; + m_modules = null; } return true; } diff --git a/Noise2D.cs b/Noise2D.cs index 61dc935..4faf66f 100755 --- a/Noise2D.cs +++ b/Noise2D.cs @@ -1,9 +1,9 @@ +using System; +using System.Xml.Serialization; +using UnityEngine; + namespace LibNoise.Unity { - using System; - - using UnityEngine; - /// /// Provides a two-dimensional noise map. /// @@ -26,15 +26,18 @@ public class Noise2D : IDisposable #region Fields - private int m_width = 0; - private int m_height = 0; - private float[,] m_data = null; - private int m_ucWidth = 0; - private int m_ucHeight = 0; + private int m_width; + private int m_height; + private float[,] m_data; + private readonly int m_ucWidth; + private readonly int m_ucHeight; private int m_ucBorder = 1; // Border size of extra noise for uncropped data. - private float[,] m_ucData = null; // Uncropped data. This has a border of extra noise data used for calculating normal map edges. + + private readonly float[,] m_ucData; + // Uncropped data. This has a border of extra noise data used for calculating normal map edges. + private float m_borderValue = float.NaN; - private ModuleBase m_generator = null; + private ModuleBase m_generator; #endregion @@ -84,14 +87,15 @@ public Noise2D(int width, int height) /// The generator module. public Noise2D(int width, int height, ModuleBase generator) { - this.m_generator = generator; - this.m_width = width; - this.m_height = height; - this.m_data = new float[width, height]; - this.m_ucWidth = width + m_ucBorder * 2; - this.m_ucHeight = height + m_ucBorder * 2; - this.m_ucData = new float[width + m_ucBorder * 2, height + m_ucBorder * 2]; + m_generator = generator; + m_width = width; + m_height = height; + m_data = new float[width, height]; + m_ucWidth = width + m_ucBorder * 2; + m_ucHeight = height + m_ucBorder * 2; + m_ucData = new float[width + m_ucBorder * 2, height + m_ucBorder * 2]; } + #endregion #region Indexers @@ -109,54 +113,51 @@ public Noise2D(int width, int height, ModuleBase generator) { if (isCropped) { - if (x < 0 && x >= this.m_width) + if (x < 0 && x >= m_width) { throw new ArgumentOutOfRangeException("Invalid x position"); } - if (y < 0 && y >= this.m_height) + if (y < 0 && y >= m_height) { throw new ArgumentOutOfRangeException("Invalid y position"); } - return this.m_data[x, y]; + return m_data[x, y]; } - else + if (x < 0 && x >= m_ucWidth) { - if (x < 0 && x >= this.m_ucWidth) - { - throw new ArgumentOutOfRangeException("Invalid x position"); - } - if (y < 0 && y >= this.m_ucHeight) - { - throw new ArgumentOutOfRangeException("Invalid y position"); - } - return this.m_ucData[x, y]; + throw new ArgumentOutOfRangeException("Invalid x position"); } + if (y < 0 && y >= m_ucHeight) + { + throw new ArgumentOutOfRangeException("Invalid y position"); + } + return m_ucData[x, y]; } set { if (isCropped) { - if (x < 0 && x >= this.m_width) + if (x < 0 && x >= m_width) { throw new ArgumentOutOfRangeException("Invalid x position"); } - if (y < 0 && y >= this.m_height) + if (y < 0 && y >= m_height) { throw new ArgumentOutOfRangeException("Invalid y position"); } - this.m_data[x, y] = value; + m_data[x, y] = value; } else { - if (x < 0 && x >= this.m_ucWidth) + if (x < 0 && x >= m_ucWidth) { throw new ArgumentOutOfRangeException("Invalid x position"); } - if (y < 0 && y >= this.m_ucHeight) + if (y < 0 && y >= m_ucHeight) { throw new ArgumentOutOfRangeException("Invalid y position"); } - this.m_ucData[x, y] = value; + m_ucData[x, y] = value; } } } @@ -170,8 +171,8 @@ public Noise2D(int width, int height, ModuleBase generator) /// public float Border { - get { return this.m_borderValue; } - set { this.m_borderValue = value; } + get { return m_borderValue; } + set { m_borderValue = value; } } /// @@ -179,8 +180,8 @@ public float Border /// public ModuleBase Generator { - get { return this.m_generator; } - set { this.m_generator = value; } + get { return m_generator; } + set { m_generator = value; } } /// @@ -188,7 +189,7 @@ public ModuleBase Generator /// public int Height { - get { return this.m_height; } + get { return m_height; } } /// @@ -196,7 +197,7 @@ public int Height /// public int Width { - get { return this.m_width; } + get { return m_width; } } #endregion @@ -212,7 +213,7 @@ public int Width /// The normalized noise map data. public float[,] GetNormalizedData(bool isCropped = true, int xCrop = 0, int yCrop = 0) { - return this.GetData(isCropped, xCrop, yCrop, true); + return GetData(isCropped, xCrop, yCrop, true); } /// @@ -229,31 +230,31 @@ public int Width float[,] data; if (isCropped) { - width = this.m_width; - height = this.m_height; - data = this.m_data; + width = m_width; + height = m_height; + data = m_data; } else { - width = this.m_ucWidth; - height = this.m_ucHeight; - data = this.m_ucData; + width = m_ucWidth; + height = m_ucHeight; + data = m_ucData; } width -= xCrop; height -= yCrop; - float[,] result = new float[width, height]; - for (int x = 0; x < width; x++) + var result = new float[width, height]; + for (var x = 0; x < width; x++) { - for (int y = 0; y < height; y++) + for (var y = 0; y < height; y++) { float sample; if (isNormalized) { - sample = ((float)data[x, y] + 1) / 2; + sample = (data[x, y] + 1) / 2; } else { - sample = (float)data[x, y]; + sample = data[x, y]; } result[x, y] = sample; } @@ -267,11 +268,11 @@ public int Width /// The constant value to clear the noise map with. public void Clear(float value = 0f) { - for (int x = 0; x < this.m_width; x++) + for (var x = 0; x < m_width; x++) { - for (int y = 0; y < this.m_height; y++) + for (var y = 0; y < m_height; y++) { - this.m_data[x, y] = value; + m_data[x, y] = value; } } } @@ -284,7 +285,7 @@ public void Clear(float value = 0f) /// The corresponding noise map value. private double GeneratePlanar(double x, double y) { - return this.m_generator.GetValue(x, 0.0, y); + return m_generator.GetValue(x, 0.0, y); } /// @@ -304,39 +305,40 @@ public void GeneratePlanar(double left, double right, double top, double bottom, if (m_generator == null) { throw new ArgumentNullException("Generator is null"); - } - double xe = right - left; - double ze = bottom - top; - double xd = xe / ((double)this.m_width - m_ucBorder); - double zd = ze / ((double)this.m_height - m_ucBorder); - double xc = left; - double zc = top; - float fv = 0.0f; - for (int x = 0; x < this.m_ucWidth; x++) + } + var xe = right - left; + var ze = bottom - top; + var xd = xe / ((double) m_width - m_ucBorder); + var zd = ze / ((double) m_height - m_ucBorder); + var xc = left; + var zc = top; + var fv = 0.0f; + for (var x = 0; x < m_ucWidth; x++) { zc = top; - for (int y = 0; y < this.m_ucHeight; y++) + for (var y = 0; y < m_ucHeight; y++) { if (isSeamless) { - fv = (float)this.GeneratePlanar(xc, zc); + fv = (float) GeneratePlanar(xc, zc); } else { - double swv = this.GeneratePlanar(xc, zc); - double sev = this.GeneratePlanar(xc + xe, zc); - double nwv = this.GeneratePlanar(xc, zc + ze); - double nev = this.GeneratePlanar(xc + xe, zc + ze); - double xb = 1.0 - ((xc - left) / xe); - double zb = 1.0 - ((zc - top) / ze); - double z0 = Utils.InterpolateLinear(swv, sev, xb); - double z1 = Utils.InterpolateLinear(nwv, nev, xb); - fv = (float)Utils.InterpolateLinear(z0, z1, zb); + var swv = GeneratePlanar(xc, zc); + var sev = GeneratePlanar(xc + xe, zc); + var nwv = GeneratePlanar(xc, zc + ze); + var nev = GeneratePlanar(xc + xe, zc + ze); + var xb = 1.0 - ((xc - left) / xe); + var zb = 1.0 - ((zc - top) / ze); + var z0 = Utils.InterpolateLinear(swv, sev, xb); + var z1 = Utils.InterpolateLinear(nwv, nev, xb); + fv = (float) Utils.InterpolateLinear(z0, z1, zb); } - this.m_ucData[x, y] = fv; - if (x >= m_ucBorder && y >= m_ucBorder && x < this.m_width + m_ucBorder && y < this.m_height + m_ucBorder) + m_ucData[x, y] = fv; + if (x >= m_ucBorder && y >= m_ucBorder && x < m_width + m_ucBorder && + y < m_height + m_ucBorder) { - this.m_data[x - m_ucBorder, y - m_ucBorder] = fv; // Cropped data + m_data[x - m_ucBorder, y - m_ucBorder] = fv; // Cropped data } zc += zd; } @@ -352,10 +354,10 @@ public void GeneratePlanar(double left, double right, double top, double bottom, /// The corresponding noise map value. private double GenerateCylindrical(double angle, double height) { - double x = Math.Cos(angle * Mathf.Deg2Rad); - double y = height; - double z = Math.Sin(angle * Mathf.Deg2Rad); - return this.m_generator.GetValue(x, y, z); + var x = Math.Cos(angle * Mathf.Deg2Rad); + var y = height; + var z = Math.Sin(angle * Mathf.Deg2Rad); + return m_generator.GetValue(x, y, z); } /// @@ -375,21 +377,23 @@ public void GenerateCylindrical(double angleMin, double angleMax, double heightM { throw new ArgumentNullException("Generator is null"); } - double ae = angleMax - angleMin; - double he = heightMax - heightMin; - double xd = ae / ((double)this.m_width - m_ucBorder); - double yd = he / ((double)this.m_height - m_ucBorder); - double ca = angleMin; - double ch = heightMin; - for (int x = 0; x < this.m_ucWidth; x++) + var ae = angleMax - angleMin; + var he = heightMax - heightMin; + var xd = ae / ((double) m_width - m_ucBorder); + var yd = he / ((double) m_height - m_ucBorder); + var ca = angleMin; + var ch = heightMin; + for (var x = 0; x < m_ucWidth; x++) { ch = heightMin; - for (int y = 0; y < this.m_ucHeight; y++) + for (var y = 0; y < m_ucHeight; y++) { - this.m_ucData[x, y] = (float)this.GenerateCylindrical(ca, ch); - if (x >= m_ucBorder && y >= m_ucBorder && x < this.m_width + m_ucBorder && y < this.m_height + m_ucBorder) + m_ucData[x, y] = (float) GenerateCylindrical(ca, ch); + if (x >= m_ucBorder && y >= m_ucBorder && x < m_width + m_ucBorder && + y < m_height + m_ucBorder) { - this.m_data[x - m_ucBorder, y - m_ucBorder] = (float)this.GenerateCylindrical(ca, ch); // Cropped data + m_data[x - m_ucBorder, y - m_ucBorder] = (float) GenerateCylindrical(ca, ch); + // Cropped data } ch += yd; } @@ -405,8 +409,8 @@ public void GenerateCylindrical(double angleMin, double angleMax, double heightM /// The corresponding noise map value. private double GenerateSpherical(double lat, double lon) { - double r = Math.Cos(Mathf.Deg2Rad * lat); - return this.m_generator.GetValue(r * Math.Cos(Mathf.Deg2Rad * lon), Math.Sin(Mathf.Deg2Rad * lat), + var r = Math.Cos(Mathf.Deg2Rad * lat); + return m_generator.GetValue(r * Math.Cos(Mathf.Deg2Rad * lon), Math.Sin(Mathf.Deg2Rad * lat), r * Math.Sin(Mathf.Deg2Rad * lon)); } @@ -427,21 +431,23 @@ public void GenerateSpherical(double south, double north, double west, double ea { throw new ArgumentNullException("Generator is null"); } - double loe = east - west; - double lae = north - south; - double xd = loe / ((double)this.m_width - m_ucBorder); - double yd = lae / ((double)this.m_height - m_ucBorder); - double clo = west; - double cla = south; - for (int x = 0; x < this.m_ucWidth; x++) + var loe = east - west; + var lae = north - south; + var xd = loe / ((double) m_width - m_ucBorder); + var yd = lae / ((double) m_height - m_ucBorder); + var clo = west; + var cla = south; + for (var x = 0; x < m_ucWidth; x++) { cla = south; - for (int y = 0; y < this.m_ucHeight; y++) + for (var y = 0; y < m_ucHeight; y++) { - this.m_ucData[x, y] = (float)this.GenerateSpherical(cla, clo); - if (x >= m_ucBorder && y >= m_ucBorder && x < this.m_width + m_ucBorder && y < this.m_height + m_ucBorder) + m_ucData[x, y] = (float) GenerateSpherical(cla, clo); + if (x >= m_ucBorder && y >= m_ucBorder && x < m_width + m_ucBorder && + y < m_height + m_ucBorder) { - this.m_data[x - m_ucBorder, y - m_ucBorder] = (float)this.GenerateSpherical(cla, clo); // Cropped data + m_data[x - m_ucBorder, y - m_ucBorder] = (float) GenerateSpherical(cla, clo); + // Cropped data } cla += yd; } @@ -455,7 +461,7 @@ public void GenerateSpherical(double south, double north, double west, double ea /// The created texture map. public Texture2D GetTexture() { - return this.GetTexture(GradientPresets.Grayscale); + return GetTexture(GradientPresets.Grayscale); } /// @@ -465,22 +471,23 @@ public Texture2D GetTexture() /// The created texture map. public Texture2D GetTexture(Gradient gradient) { - Texture2D texture = new Texture2D(this.m_width, this.m_height); - Color[] pixels = new Color[this.m_width * this.m_height]; - for (int x = 0; x < this.m_width; x++) + var texture = new Texture2D(m_width, m_height); + var pixels = new Color[m_width * m_height]; + for (var x = 0; x < m_width; x++) { - for (int y = 0; y < this.m_height; y++) + for (var y = 0; y < m_height; y++) { - float sample = 0.0f; - if (!float.IsNaN(this.m_borderValue) && (x == 0 || x == this.m_width - m_ucBorder || y == 0 || y == this.m_height - m_ucBorder)) + var sample = 0.0f; + if (!float.IsNaN(m_borderValue) && + (x == 0 || x == m_width - m_ucBorder || y == 0 || y == m_height - m_ucBorder)) { - sample = this.m_borderValue; + sample = m_borderValue; } else { - sample = this.m_data[x, y]; + sample = m_data[x, y]; } - pixels[x + y * this.m_width] = gradient.Evaluate((sample + 1) / 2); + pixels[x + y * m_width] = gradient.Evaluate((sample + 1) / 2); } } texture.SetPixels(pixels); @@ -496,28 +503,32 @@ public Texture2D GetTexture(Gradient gradient) /// The created normal map. public Texture2D GetNormalMap(float intensity) { - Texture2D texture = new Texture2D(this.m_width, this.m_height); - Color[] pixels = new Color[this.m_width * this.m_height]; - for (int x = 0; x < this.m_ucWidth; x++) + var texture = new Texture2D(m_width, m_height); + var pixels = new Color[m_width * m_height]; + for (var x = 0; x < m_ucWidth; x++) { - for (int y = 0; y < this.m_ucHeight; y++) + for (var y = 0; y < m_ucHeight; y++) { - float xPos = (this.m_ucData[Mathf.Max(0, x - m_ucBorder), y] - this.m_ucData[Mathf.Min(x + m_ucBorder, this.m_height + m_ucBorder), y]) / 2; - float yPos = (this.m_ucData[x, Mathf.Max(0, y - m_ucBorder)] - this.m_ucData[x, Mathf.Min(y + m_ucBorder, this.m_width + m_ucBorder)]) / 2; - Vector3 normalX = new Vector3(xPos * intensity, 0, 1); - Vector3 normalY = new Vector3(0, yPos * intensity, 1); + var xPos = (m_ucData[Mathf.Max(0, x - m_ucBorder), y] - + m_ucData[Mathf.Min(x + m_ucBorder, m_height + m_ucBorder), y]) / 2; + var yPos = (m_ucData[x, Mathf.Max(0, y - m_ucBorder)] - + m_ucData[x, Mathf.Min(y + m_ucBorder, m_width + m_ucBorder)]) / 2; + var normalX = new Vector3(xPos * intensity, 0, 1); + var normalY = new Vector3(0, yPos * intensity, 1); // Get normal vector - Vector3 normalVector = normalX + normalY; + var normalVector = normalX + normalY; normalVector.Normalize(); // Get color vector - Vector3 colorVector = Vector3.zero; + var colorVector = Vector3.zero; colorVector.x = (normalVector.x + 1) / 2; colorVector.y = (normalVector.y + 1) / 2; colorVector.z = (normalVector.z + 1) / 2; // Start at (x + m_ucBorder, y + m_ucBorder) so that resulting normal map aligns with cropped data - if (x >= m_ucBorder && y >= m_ucBorder && x < this.m_width + m_ucBorder && y < this.m_height + m_ucBorder) + if (x >= m_ucBorder && y >= m_ucBorder && x < m_width + m_ucBorder && + y < m_height + m_ucBorder) { - pixels[(x - m_ucBorder) + (y - m_ucBorder) * this.m_width] = new Color(colorVector.x, colorVector.y, colorVector.z); + pixels[(x - m_ucBorder) + (y - m_ucBorder) * m_width] = new Color(colorVector.x, + colorVector.y, colorVector.z); } } } @@ -531,18 +542,18 @@ public Texture2D GetNormalMap(float intensity) #region IDisposable Members - [System.Xml.Serialization.XmlIgnore] - #if !XBOX360 && !ZUNE - [NonSerialized] - #endif - private bool m_disposed = false; + [XmlIgnore] +#if !XBOX360 && !ZUNE + [NonSerialized] +#endif + private bool m_disposed; /// /// Gets a value whether the object is disposed. /// public bool IsDisposed { - get { return this.m_disposed; } + get { return m_disposed; } } /// @@ -550,9 +561,9 @@ public bool IsDisposed /// public void Dispose() { - if (!this.m_disposed) + if (!m_disposed) { - this.m_disposed = this.Disposing(); + m_disposed = Disposing(); } GC.SuppressFinalize(this); } @@ -563,12 +574,12 @@ public void Dispose() /// True if the object is completely disposed. protected virtual bool Disposing() { - if (this.m_data != null) + if (m_data != null) { - this.m_data = null; + m_data = null; } - this.m_width = 0; - this.m_height = 0; + m_width = 0; + m_height = 0; return true; } diff --git a/Operator/Abs.cs b/Operator/Abs.cs index 55fd992..b75ec48 100755 --- a/Operator/Abs.cs +++ b/Operator/Abs.cs @@ -1,7 +1,8 @@ -namespace LibNoise.Unity.Operator +using System; +using System.Diagnostics; + +namespace LibNoise.Unity.Operator { - using System; - /// /// Provides a noise module that outputs the absolute value of the output value from /// a source module. [OPERATOR] @@ -25,7 +26,7 @@ public Abs() public Abs(ModuleBase input) : base(1) { - this.m_modules[0] = input; + m_modules[0] = input; } #endregion @@ -41,8 +42,8 @@ public Abs(ModuleBase input) /// The resulting output value. public override double GetValue(double x, double y, double z) { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - return Math.Abs(this.m_modules[0].GetValue(x, y, z)); + Debug.Assert(m_modules[0] != null); + return Math.Abs(m_modules[0].GetValue(x, y, z)); } #endregion diff --git a/Operator/Add.cs b/Operator/Add.cs index c6a57f9..64b15c9 100755 --- a/Operator/Add.cs +++ b/Operator/Add.cs @@ -1,7 +1,7 @@ -namespace LibNoise.Unity.Operator +using System.Diagnostics; + +namespace LibNoise.Unity.Operator { - using System; - /// /// Provides a noise module that outputs the sum of the two output values from two /// source modules. [OPERATOR] @@ -26,8 +26,8 @@ public Add() public Add(ModuleBase lhs, ModuleBase rhs) : base(2) { - this.m_modules[0] = lhs; - this.m_modules[1] = rhs; + m_modules[0] = lhs; + m_modules[1] = rhs; } #endregion @@ -43,9 +43,9 @@ public Add(ModuleBase lhs, ModuleBase rhs) /// The resulting output value. public override double GetValue(double x, double y, double z) { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - System.Diagnostics.Debug.Assert(this.m_modules[1] != null); - return this.m_modules[0].GetValue(x, y, z) + this.m_modules[1].GetValue(x, y, z); + Debug.Assert(m_modules[0] != null); + Debug.Assert(m_modules[1] != null); + return m_modules[0].GetValue(x, y, z) + m_modules[1].GetValue(x, y, z); } #endregion diff --git a/Operator/Blend.cs b/Operator/Blend.cs index 9f5d99c..aabeb3c 100755 --- a/Operator/Blend.cs +++ b/Operator/Blend.cs @@ -1,7 +1,7 @@ -namespace LibNoise.Unity.Operator +using System.Diagnostics; + +namespace LibNoise.Unity.Operator { - using System; - /// /// 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] @@ -27,9 +27,9 @@ public Blend() public Blend(ModuleBase lhs, ModuleBase rhs, ModuleBase controller) : base(3) { - this.m_modules[0] = lhs; - this.m_modules[1] = rhs; - this.m_modules[2] = controller; + m_modules[0] = lhs; + m_modules[1] = rhs; + m_modules[2] = controller; } #endregion @@ -41,11 +41,11 @@ public Blend(ModuleBase lhs, ModuleBase rhs, ModuleBase controller) /// public ModuleBase Controller { - get { return this.m_modules[2]; } + get { return m_modules[2]; } set { - System.Diagnostics.Debug.Assert(value != null); - this.m_modules[2] = value; + Debug.Assert(value != null); + m_modules[2] = value; } } @@ -62,12 +62,12 @@ public ModuleBase Controller /// The resulting output value. public override double GetValue(double x, double y, double z) { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - System.Diagnostics.Debug.Assert(this.m_modules[1] != null); - System.Diagnostics.Debug.Assert(this.m_modules[2] != null); - double a = this.m_modules[0].GetValue(x, y, z); - double b = this.m_modules[1].GetValue(x, y, z); - double c = (this.m_modules[2].GetValue(x, y, z) + 1.0) / 2.0; + Debug.Assert(m_modules[0] != null); + Debug.Assert(m_modules[1] != null); + Debug.Assert(m_modules[2] != null); + var a = m_modules[0].GetValue(x, y, z); + var b = m_modules[1].GetValue(x, y, z); + var c = (m_modules[2].GetValue(x, y, z) + 1.0) / 2.0; return Utils.InterpolateLinear(a, b, c); } diff --git a/Operator/Cache.cs b/Operator/Cache.cs index c806de7..a4f2d32 100755 --- a/Operator/Cache.cs +++ b/Operator/Cache.cs @@ -1,7 +1,7 @@ -namespace LibNoise.Unity.Operator +using System.Diagnostics; + +namespace LibNoise.Unity.Operator { - using System; - /// /// Provides a noise module that caches the last output value generated by a source /// module. [OPERATOR] @@ -10,11 +10,11 @@ public class Cache : ModuleBase { #region Fields - private double m_value = 0.0; - private bool m_cached = false; - private double m_x = 0.0; - private double m_y = 0.0; - private double m_z = 0.0; + private double m_value; + private bool m_cached; + private double m_x; + private double m_y; + private double m_z; #endregion @@ -35,7 +35,7 @@ public Cache() public Cache(ModuleBase input) : base(1) { - this.m_modules[0] = input; + m_modules[0] = input; } #endregion @@ -53,7 +53,7 @@ public override ModuleBase this[int index] set { base[index] = value; - this.m_cached = false; + m_cached = false; } } @@ -66,16 +66,16 @@ public override ModuleBase this[int index] /// The resulting output value. public override double GetValue(double x, double y, double z) { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - if (!(this.m_cached && this.m_x == x && this.m_y == y && this.m_z == z)) + Debug.Assert(m_modules[0] != null); + if (!(m_cached && m_x == x && m_y == y && m_z == z)) { - this.m_value = this.m_modules[0].GetValue(x, y, z); - this.m_x = x; - this.m_y = y; - this.m_z = z; + m_value = m_modules[0].GetValue(x, y, z); + m_x = x; + m_y = y; + m_z = z; } - this.m_cached = true; - return this.m_value; + m_cached = true; + return m_value; } #endregion diff --git a/Operator/Clamp.cs b/Operator/Clamp.cs index 3274717..af4eb01 100755 --- a/Operator/Clamp.cs +++ b/Operator/Clamp.cs @@ -1,7 +1,7 @@ -namespace LibNoise.Unity.Operator +using System.Diagnostics; + +namespace LibNoise.Unity.Operator { - using System; - /// /// Provides a noise module that clamps the output value from a source module to a /// range of values. [OPERATOR] @@ -32,7 +32,7 @@ public Clamp() public Clamp(ModuleBase input) : base(1) { - this.m_modules[0] = input; + m_modules[0] = input; } /// @@ -44,9 +44,9 @@ public Clamp(ModuleBase input) public Clamp(double min, double max, ModuleBase input) : base(1) { - this.Minimum = min; - this.Maximum = max; - this.m_modules[0] = input; + Minimum = min; + Maximum = max; + m_modules[0] = input; } #endregion @@ -58,8 +58,8 @@ public Clamp(double min, double max, ModuleBase input) /// public double Maximum { - get { return this.m_max; } - set { this.m_max = value; } + get { return m_max; } + set { m_max = value; } } /// @@ -67,8 +67,8 @@ public double Maximum /// public double Minimum { - get { return this.m_min; } - set { this.m_min = value; } + get { return m_min; } + set { m_min = value; } } #endregion @@ -82,9 +82,9 @@ public double Minimum /// The maximum value. public void SetBounds(double min, double max) { - System.Diagnostics.Debug.Assert(min < max); - this.m_min = min; - this.m_max = max; + Debug.Assert(min < max); + m_min = min; + m_max = max; } #endregion @@ -100,21 +100,21 @@ public void SetBounds(double min, double max) /// The resulting output value. public override double GetValue(double x, double y, double z) { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - if (this.m_min > this.m_max) + Debug.Assert(m_modules[0] != null); + if (m_min > m_max) { - double t = this.m_min; - this.m_min = this.m_max; - this.m_max = t; + var t = m_min; + m_min = m_max; + m_max = t; } - double v = this.m_modules[0].GetValue(x, y, z); - if (v < this.m_min) + var v = m_modules[0].GetValue(x, y, z); + if (v < m_min) { - return this.m_min; + return m_min; } - else if (v > this.m_max) + if (v > m_max) { - return this.m_max; + return m_max; } return v; } diff --git a/Operator/Curve.cs b/Operator/Curve.cs index 00d864f..22c92c9 100755 --- a/Operator/Curve.cs +++ b/Operator/Curve.cs @@ -1,10 +1,9 @@ -namespace LibNoise.Unity.Operator -{ - using System; - using System.Collections.Generic; - - using UnityEngine; +using System.Collections.Generic; +using UnityEngine; +using Debug = System.Diagnostics.Debug; +namespace LibNoise.Unity.Operator +{ /// /// Provides a noise module that maps the output value from a source module onto an /// arbitrary function curve. [OPERATOR] @@ -13,7 +12,7 @@ public class Curve : ModuleBase { #region Fields - private List> m_data = new List>(); + private readonly List> m_data = new List>(); #endregion @@ -34,7 +33,7 @@ public Curve() public Curve(ModuleBase input) : base(1) { - this.m_modules[0] = input; + m_modules[0] = input; } #endregion @@ -46,7 +45,7 @@ public Curve(ModuleBase input) /// public int ControlPointCount { - get { return this.m_data.Count; } + get { return m_data.Count; } } /// @@ -54,7 +53,7 @@ public int ControlPointCount /// public List> ControlPoints { - get { return this.m_data; } + get { return m_data; } } #endregion @@ -68,13 +67,16 @@ public List> ControlPoints /// The curves output value. public void Add(double input, double output) { - KeyValuePair kvp = new KeyValuePair(input, output); - if (!this.m_data.Contains(kvp)) + var kvp = new KeyValuePair(input, output); + if (!m_data.Contains(kvp)) { - this.m_data.Add(kvp); + m_data.Add(kvp); } - this.m_data.Sort(delegate(KeyValuePair lhs, KeyValuePair rhs) - { return lhs.Key.CompareTo(rhs.Key); }); + m_data.Sort( + delegate(KeyValuePair lhs, KeyValuePair rhs) + { + return lhs.Key.CompareTo(rhs.Key); + }); } /// @@ -82,7 +84,7 @@ public void Add(double input, double output) /// public void Clear() { - this.m_data.Clear(); + m_data.Clear(); } #endregion @@ -98,31 +100,32 @@ public void Clear() /// The resulting output value. public override double GetValue(double x, double y, double z) { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - System.Diagnostics.Debug.Assert(this.ControlPointCount >= 4); - double smv = this.m_modules[0].GetValue(x, y, z); + Debug.Assert(m_modules[0] != null); + Debug.Assert(ControlPointCount >= 4); + var smv = m_modules[0].GetValue(x, y, z); int ip; - for (ip = 0; ip < this.m_data.Count; ip++) + for (ip = 0; ip < m_data.Count; ip++) { - if (smv < this.m_data[ip].Key) + if (smv < m_data[ip].Key) { break; } } - int i0 = (int)Mathf.Clamp(ip - 2, 0, this.m_data.Count - 1); - int i1 = (int)Mathf.Clamp(ip - 1, 0, this.m_data.Count - 1); - int i2 = (int)Mathf.Clamp(ip, 0, this.m_data.Count - 1); - int i3 = (int)Mathf.Clamp(ip + 1, 0, this.m_data.Count - 1); + var i0 = Mathf.Clamp(ip - 2, 0, m_data.Count - 1); + var i1 = Mathf.Clamp(ip - 1, 0, m_data.Count - 1); + var i2 = Mathf.Clamp(ip, 0, m_data.Count - 1); + var i3 = Mathf.Clamp(ip + 1, 0, m_data.Count - 1); if (i1 == i2) { - return this.m_data[i1].Value; + return m_data[i1].Value; } - //double ip0 = this.m_data[i1].Value; - //double ip1 = this.m_data[i2].Value; - double ip0 = this.m_data[i1].Key; - double ip1 = this.m_data[i2].Key; - double a = (smv - ip0) / (ip1 - ip0); - return Utils.InterpolateCubic(this.m_data[i0].Value, this.m_data[i1].Value, this.m_data[i2].Value, this.m_data[i3].Value, a); + //double ip0 = m_data[i1].Value; + //double ip1 = m_data[i2].Value; + var ip0 = m_data[i1].Key; + var ip1 = m_data[i2].Key; + var a = (smv - ip0) / (ip1 - ip0); + return Utils.InterpolateCubic(m_data[i0].Value, m_data[i1].Value, m_data[i2].Value, + m_data[i3].Value, a); } #endregion diff --git a/Operator/Displace.cs b/Operator/Displace.cs index 53fb792..1eba86c 100755 --- a/Operator/Displace.cs +++ b/Operator/Displace.cs @@ -1,7 +1,7 @@ -namespace LibNoise.Unity.Operator +using System.Diagnostics; + +namespace LibNoise.Unity.Operator { - using System; - /// /// Provides a noise module that uses three source modules to displace each /// coordinate of the input value before returning the output value from @@ -29,10 +29,10 @@ public Displace() public Displace(ModuleBase input, ModuleBase x, ModuleBase y, ModuleBase z) : base(4) { - this.m_modules[0] = input; - this.m_modules[1] = x; - this.m_modules[2] = y; - this.m_modules[3] = z; + m_modules[0] = input; + m_modules[1] = x; + m_modules[2] = y; + m_modules[3] = z; } #endregion @@ -44,11 +44,11 @@ public Displace(ModuleBase input, ModuleBase x, ModuleBase y, ModuleBase z) /// public ModuleBase X { - get { return this.m_modules[1]; } + get { return m_modules[1]; } set { - System.Diagnostics.Debug.Assert(value != null); - this.m_modules[1] = value; + Debug.Assert(value != null); + m_modules[1] = value; } } @@ -57,11 +57,11 @@ public ModuleBase X /// public ModuleBase Y { - get { return this.m_modules[2]; } + get { return m_modules[2]; } set { - System.Diagnostics.Debug.Assert(value != null); - this.m_modules[2] = value; + Debug.Assert(value != null); + m_modules[2] = value; } } @@ -70,11 +70,11 @@ public ModuleBase Y /// public ModuleBase Z { - get { return this.m_modules[3]; } + get { return m_modules[3]; } set { - System.Diagnostics.Debug.Assert(value != null); - this.m_modules[3] = value; + Debug.Assert(value != null); + m_modules[3] = value; } } @@ -91,16 +91,16 @@ public ModuleBase Z /// The resulting output value. public override double GetValue(double x, double y, double z) { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - System.Diagnostics.Debug.Assert(this.m_modules[1] != null); - System.Diagnostics.Debug.Assert(this.m_modules[2] != null); - System.Diagnostics.Debug.Assert(this.m_modules[3] != null); - double dx = x + this.m_modules[1].GetValue(x, y, z); - double dy = y + this.m_modules[2].GetValue(x, y, z); - double dz = z + this.m_modules[3].GetValue(x, y, z); - return this.m_modules[0].GetValue(dx, dy, dz); + Debug.Assert(m_modules[0] != null); + Debug.Assert(m_modules[1] != null); + Debug.Assert(m_modules[2] != null); + Debug.Assert(m_modules[3] != null); + var dx = x + m_modules[1].GetValue(x, y, z); + var dy = y + m_modules[2].GetValue(x, y, z); + var dz = z + m_modules[3].GetValue(x, y, z); + return m_modules[0].GetValue(dx, dy, dz); } #endregion } -} +} \ No newline at end of file diff --git a/Operator/Exponent.cs b/Operator/Exponent.cs index 075bf8c..7c5826a 100755 --- a/Operator/Exponent.cs +++ b/Operator/Exponent.cs @@ -1,7 +1,8 @@ -namespace LibNoise.Unity.Operator +using System; +using System.Diagnostics; + +namespace LibNoise.Unity.Operator { - using System; - /// /// Provides a noise module that maps the output value from a source module onto an /// exponential curve. [OPERATOR] @@ -31,7 +32,7 @@ public Exponent() public Exponent(ModuleBase input) : base(1) { - this.m_modules[0] = input; + m_modules[0] = input; } /// @@ -42,8 +43,8 @@ public Exponent(ModuleBase input) public Exponent(double exponent, ModuleBase input) : base(1) { - this.m_modules[0] = input; - this.Value = exponent; + m_modules[0] = input; + Value = exponent; } #endregion @@ -55,8 +56,8 @@ public Exponent(double exponent, ModuleBase input) /// public double Value { - get { return this.m_exponent; } - set { this.m_exponent = value; } + get { return m_exponent; } + set { m_exponent = value; } } #endregion @@ -72,9 +73,9 @@ public double Value /// The resulting output value. public override double GetValue(double x, double y, double z) { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - double v = this.m_modules[0].GetValue(x, y, z); - return (Math.Pow(Math.Abs((v + 1.0) / 2.0), this.m_exponent) * 2.0 - 1.0); + Debug.Assert(m_modules[0] != null); + var v = m_modules[0].GetValue(x, y, z); + return (Math.Pow(Math.Abs((v + 1.0) / 2.0), m_exponent) * 2.0 - 1.0); } #endregion diff --git a/Operator/Invert.cs b/Operator/Invert.cs index 80ca3ee..12015ed 100755 --- a/Operator/Invert.cs +++ b/Operator/Invert.cs @@ -1,7 +1,7 @@ -namespace LibNoise.Unity.Operator +using System.Diagnostics; + +namespace LibNoise.Unity.Operator { - using System; - /// /// Provides a noise module that inverts the output value from a source module. [OPERATOR] /// @@ -24,7 +24,7 @@ public Invert() public Invert(ModuleBase input) : base(1) { - this.m_modules[0] = input; + m_modules[0] = input; } #endregion @@ -40,8 +40,8 @@ public Invert(ModuleBase input) /// The resulting output value. public override double GetValue(double x, double y, double z) { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - return -this.m_modules[0].GetValue(x, y, z); + Debug.Assert(m_modules[0] != null); + return -m_modules[0].GetValue(x, y, z); } #endregion diff --git a/Operator/Max.cs b/Operator/Max.cs index e6fc665..92a13b4 100755 --- a/Operator/Max.cs +++ b/Operator/Max.cs @@ -1,7 +1,8 @@ -namespace LibNoise.Unity.Operator +using System; +using System.Diagnostics; + +namespace LibNoise.Unity.Operator { - using System; - /// /// Provides a noise module that outputs the larger of the two output values from two /// source modules. [OPERATOR] @@ -26,8 +27,8 @@ public Max() public Max(ModuleBase lhs, ModuleBase rhs) : base(2) { - this.m_modules[0] = lhs; - this.m_modules[1] = rhs; + m_modules[0] = lhs; + m_modules[1] = rhs; } #endregion @@ -43,10 +44,10 @@ public Max(ModuleBase lhs, ModuleBase rhs) /// The resulting output value. public override double GetValue(double x, double y, double z) { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - System.Diagnostics.Debug.Assert(this.m_modules[1] != null); - double a = this.m_modules[0].GetValue(x, y, z); - double b = this.m_modules[1].GetValue(x, y, z); + Debug.Assert(m_modules[0] != null); + Debug.Assert(m_modules[1] != null); + var a = m_modules[0].GetValue(x, y, z); + var b = m_modules[1].GetValue(x, y, z); return Math.Max(a, b); } diff --git a/Operator/Min.cs b/Operator/Min.cs index 7df7c6b..a855e6d 100755 --- a/Operator/Min.cs +++ b/Operator/Min.cs @@ -1,7 +1,8 @@ -namespace LibNoise.Unity.Operator +using System; +using System.Diagnostics; + +namespace LibNoise.Unity.Operator { - using System; - /// /// Provides a noise module that outputs the smaller of the two output values from two /// source modules. [OPERATOR] @@ -26,8 +27,8 @@ public Min() public Min(ModuleBase lhs, ModuleBase rhs) : base(2) { - this.m_modules[0] = lhs; - this.m_modules[1] = rhs; + m_modules[0] = lhs; + m_modules[1] = rhs; } #endregion @@ -43,10 +44,10 @@ public Min(ModuleBase lhs, ModuleBase rhs) /// The resulting output value. public override double GetValue(double x, double y, double z) { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - System.Diagnostics.Debug.Assert(this.m_modules[1] != null); - double a = this.m_modules[0].GetValue(x, y, z); - double b = this.m_modules[1].GetValue(x, y, z); + Debug.Assert(m_modules[0] != null); + Debug.Assert(m_modules[1] != null); + var a = m_modules[0].GetValue(x, y, z); + var b = m_modules[1].GetValue(x, y, z); return Math.Min(a, b); } diff --git a/Operator/Multiply.cs b/Operator/Multiply.cs index 9921cc9..2558ffc 100755 --- a/Operator/Multiply.cs +++ b/Operator/Multiply.cs @@ -1,7 +1,7 @@ -namespace LibNoise.Unity.Operator +using System.Diagnostics; + +namespace LibNoise.Unity.Operator { - using System; - /// /// Provides a noise module that outputs the product of the two output values from /// two source modules. [OPERATOR] @@ -26,8 +26,8 @@ public Multiply() public Multiply(ModuleBase lhs, ModuleBase rhs) : base(2) { - this.m_modules[0] = lhs; - this.m_modules[1] = rhs; + m_modules[0] = lhs; + m_modules[1] = rhs; } #endregion @@ -43,9 +43,9 @@ public Multiply(ModuleBase lhs, ModuleBase rhs) /// The resulting output value. public override double GetValue(double x, double y, double z) { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - System.Diagnostics.Debug.Assert(this.m_modules[1] != null); - return this.m_modules[0].GetValue(x, y, z) * this.m_modules[1].GetValue(x, y, z); + Debug.Assert(m_modules[0] != null); + Debug.Assert(m_modules[1] != null); + return m_modules[0].GetValue(x, y, z) * m_modules[1].GetValue(x, y, z); } #endregion diff --git a/Operator/Power.cs b/Operator/Power.cs index 607d34b..fe68267 100755 --- a/Operator/Power.cs +++ b/Operator/Power.cs @@ -1,7 +1,8 @@ -namespace LibNoise.Unity.Operator +using System; +using System.Diagnostics; + +namespace LibNoise.Unity.Operator { - using System; - /// /// Provides a noise module that outputs value from a first source module /// to the power of the output value from a second source module. [OPERATOR] @@ -26,8 +27,8 @@ public Power() public Power(ModuleBase lhs, ModuleBase rhs) : base(2) { - this.m_modules[0] = lhs; - this.m_modules[1] = rhs; + m_modules[0] = lhs; + m_modules[1] = rhs; } #endregion @@ -43,9 +44,9 @@ public Power(ModuleBase lhs, ModuleBase rhs) /// The resulting output value. public override double GetValue(double x, double y, double z) { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - System.Diagnostics.Debug.Assert(this.m_modules[1] != null); - return Math.Pow(this.m_modules[0].GetValue(x, y, z), this.m_modules[1].GetValue(x, y, z)); + Debug.Assert(m_modules[0] != null); + Debug.Assert(m_modules[1] != null); + return Math.Pow(m_modules[0].GetValue(x, y, z), m_modules[1].GetValue(x, y, z)); } #endregion diff --git a/Operator/Rotate.cs b/Operator/Rotate.cs index b085a18..1adc258 100755 --- a/Operator/Rotate.cs +++ b/Operator/Rotate.cs @@ -1,150 +1,150 @@ -namespace LibNoise.Unity.Operator +using System; +using UnityEngine; +using Debug = System.Diagnostics.Debug; + +namespace LibNoise.Unity.Operator { - using System; - - using UnityEngine; - - /// - /// Provides a noise module that rotates the input value around the origin before - /// returning the output value from a source module. [OPERATOR] - /// - public class Rotate : ModuleBase - { - #region Fields - - private double m_x = 0.0; - private double m_x1Matrix = 0.0; - private double m_x2Matrix = 0.0; - private double m_x3Matrix = 0.0; - private double m_y = 0.0; - private double m_y1Matrix = 0.0; - private double m_y2Matrix = 0.0; - private double m_y3Matrix = 0.0; - private double m_z = 0.0; - private double m_z1Matrix = 0.0; - private double m_z2Matrix = 0.0; - private double m_z3Matrix = 0.0; - - #endregion - - #region Constructors - - /// - /// Initializes a new instance of Rotate. - /// - public Rotate() - : base(1) - { - this.SetAngles(0.0, 0.0, 0.0); - } - - /// - /// Initializes a new instance of Rotate. - /// - /// The input module. - public Rotate(ModuleBase input) - : base(1) - { - this.m_modules[0] = input; - } - - /// - /// Initializes a new instance of Rotate. - /// - /// The rotation around the x-axis. - /// The rotation around the y-axis. - /// The rotation around the z-axis. - /// The input module. - public Rotate(double x, double y, double z, ModuleBase input) - : base(1) - { - this.m_modules[0] = input; - this.SetAngles(x, y, z); - } - - #endregion - - #region Properties - - /// - /// Gets or sets the rotation around the x-axis in degree. - /// - public double X - { - get { return this.m_x; } - set { this.SetAngles(value, this.m_y, this.m_z); } - } - - /// - /// Gets or sets the rotation around the y-axis in degree. - /// - public double Y - { - get { return this.m_y; } - set { this.SetAngles(this.m_x, value, this.m_z); } - } - - /// - /// Gets or sets the rotation around the z-axis in degree. - /// - public double Z - { - get { return this.m_x; } - set { this.SetAngles(this.m_x, this.m_y, value); } - } - - #endregion - - #region Methods - - /// - /// Sets the rotation angles. - /// - /// The rotation around the x-axis. - /// The rotation around the y-axis. - /// The rotation around the z-axis. - private void SetAngles(double x, double y, double z) - { - double xc = Math.Cos(x * Mathf.Deg2Rad); - double yc = Math.Cos(y * Mathf.Deg2Rad); - double zc = Math.Cos(z * Mathf.Deg2Rad); - double xs = Math.Sin(x * Mathf.Deg2Rad); - double ys = Math.Sin(y * Mathf.Deg2Rad); - double zs = Math.Sin(z * Mathf.Deg2Rad); - this.m_x1Matrix = ys * xs * zs + yc * zc; - this.m_y1Matrix = xc * zs; - this.m_z1Matrix = ys * zc - yc * xs * zs; - this.m_x2Matrix = ys * xs * zc - yc * zs; - this.m_y2Matrix = xc * zc; - this.m_z2Matrix = -yc * xs * zc - ys * zs; - this.m_x3Matrix = -ys * xc; - this.m_y3Matrix = xs; - this.m_z3Matrix = yc * xc; - this.m_x = x; - this.m_y = y; - this.m_z = z; - } - - #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) - { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - double nx = (this.m_x1Matrix * x) + (this.m_y1Matrix * y) + (this.m_z1Matrix * z); - double ny = (this.m_x2Matrix * x) + (this.m_y2Matrix * y) + (this.m_z2Matrix * z); - double nz = (this.m_x3Matrix * x) + (this.m_y3Matrix * y) + (this.m_z3Matrix * z); - return this.m_modules[0].GetValue(nx, ny, nz); - } - - #endregion - } + /// + /// Provides a noise module that rotates the input value around the origin before + /// returning the output value from a source module. [OPERATOR] + /// + public class Rotate : ModuleBase + { + #region Fields + + private double m_x; + private double m_x1Matrix; + private double m_x2Matrix; + private double m_x3Matrix; + private double m_y; + private double m_y1Matrix; + private double m_y2Matrix; + private double m_y3Matrix; + private double m_z; + private double m_z1Matrix; + private double m_z2Matrix; + private double m_z3Matrix; + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of Rotate. + /// + public Rotate() + : base(1) + { + SetAngles(0.0, 0.0, 0.0); + } + + /// + /// Initializes a new instance of Rotate. + /// + /// The input module. + public Rotate(ModuleBase input) + : base(1) + { + m_modules[0] = input; + } + + /// + /// Initializes a new instance of Rotate. + /// + /// The rotation around the x-axis. + /// The rotation around the y-axis. + /// The rotation around the z-axis. + /// The input module. + public Rotate(double x, double y, double z, ModuleBase input) + : base(1) + { + m_modules[0] = input; + SetAngles(x, y, z); + } + + #endregion + + #region Properties + + /// + /// Gets or sets the rotation around the x-axis in degree. + /// + public double X + { + get { return m_x; } + set { SetAngles(value, m_y, m_z); } + } + + /// + /// Gets or sets the rotation around the y-axis in degree. + /// + public double Y + { + get { return m_y; } + set { SetAngles(m_x, value, m_z); } + } + + /// + /// Gets or sets the rotation around the z-axis in degree. + /// + public double Z + { + get { return m_x; } + set { SetAngles(m_x, m_y, value); } + } + + #endregion + + #region Methods + + /// + /// Sets the rotation angles. + /// + /// The rotation around the x-axis. + /// The rotation around the y-axis. + /// The rotation around the z-axis. + private void SetAngles(double x, double y, double z) + { + var xc = Math.Cos(x * Mathf.Deg2Rad); + var yc = Math.Cos(y * Mathf.Deg2Rad); + var zc = Math.Cos(z * Mathf.Deg2Rad); + var xs = Math.Sin(x * Mathf.Deg2Rad); + var ys = Math.Sin(y * Mathf.Deg2Rad); + var zs = Math.Sin(z * Mathf.Deg2Rad); + m_x1Matrix = ys * xs * zs + yc * zc; + m_y1Matrix = xc * zs; + m_z1Matrix = ys * zc - yc * xs * zs; + m_x2Matrix = ys * xs * zc - yc * zs; + m_y2Matrix = xc * zc; + m_z2Matrix = -yc * xs * zc - ys * zs; + m_x3Matrix = -ys * xc; + m_y3Matrix = xs; + m_z3Matrix = yc * xc; + m_x = x; + m_y = y; + m_z = z; + } + + #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(m_modules[0] != null); + var nx = (m_x1Matrix * x) + (m_y1Matrix * y) + (m_z1Matrix * z); + var ny = (m_x2Matrix * x) + (m_y2Matrix * y) + (m_z2Matrix * z); + var nz = (m_x3Matrix * x) + (m_y3Matrix * y) + (m_z3Matrix * z); + return m_modules[0].GetValue(nx, ny, nz); + } + + #endregion + } } \ No newline at end of file diff --git a/Operator/Scale.cs b/Operator/Scale.cs index 7461b91..a75d429 100755 --- a/Operator/Scale.cs +++ b/Operator/Scale.cs @@ -1,7 +1,7 @@ -namespace LibNoise.Unity.Operator +using System.Diagnostics; + +namespace LibNoise.Unity.Operator { - using System; - /// /// Provides a noise module that scales the coordinates of the input value before /// returning the output value from a source module. [OPERATOR] @@ -33,7 +33,7 @@ public Scale() public Scale(ModuleBase input) : base(1) { - this.m_modules[0] = input; + m_modules[0] = input; } /// @@ -46,10 +46,10 @@ public Scale(ModuleBase input) public Scale(double x, double y, double z, ModuleBase input) : base(1) { - this.m_modules[0] = input; - this.X = x; - this.Y = y; - this.Z = z; + m_modules[0] = input; + X = x; + Y = y; + Z = z; } #endregion @@ -61,8 +61,8 @@ public Scale(double x, double y, double z, ModuleBase input) /// public double X { - get { return this.m_x; } - set { this.m_x = value; } + get { return m_x; } + set { m_x = value; } } /// @@ -70,8 +70,8 @@ public double X /// public double Y { - get { return this.m_y; } - set { this.m_y = value; } + get { return m_y; } + set { m_y = value; } } /// @@ -79,8 +79,8 @@ public double Y /// public double Z { - get { return this.m_z; } - set { this.m_z = value; } + get { return m_z; } + set { m_z = value; } } #endregion @@ -96,8 +96,8 @@ public double Z /// The resulting output value. public override double GetValue(double x, double y, double z) { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - return this.m_modules[0].GetValue(x * this.m_x, y * this.m_y, z * this.m_z); + Debug.Assert(m_modules[0] != null); + return m_modules[0].GetValue(x * m_x, y * m_y, z * m_z); } #endregion diff --git a/Operator/ScaleBias.cs b/Operator/ScaleBias.cs index 4ee9518..0ca11c4 100755 --- a/Operator/ScaleBias.cs +++ b/Operator/ScaleBias.cs @@ -1,7 +1,7 @@ -namespace LibNoise.Unity.Operator +using System.Diagnostics; + +namespace LibNoise.Unity.Operator { - using System; - /// /// Provides a noise module that applies a scaling factor and a bias to the output /// value from a source module. [OPERATOR] @@ -11,7 +11,7 @@ public class ScaleBias : ModuleBase #region Fields private double m_scale = 1.0; - private double m_bias = 0.0; + private double m_bias; #endregion @@ -32,7 +32,7 @@ public ScaleBias() public ScaleBias(ModuleBase input) : base(1) { - this.m_modules[0] = input; + m_modules[0] = input; } /// @@ -44,9 +44,9 @@ public ScaleBias(ModuleBase input) public ScaleBias(double scale, double bias, ModuleBase input) : base(1) { - this.m_modules[0] = input; - this.Bias = bias; - this.Scale = scale; + m_modules[0] = input; + Bias = bias; + Scale = scale; } #endregion @@ -58,8 +58,8 @@ public ScaleBias(double scale, double bias, ModuleBase input) /// public double Bias { - get { return this.m_bias; } - set { this.m_bias = value; } + get { return m_bias; } + set { m_bias = value; } } /// @@ -67,8 +67,8 @@ public double Bias /// public double Scale { - get { return this.m_scale; } - set { this.m_scale = value; } + get { return m_scale; } + set { m_scale = value; } } #endregion @@ -84,8 +84,8 @@ public double Scale /// The resulting output value. public override double GetValue(double x, double y, double z) { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - return this.m_modules[0].GetValue(x, y, z) * this.m_scale + this.m_bias; + Debug.Assert(m_modules[0] != null); + return m_modules[0].GetValue(x, y, z) * m_scale + m_bias; } #endregion diff --git a/Operator/Select.cs b/Operator/Select.cs index cf7276f..1576a96 100755 --- a/Operator/Select.cs +++ b/Operator/Select.cs @@ -1,7 +1,7 @@ -namespace LibNoise.Unity.Operator +using System.Diagnostics; + +namespace LibNoise.Unity.Operator { - using System; - /// /// Provides a noise module that outputs the value selected from one of two source /// modules chosen by the output value from a control module. [OPERATOR] @@ -10,8 +10,8 @@ public class Select : ModuleBase { #region Fields - private double m_fallOff = 0.0; - private double m_raw = 0.0; + private double m_fallOff; + private double m_raw; private double m_min = -1.0; private double m_max = 1.0; @@ -26,7 +26,7 @@ public Select() : base(3) { } - + /// /// Initializes a new instance of Select. /// @@ -36,10 +36,10 @@ public Select() public Select(ModuleBase inputA, ModuleBase inputB, ModuleBase controller) : base(3) { - this.m_modules[0] = inputA; - this.m_modules[1] = inputB; - this.m_modules[2] = controller; - } + m_modules[0] = inputA; + m_modules[1] = inputB; + m_modules[2] = controller; + } /// /// Initializes a new instance of Select. @@ -52,9 +52,9 @@ public Select(ModuleBase inputA, ModuleBase inputB, ModuleBase controller) public Select(double min, double max, double fallOff, ModuleBase inputA, ModuleBase inputB) : this(inputA, inputB, null) { - this.m_min = min; - this.m_max = max; - this.FallOff = fallOff; + m_min = min; + m_max = max; + FallOff = fallOff; } #endregion @@ -66,11 +66,11 @@ public Select(double min, double max, double fallOff, ModuleBase inputA, ModuleB /// public ModuleBase Controller { - get { return this.m_modules[2]; } + get { return m_modules[2]; } set { - System.Diagnostics.Debug.Assert(value != null); - this.m_modules[2] = value; + Debug.Assert(value != null); + m_modules[2] = value; } } @@ -79,12 +79,12 @@ public ModuleBase Controller /// public double FallOff { - get { return this.m_fallOff; } + get { return m_fallOff; } set { - double bs = this.m_max - this.m_min; - this.m_raw = value; - this.m_fallOff = (value > bs / 2) ? bs / 2 : value; + var bs = m_max - m_min; + m_raw = value; + m_fallOff = (value > bs / 2) ? bs / 2 : value; } } @@ -93,11 +93,11 @@ public double FallOff /// public double Maximum { - get { return this.m_max; } + get { return m_max; } set { - this.m_max = value; - this.FallOff = this.m_raw; + m_max = value; + FallOff = m_raw; } } @@ -106,11 +106,11 @@ public double Maximum /// public double Minimum { - get { return this.m_min; } + get { return m_min; } set { - this.m_min = value; - this.FallOff = this.m_raw; + m_min = value; + FallOff = m_raw; } } @@ -125,10 +125,10 @@ public double Minimum /// The maximum value. public void SetBounds(double min, double max) { - System.Diagnostics.Debug.Assert(min < max); - this.m_min = min; - this.m_max = max; - this.FallOff = this.m_fallOff; + Debug.Assert(min < max); + m_min = min; + m_max = max; + FallOff = m_fallOff; } #endregion @@ -144,47 +144,44 @@ public void SetBounds(double min, double max) /// The resulting output value. public override double GetValue(double x, double y, double z) { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - System.Diagnostics.Debug.Assert(this.m_modules[1] != null); - System.Diagnostics.Debug.Assert(this.m_modules[2] != null); - double cv = this.m_modules[2].GetValue(x, y, z); + Debug.Assert(m_modules[0] != null); + Debug.Assert(m_modules[1] != null); + Debug.Assert(m_modules[2] != null); + var cv = m_modules[2].GetValue(x, y, z); double a; - if (this.m_fallOff > 0.0) + if (m_fallOff > 0.0) { - if (cv < (this.m_min - this.m_fallOff)) + if (cv < (m_min - m_fallOff)) { - return this.m_modules[0].GetValue(x, y, z); + return m_modules[0].GetValue(x, y, z); } - else if (cv < (this.m_min + this.m_fallOff)) + if (cv < (m_min + m_fallOff)) { - double lc = (this.m_min - this.m_fallOff); - double uc = (this.m_min + this.m_fallOff); + var lc = (m_min - m_fallOff); + var uc = (m_min + m_fallOff); a = Utils.MapCubicSCurve((cv - lc) / (uc - lc)); - return Utils.InterpolateLinear(this.m_modules[0].GetValue(x, y, z), this.m_modules[1].GetValue(x, y, z), a); - + return Utils.InterpolateLinear(m_modules[0].GetValue(x, y, z), + m_modules[1].GetValue(x, y, z), a); } - else if (cv < (this.m_max - this.m_fallOff)) + if (cv < (m_max - m_fallOff)) { - return this.m_modules[1].GetValue(x, y, z); + return m_modules[1].GetValue(x, y, z); } - else if (cv < (this.m_max + this.m_fallOff)) + if (cv < (m_max + m_fallOff)) { - double lc = (this.m_max - this.m_fallOff); - double uc = (this.m_max + this.m_fallOff); + var lc = (m_max - m_fallOff); + var uc = (m_max + m_fallOff); a = Utils.MapCubicSCurve((cv - lc) / (uc - lc)); - return Utils.InterpolateLinear(this.m_modules[1].GetValue(x, y, z), this.m_modules[0].GetValue(x, y, z), a); - + return Utils.InterpolateLinear(m_modules[1].GetValue(x, y, z), + m_modules[0].GetValue(x, y, z), a); } - return this.m_modules[0].GetValue(x, y, z); + return m_modules[0].GetValue(x, y, z); } - else + if (cv < m_min || cv > m_max) { - if (cv < this.m_min || cv > this.m_max) - { - return this.m_modules[0].GetValue(x, y, z); - } - return this.m_modules[1].GetValue(x, y, z); + return m_modules[0].GetValue(x, y, z); } + return m_modules[1].GetValue(x, y, z); } #endregion diff --git a/Operator/Subtract.cs b/Operator/Subtract.cs index 460e44d..03d49d3 100755 --- a/Operator/Subtract.cs +++ b/Operator/Subtract.cs @@ -1,7 +1,7 @@ -namespace LibNoise.Unity.Operator +using System.Diagnostics; + +namespace LibNoise.Unity.Operator { - using System; - /// /// Provides a noise module that outputs the difference of the two output values from two /// source modules. [OPERATOR] @@ -26,8 +26,8 @@ public Subtract() public Subtract(ModuleBase lhs, ModuleBase rhs) : base(2) { - this.m_modules[0] = lhs; - this.m_modules[1] = rhs; + m_modules[0] = lhs; + m_modules[1] = rhs; } #endregion @@ -43,9 +43,9 @@ public Subtract(ModuleBase lhs, ModuleBase rhs) /// The resulting output value. public override double GetValue(double x, double y, double z) { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - System.Diagnostics.Debug.Assert(this.m_modules[1] != null); - return this.m_modules[0].GetValue(x, y, z) - this.m_modules[1].GetValue(x, y, z); + Debug.Assert(m_modules[0] != null); + Debug.Assert(m_modules[1] != null); + return m_modules[0].GetValue(x, y, z) - m_modules[1].GetValue(x, y, z); } #endregion diff --git a/Operator/Terrace.cs b/Operator/Terrace.cs index 7a607ed..6b2ade6 100755 --- a/Operator/Terrace.cs +++ b/Operator/Terrace.cs @@ -1,10 +1,10 @@ -namespace LibNoise.Unity.Operator -{ - using System; - using System.Collections.Generic; - - using UnityEngine; +using System; +using System.Collections.Generic; +using UnityEngine; +using Debug = System.Diagnostics.Debug; +namespace LibNoise.Unity.Operator +{ /// /// Provides a noise module that maps the output value from a source module onto a /// terrace-forming curve. [OPERATOR] @@ -13,8 +13,8 @@ public class Terrace : ModuleBase { #region Fields - private List m_data = new List(); - private bool m_inverted = false; + private readonly List m_data = new List(); + private bool m_inverted; #endregion @@ -35,7 +35,7 @@ public Terrace() public Terrace(ModuleBase input) : base(1) { - this.m_modules[0] = input; + m_modules[0] = input; } /// @@ -46,8 +46,8 @@ public Terrace(ModuleBase input) public Terrace(bool inverted, ModuleBase input) : base(1) { - this.m_modules[0] = input; - this.IsInverted = inverted; + m_modules[0] = input; + IsInverted = inverted; } #endregion @@ -59,7 +59,7 @@ public Terrace(bool inverted, ModuleBase input) /// public int ControlPointCount { - get { return this.m_data.Count; } + get { return m_data.Count; } } /// @@ -67,7 +67,7 @@ public int ControlPointCount /// public List ControlPoints { - get { return this.m_data; } + get { return m_data; } } /// @@ -75,8 +75,8 @@ public List ControlPoints /// public bool IsInverted { - get { return this.m_inverted; } - set { this.m_inverted = value; } + get { return m_inverted; } + set { m_inverted = value; } } #endregion @@ -89,11 +89,11 @@ public bool IsInverted /// The curves input value. public void Add(double input) { - if (!this.m_data.Contains(input)) + if (!m_data.Contains(input)) { - this.m_data.Add(input); + m_data.Add(input); } - this.m_data.Sort(delegate(double lhs, double rhs) { return lhs.CompareTo(rhs); }); + m_data.Sort(delegate(double lhs, double rhs) { return lhs.CompareTo(rhs); }); } /// @@ -101,7 +101,7 @@ public void Add(double input) /// public void Clear() { - this.m_data.Clear(); + m_data.Clear(); } /// @@ -114,12 +114,12 @@ public void Generate(int steps) { throw new ArgumentException("Need at least two steps"); } - this.Clear(); - double ts = 2.0 / ((double)steps - 1.0); - double cv = -1.0; - for (int i = 0; i < (int)steps; i++) + Clear(); + var ts = 2.0 / (steps - 1.0); + var cv = -1.0; + for (var i = 0; i < steps; i++) { - this.Add(cv); + Add(cv); cv += ts; } } @@ -137,30 +137,30 @@ public void Generate(int steps) /// The resulting output value. public override double GetValue(double x, double y, double z) { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - System.Diagnostics.Debug.Assert(this.ControlPointCount >= 2); - double smv = this.m_modules[0].GetValue(x, y, z); + Debug.Assert(m_modules[0] != null); + Debug.Assert(ControlPointCount >= 2); + var smv = m_modules[0].GetValue(x, y, z); int ip; - for (ip = 0; ip < this.m_data.Count; ip++) + for (ip = 0; ip < m_data.Count; ip++) { - if (smv < this.m_data[ip]) + if (smv < m_data[ip]) { break; } } - int i0 = (int)Mathf.Clamp(ip - 1, 0, this.m_data.Count - 1); - int i1 = (int)Mathf.Clamp(ip, 0, this.m_data.Count - 1); + var i0 = Mathf.Clamp(ip - 1, 0, m_data.Count - 1); + var i1 = Mathf.Clamp(ip, 0, m_data.Count - 1); if (i0 == i1) { - return this.m_data[i1]; + return m_data[i1]; } - double v0 = this.m_data[i0]; - double v1 = this.m_data[i1]; - double a = (smv - v0) / (v1 - v0); - if (this.m_inverted) + var v0 = m_data[i0]; + var v1 = m_data[i1]; + var a = (smv - v0) / (v1 - v0); + if (m_inverted) { a = 1.0 - a; - double t = v0; + var t = v0; v0 = v1; v1 = t; } diff --git a/Operator/Translate.cs b/Operator/Translate.cs index 6e45d38..6e9799e 100755 --- a/Operator/Translate.cs +++ b/Operator/Translate.cs @@ -1,7 +1,7 @@ -namespace LibNoise.Unity.Operator +using System.Diagnostics; + +namespace LibNoise.Unity.Operator { - using System; - /// /// Provides a noise module that moves the coordinates of the input value before /// returning the output value from a source module. [OPERATOR] @@ -33,7 +33,7 @@ public Translate() public Translate(ModuleBase input) : base(1) { - this.m_modules[0] = input; + m_modules[0] = input; } /// @@ -46,10 +46,10 @@ public Translate(ModuleBase input) public Translate(double x, double y, double z, ModuleBase input) : base(1) { - this.m_modules[0] = input; - this.X = x; - this.Y = y; - this.Z = z; + m_modules[0] = input; + X = x; + Y = y; + Z = z; } #endregion @@ -61,8 +61,8 @@ public Translate(double x, double y, double z, ModuleBase input) /// public double X { - get { return this.m_x; } - set { this.m_x = value; } + get { return m_x; } + set { m_x = value; } } /// @@ -70,8 +70,8 @@ public double X /// public double Y { - get { return this.m_y; } - set { this.m_y = value; } + get { return m_y; } + set { m_y = value; } } /// @@ -79,8 +79,8 @@ public double Y /// public double Z { - get { return this.m_z; } - set { this.m_z = value; } + get { return m_z; } + set { m_z = value; } } #endregion @@ -96,8 +96,8 @@ public double Z /// The resulting output value. public override double GetValue(double x, double y, double z) { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - return this.m_modules[0].GetValue(x + this.m_x, y + this.m_y, z + this.m_z); + Debug.Assert(m_modules[0] != null); + return m_modules[0].GetValue(x + m_x, y + m_y, z + m_z); } #endregion diff --git a/Operator/Turbulence.cs b/Operator/Turbulence.cs index ed2b9b8..96f7b19 100755 --- a/Operator/Turbulence.cs +++ b/Operator/Turbulence.cs @@ -1,9 +1,8 @@ -namespace LibNoise.Unity.Operator -{ - using System; - - using LibNoise.Unity.Generator; +using System.Diagnostics; +using LibNoise.Unity.Generator; +namespace LibNoise.Unity.Operator +{ /// /// Provides a noise module that that randomly displaces the input value before /// returning the output value from a source module. [OPERATOR] @@ -27,9 +26,9 @@ public class Turbulence : ModuleBase #region Fields private double m_power = 1.0; - private Perlin m_xDistort = null; - private Perlin m_yDistort = null; - private Perlin m_zDistort = null; + private readonly Perlin m_xDistort; + private readonly Perlin m_yDistort; + private readonly Perlin m_zDistort; #endregion @@ -41,9 +40,9 @@ public class Turbulence : ModuleBase public Turbulence() : base(1) { - this.m_xDistort = new Perlin(); - this.m_yDistort = new Perlin(); - this.m_zDistort = new Perlin(); + m_xDistort = new Perlin(); + m_yDistort = new Perlin(); + m_zDistort = new Perlin(); } /// @@ -53,10 +52,10 @@ public Turbulence() public Turbulence(ModuleBase input) : base(1) { - this.m_xDistort = new Perlin(); - this.m_yDistort = new Perlin(); - this.m_zDistort = new Perlin(); - this.m_modules[0] = input; + m_xDistort = new Perlin(); + m_yDistort = new Perlin(); + m_zDistort = new Perlin(); + m_modules[0] = input; } /// @@ -78,11 +77,11 @@ public Turbulence(double power, ModuleBase input) public Turbulence(Perlin x, Perlin y, Perlin z, double power, ModuleBase input) : base(1) { - this.m_xDistort = x; - this.m_yDistort = y; - this.m_zDistort = z; - this.m_modules[0] = input; - this.Power = power; + m_xDistort = x; + m_yDistort = y; + m_zDistort = z; + m_modules[0] = input; + Power = power; } #endregion @@ -94,12 +93,12 @@ public Turbulence(Perlin x, Perlin y, Perlin z, double power, ModuleBase input) /// public double Frequency { - get { return this.m_xDistort.Frequency; } + get { return m_xDistort.Frequency; } set { - this.m_xDistort.Frequency = value; - this.m_yDistort.Frequency = value; - this.m_zDistort.Frequency = value; + m_xDistort.Frequency = value; + m_yDistort.Frequency = value; + m_zDistort.Frequency = value; } } @@ -108,8 +107,8 @@ public double Frequency /// public double Power { - get { return this.m_power; } - set { this.m_power = value; } + get { return m_power; } + set { m_power = value; } } /// @@ -117,12 +116,12 @@ public double Power /// public int Roughness { - get { return this.m_xDistort.OctaveCount; } + get { return m_xDistort.OctaveCount; } set { - this.m_xDistort.OctaveCount = value; - this.m_yDistort.OctaveCount = value; - this.m_zDistort.OctaveCount = value; + m_xDistort.OctaveCount = value; + m_yDistort.OctaveCount = value; + m_zDistort.OctaveCount = value; } } @@ -131,12 +130,12 @@ public int Roughness /// public int Seed { - get { return this.m_xDistort.Seed; } + get { return m_xDistort.Seed; } set { - this.m_xDistort.Seed = value; - this.m_yDistort.Seed = value + 1; - this.m_zDistort.Seed = value + 2; + m_xDistort.Seed = value; + m_yDistort.Seed = value + 1; + m_zDistort.Seed = value + 2; } } @@ -153,11 +152,11 @@ public int Seed /// The resulting output value. public override double GetValue(double x, double y, double z) { - System.Diagnostics.Debug.Assert(this.m_modules[0] != null); - double xd = x + (this.m_xDistort.GetValue(x + Turbulence.X0, y + Turbulence.Y0, z + Turbulence.Z0) * this.m_power); - double yd = y + (this.m_yDistort.GetValue(x + Turbulence.X1, y + Turbulence.Y1, z + Turbulence.Z1) * this.m_power); - double zd = z + (this.m_zDistort.GetValue(x + Turbulence.X2, y + Turbulence.Y2, z + Turbulence.Z2) * this.m_power); - return this.m_modules[0].GetValue(xd, yd, zd); + Debug.Assert(m_modules[0] != null); + var xd = x + (m_xDistort.GetValue(x + X0, y + Y0, z + Z0) * m_power); + var yd = y + (m_yDistort.GetValue(x + X1, y + Y1, z + Z1) * m_power); + var zd = z + (m_zDistort.GetValue(x + X2, y + Y2, z + Z2) * m_power); + return m_modules[0].GetValue(xd, yd, zd); } #endregion diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 13f9eff..bea621c 100755 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -1,24 +1,30 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. + [assembly: AssemblyTitle("LibNoise.Unity")] [assembly: AssemblyProduct("LibNoise.Unity")] -[assembly: AssemblyDescription("C# Unity Port of LibNoise, Ported from BigBlackBlock Gamestudio port of LibNoise to XNA")] +[assembly: + AssemblyDescription("C# Unity Port of LibNoise, Ported from BigBlackBlock Gamestudio port of LibNoise to XNA")] [assembly: AssemblyCompany("None")] -[assembly: AssemblyCopyright("LibUnity.Xna Copyright © Jason Bevins 2003-2007, 2010 BigBlackBlock Gamestudio, LibNoise.Unity Copyright © 2010 Unity Commons, distributed under the terms on the Lesser GPL")] +[assembly: + AssemblyCopyright( + "LibUnity.Xna Copyright © Jason Bevins 2003-2007, 2010 BigBlackBlock Gamestudio, LibNoise.Unity Copyright © 2010 Unity Commons, distributed under the terms on the Lesser GPL" + )] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. + [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM + [assembly: Guid("aa606d44-f8c3-47aa-a2b5-9156119ff843")] // Version information for an assembly consists of the following four values: @@ -28,4 +34,5 @@ // Build Number // Revision // -[assembly: AssemblyVersion("1.0.0.0")] + +[assembly: AssemblyVersion("1.0.0.0")] \ No newline at end of file diff --git a/Utils.cs b/Utils.cs index 98a7d97..4199d8f 100755 --- a/Utils.cs +++ b/Utils.cs @@ -1,27 +1,27 @@ -namespace LibNoise.Unity +using System; + +namespace LibNoise.Unity { - using System; - internal static class Utils { #region Constants - + internal const double Sqrt3 = 1.7320508075688772935; internal const int OctavesMaximum = 30; - #if NOISE_VERSION_1 +#if NOISE_VERSION_1 private const int GeneratorNoiseX = 1; private const int GeneratorNoiseY = 31337; private const int GeneratorNoiseZ = 263; private const int GeneratorSeed = 1013; private const int GeneratorShift = 13; #else - private const int GeneratorNoiseX = 1619; - private const int GeneratorNoiseY = 31337; - private const int GeneratorNoiseZ = 6971; - private const int GeneratorSeed = 1013; - private const int GeneratorShift = 8; - #endif + private const int GeneratorNoiseX = 1619; + private const int GeneratorNoiseY = 31337; + private const int GeneratorNoiseZ = 6971; + private const int GeneratorSeed = 1013; + private const int GeneratorShift = 8; +#endif #endregion @@ -165,76 +165,76 @@ internal static class Utils internal static double GradientCoherentNoise3D(double x, double y, double z, long seed, QualityMode quality) { - 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; + var x0 = x > 0.0 ? (int) x : (int) x - 1; + var x1 = x0 + 1; + var y0 = y > 0.0 ? (int) y : (int) y - 1; + var y1 = y0 + 1; + var z0 = z > 0.0 ? (int) z : (int) z - 1; + var z1 = z0 + 1; double xs = 0, ys = 0, zs = 0; switch (quality) { case QualityMode.Low: - { - xs = (x - x0); - ys = (y - y0); - zs = (z - z0); - break; - } + { + xs = (x - x0); + ys = (y - y0); + zs = (z - z0); + break; + } case QualityMode.Medium: - { - xs = Utils.MapCubicSCurve(x - x0); - ys = Utils.MapCubicSCurve(y - y0); - zs = Utils.MapCubicSCurve(z - z0); - break; - } + { + xs = MapCubicSCurve(x - x0); + ys = MapCubicSCurve(y - y0); + zs = MapCubicSCurve(z - z0); + break; + } case QualityMode.High: - { - xs = Utils.MapQuinticSCurve(x - x0); - ys = Utils.MapQuinticSCurve(y - y0); - zs = Utils.MapQuinticSCurve(z - z0); - break; - } + { + xs = MapQuinticSCurve(x - x0); + ys = MapQuinticSCurve(y - y0); + zs = MapQuinticSCurve(z - z0); + break; + } } double n0, n1, ix0, ix1, iy0, iy1; - n0 = Utils.GradientNoise3D(x, y, z, x0, y0, z0, seed); - n1 = Utils.GradientNoise3D(x, y, z, x1, y0, z0, seed); - ix0 = Utils.InterpolateLinear(n0, n1, xs); - n0 = Utils.GradientNoise3D(x, y, z, x0, y1, z0, seed); - n1 = Utils.GradientNoise3D(x, y, z, x1, y1, z0, seed); - ix1 = Utils.InterpolateLinear(n0, n1, xs); - iy0 = Utils.InterpolateLinear(ix0, ix1, ys); - n0 = Utils.GradientNoise3D(x, y, z, x0, y0, z1, seed); - n1 = Utils.GradientNoise3D(x, y, z, x1, y0, z1, seed); - ix0 = Utils.InterpolateLinear(n0, n1, xs); - n0 = Utils.GradientNoise3D(x, y, z, x0, y1, z1, seed); - n1 = Utils.GradientNoise3D(x, y, z, x1, y1, z1, seed); - ix1 = Utils.InterpolateLinear(n0, n1, xs); - iy1 = Utils.InterpolateLinear(ix0, ix1, ys); - return Utils.InterpolateLinear(iy0, iy1, zs); + n0 = GradientNoise3D(x, y, z, x0, y0, z0, seed); + n1 = GradientNoise3D(x, y, z, x1, y0, z0, seed); + ix0 = InterpolateLinear(n0, n1, xs); + n0 = GradientNoise3D(x, y, z, x0, y1, z0, seed); + n1 = GradientNoise3D(x, y, z, x1, y1, z0, seed); + ix1 = InterpolateLinear(n0, n1, xs); + iy0 = InterpolateLinear(ix0, ix1, ys); + n0 = GradientNoise3D(x, y, z, x0, y0, z1, seed); + n1 = GradientNoise3D(x, y, z, x1, y0, z1, seed); + ix0 = InterpolateLinear(n0, n1, xs); + n0 = GradientNoise3D(x, y, z, x0, y1, z1, seed); + n1 = GradientNoise3D(x, y, z, x1, y1, z1, seed); + ix1 = InterpolateLinear(n0, n1, xs); + iy1 = InterpolateLinear(ix0, ix1, ys); + return InterpolateLinear(iy0, iy1, zs); } internal static double GradientNoise3D(double fx, double fy, double fz, int ix, int iy, int iz, long seed) { - long i = (Utils.GeneratorNoiseX * ix + Utils.GeneratorNoiseY * iy + Utils.GeneratorNoiseZ * iz + - Utils.GeneratorSeed * seed) & 0xffffffff; - i ^= (i >> Utils.GeneratorShift); + var i = (GeneratorNoiseX * ix + GeneratorNoiseY * iy + GeneratorNoiseZ * iz + + GeneratorSeed * seed) & 0xffffffff; + i ^= (i >> GeneratorShift); i &= 0xff; - double xvg = Utils._randoms[(i << 2)]; - double yvg = Utils._randoms[(i << 2) + 1]; - double zvg = Utils._randoms[(i << 2) + 2]; - double xvp = (fx - ix); - double yvp = (fy - iy); - double zvp = (fz - iz); + var xvg = _randoms[(i << 2)]; + var yvg = _randoms[(i << 2) + 1]; + var zvg = _randoms[(i << 2) + 2]; + var xvp = (fx - ix); + var yvp = (fy - iy); + var zvp = (fz - iz); return ((xvg * xvp) + (yvg * yvp) + (zvg * zvp)) * 2.12; } internal static double InterpolateCubic(double a, double b, double c, double d, double position) { - double p = (d - c) - (a - b); - double q = (a - b) - p; - double r = c - a; - double s = b; + var p = (d - c) - (a - b); + var q = (a - b) - p; + var r = c - a; + var s = b; return p * position * position * position + q * position * position + r * position + s; } @@ -249,14 +249,11 @@ internal static double MakeInt32Range(double value) { return (2.0 * Math.IEEERemainder(value, 1073741824.0)) - 1073741824.0; } - else if (value <= -1073741824.0) + if (value <= -1073741824.0) { return (2.0 * Math.IEEERemainder(value, 1073741824.0)) + 1073741824.0; } - else - { - return value; - } + return value; } internal static double MapCubicSCurve(double value) @@ -266,21 +263,21 @@ internal static double MapCubicSCurve(double value) internal static double MapQuinticSCurve(double value) { - double a3 = value * value * value; - double a4 = a3 * value; - double a5 = a4 * value; + var a3 = value * value * value; + var a4 = a3 * value; + var a5 = a4 * value; return (6.0 * a5) - (15.0 * a4) + (10.0 * a3); } internal static double ValueNoise3D(int x, int y, int z, int seed) { - return 1.0 - ((double)Utils.ValueNoise3DInt(x, y, z, seed) / 1073741824.0); + return 1.0 - (ValueNoise3DInt(x, y, z, seed) / 1073741824.0); } internal static long ValueNoise3DInt(int x, int y, int z, int seed) { - long n = (Utils.GeneratorNoiseX * x + Utils.GeneratorNoiseY * y + Utils.GeneratorNoiseZ * z + - Utils.GeneratorSeed * seed) & 0x7fffffff; + long n = (GeneratorNoiseX * x + GeneratorNoiseY * y + GeneratorNoiseZ * z + + GeneratorSeed * seed) & 0x7fffffff; n = (n >> 13) ^ n; return (n * (n * n * 60493 + 19990303) + 1376312589) & 0x7fffffff; } From b9505db5f79ab529c5691bf860be1ef2ab0edc8e Mon Sep 17 00:00:00 2001 From: "Ricardo J. Mendez" Date: Thu, 17 Jul 2014 06:27:50 +0300 Subject: [PATCH 2/7] Renamed private and public members for consistency with my other libraries Also: - Further code clean-up - Marked TODOs in the code - Fixed comments --- Generator/Billow.cs | 65 +++++---- Generator/Const.cs | 8 +- Generator/Cylinders.cs | 10 +- Generator/Perlin.cs | 65 +++++---- Generator/RidgedMultifractal.cs | 61 +++++---- Generator/Spheres.cs | 12 +- Generator/Voronoi.cs | 41 +++--- GradientPresets.cs | 58 ++++---- ModuleBase.cs | 44 +++--- Noise2D.cs | 232 +++++++++++++++----------------- Operator/Abs.cs | 6 +- Operator/Add.cs | 10 +- Operator/Blend.cs | 22 +-- Operator/Cache.cs | 32 ++--- Operator/Clamp.cs | 40 +++--- Operator/Curve.cs | 46 +++---- Operator/Displace.cs | 36 ++--- Operator/Exponent.cs | 16 +-- Operator/Invert.cs | 6 +- Operator/Max.cs | 12 +- Operator/Min.cs | 12 +- Operator/Multiply.cs | 10 +- Operator/Power.cs | 10 +- Operator/Rotate.cs | 74 +++++----- Operator/Scale.cs | 26 ++-- Operator/ScaleBias.cs | 20 +-- Operator/Select.cs | 98 +++++++------- Operator/Subtract.cs | 10 +- Operator/Terrace.cs | 44 +++--- Operator/Translate.cs | 26 ++-- Operator/Turbulence.cs | 68 +++++----- Utils.cs | 21 ++- 32 files changed, 612 insertions(+), 629 deletions(-) diff --git a/Generator/Billow.cs b/Generator/Billow.cs index e1295f6..cf323d6 100755 --- a/Generator/Billow.cs +++ b/Generator/Billow.cs @@ -10,12 +10,12 @@ public class Billow : ModuleBase { #region Fields - private double m_frequency = 1.0; - private double m_lacunarity = 2.0; - private QualityMode m_quality = QualityMode.Medium; - private int m_octaveCount = 6; - private double m_persistence = 0.5; - private int m_seed; + private double _frequency = 1.0; + private double _lacunarity = 2.0; + private QualityMode _quality = QualityMode.Medium; + private int _octaveCount = 6; + private double _persistence = 0.5; + private int _seed; #endregion @@ -59,8 +59,8 @@ public Billow(double frequency, double lacunarity, double persistence, int octav /// public double Frequency { - get { return m_frequency; } - set { m_frequency = value; } + get { return _frequency; } + set { _frequency = value; } } /// @@ -68,8 +68,8 @@ public double Frequency /// public double Lacunarity { - get { return m_lacunarity; } - set { m_lacunarity = value; } + get { return _lacunarity; } + set { _lacunarity = value; } } /// @@ -77,8 +77,8 @@ public double Lacunarity /// public QualityMode Quality { - get { return m_quality; } - set { m_quality = value; } + get { return _quality; } + set { _quality = value; } } /// @@ -86,8 +86,8 @@ public QualityMode Quality /// public int OctaveCount { - get { return m_octaveCount; } - set { m_octaveCount = Mathf.Clamp(value, 1, Utils.OctavesMaximum); } + get { return _octaveCount; } + set { _octaveCount = Mathf.Clamp(value, 1, Utils.OctavesMaximum); } } /// @@ -95,8 +95,8 @@ public int OctaveCount /// public double Persistence { - get { return m_persistence; } - set { m_persistence = value; } + get { return _persistence; } + set { _persistence = value; } } /// @@ -104,8 +104,8 @@ public double Persistence /// public int Seed { - get { return m_seed; } - set { m_seed = value; } + get { return _seed; } + set { _seed = value; } } #endregion @@ -122,26 +122,23 @@ public int Seed public override double GetValue(double x, double y, double z) { var value = 0.0; - var signal = 0.0; var curp = 1.0; - double nx, ny, nz; - long seed; - x *= m_frequency; - y *= m_frequency; - z *= m_frequency; - for (var i = 0; i < m_octaveCount; i++) + x *= _frequency; + y *= _frequency; + z *= _frequency; + for (var i = 0; i < _octaveCount; i++) { - nx = Utils.MakeInt32Range(x); - ny = Utils.MakeInt32Range(y); - nz = Utils.MakeInt32Range(z); - seed = (m_seed + i) & 0xffffffff; - signal = Utils.GradientCoherentNoise3D(nx, ny, nz, seed, m_quality); + var nx = Utils.MakeInt32Range(x); + var ny = Utils.MakeInt32Range(y); + var nz = Utils.MakeInt32Range(z); + var seed = (_seed + i) & 0xffffffff; + var signal = Utils.GradientCoherentNoise3D(nx, ny, nz, seed, _quality); signal = 2.0 * Math.Abs(signal) - 1.0; value += signal * curp; - x *= m_lacunarity; - y *= m_lacunarity; - z *= m_lacunarity; - curp *= m_persistence; + x *= _lacunarity; + y *= _lacunarity; + z *= _lacunarity; + curp *= _persistence; } return value + 0.5; } diff --git a/Generator/Const.cs b/Generator/Const.cs index 45f5116..5aa4f9c 100755 --- a/Generator/Const.cs +++ b/Generator/Const.cs @@ -7,7 +7,7 @@ public class Const : ModuleBase { #region Fields - private double m_value; + private double _value; #endregion @@ -40,8 +40,8 @@ public Const(double value) /// public double Value { - get { return m_value; } - set { m_value = value; } + get { return _value; } + set { _value = value; } } #endregion @@ -57,7 +57,7 @@ public double Value /// The resulting output value. public override double GetValue(double x, double y, double z) { - return m_value; + return _value; } #endregion diff --git a/Generator/Cylinders.cs b/Generator/Cylinders.cs index c720674..6dc1911 100755 --- a/Generator/Cylinders.cs +++ b/Generator/Cylinders.cs @@ -9,7 +9,7 @@ public class Cylinders : ModuleBase { #region Fields - private double m_frequency = 1.0; + private double _frequency = 1.0; #endregion @@ -42,8 +42,8 @@ public Cylinders(double frequency) /// public double Frequency { - get { return m_frequency; } - set { m_frequency = value; } + get { return _frequency; } + set { _frequency = value; } } #endregion @@ -59,8 +59,8 @@ public double Frequency /// The resulting output value. public override double GetValue(double x, double y, double z) { - x *= m_frequency; - z *= m_frequency; + x *= _frequency; + z *= _frequency; var dfc = Math.Sqrt(x * x + z * z); var dfss = dfc - Math.Floor(dfc); var dfls = 1.0 - dfss; diff --git a/Generator/Perlin.cs b/Generator/Perlin.cs index 28a4b5b..0e37d40 100755 --- a/Generator/Perlin.cs +++ b/Generator/Perlin.cs @@ -9,12 +9,12 @@ public class Perlin : ModuleBase { #region Fields - private double m_frequency = 1.0; - private double m_lacunarity = 2.0; - private QualityMode m_quality = QualityMode.Medium; - private int m_octaveCount = 6; - private double m_persistence = 0.5; - private int m_seed; + private double _frequency = 1.0; + private double _lacunarity = 2.0; + private QualityMode _quality = QualityMode.Medium; + private int _octaveCount = 6; + private double _persistence = 0.5; + private int _seed; #endregion @@ -58,8 +58,8 @@ public Perlin(double frequency, double lacunarity, double persistence, int octav /// public double Frequency { - get { return m_frequency; } - set { m_frequency = value; } + get { return _frequency; } + set { _frequency = value; } } /// @@ -67,8 +67,8 @@ public double Frequency /// public double Lacunarity { - get { return m_lacunarity; } - set { m_lacunarity = value; } + get { return _lacunarity; } + set { _lacunarity = value; } } /// @@ -76,8 +76,8 @@ public double Lacunarity /// public QualityMode Quality { - get { return m_quality; } - set { m_quality = value; } + get { return _quality; } + set { _quality = value; } } /// @@ -85,8 +85,8 @@ public QualityMode Quality /// public int OctaveCount { - get { return m_octaveCount; } - set { m_octaveCount = Mathf.Clamp(value, 1, Utils.OctavesMaximum); } + get { return _octaveCount; } + set { _octaveCount = Mathf.Clamp(value, 1, Utils.OctavesMaximum); } } /// @@ -94,8 +94,8 @@ public int OctaveCount /// public double Persistence { - get { return m_persistence; } - set { m_persistence = value; } + get { return _persistence; } + set { _persistence = value; } } /// @@ -103,8 +103,8 @@ public double Persistence /// public int Seed { - get { return m_seed; } - set { m_seed = value; } + get { return _seed; } + set { _seed = value; } } #endregion @@ -121,25 +121,22 @@ public int Seed public override double GetValue(double x, double y, double z) { var value = 0.0; - var signal = 0.0; var cp = 1.0; - double nx, ny, nz; - long seed; - x *= m_frequency; - y *= m_frequency; - z *= m_frequency; - for (var i = 0; i < m_octaveCount; i++) + x *= _frequency; + y *= _frequency; + z *= _frequency; + for (var i = 0; i < _octaveCount; i++) { - nx = Utils.MakeInt32Range(x); - ny = Utils.MakeInt32Range(y); - nz = Utils.MakeInt32Range(z); - seed = (m_seed + i) & 0xffffffff; - signal = Utils.GradientCoherentNoise3D(nx, ny, nz, seed, m_quality); + var nx = Utils.MakeInt32Range(x); + var ny = Utils.MakeInt32Range(y); + var nz = Utils.MakeInt32Range(z); + var seed = (_seed + i) & 0xffffffff; + var signal = Utils.GradientCoherentNoise3D(nx, ny, nz, seed, _quality); value += signal * cp; - x *= m_lacunarity; - y *= m_lacunarity; - z *= m_lacunarity; - cp *= m_persistence; + x *= _lacunarity; + y *= _lacunarity; + z *= _lacunarity; + cp *= _persistence; } return value; } diff --git a/Generator/RidgedMultifractal.cs b/Generator/RidgedMultifractal.cs index 6d618a9..83a173d 100755 --- a/Generator/RidgedMultifractal.cs +++ b/Generator/RidgedMultifractal.cs @@ -10,12 +10,12 @@ public class RidgedMultifractal : ModuleBase { #region Fields - private double m_frequency = 1.0; - private double m_lacunarity = 2.0; - private QualityMode m_quality = QualityMode.Medium; - private int m_octaveCount = 6; - private int m_seed; - private readonly double[] m_weights = new double[Utils.OctavesMaximum]; + private double _frequency = 1.0; + private double _lacunarity = 2.0; + private QualityMode _quality = QualityMode.Medium; + private int _octaveCount = 6; + private int _seed; + private readonly double[] _weights = new double[Utils.OctavesMaximum]; #endregion @@ -57,8 +57,8 @@ public RidgedMultifractal(double frequency, double lacunarity, int octaves, int /// public double Frequency { - get { return m_frequency; } - set { m_frequency = value; } + get { return _frequency; } + set { _frequency = value; } } /// @@ -66,10 +66,10 @@ public double Frequency /// public double Lacunarity { - get { return m_lacunarity; } + get { return _lacunarity; } set { - m_lacunarity = value; + _lacunarity = value; UpdateWeights(); } } @@ -79,8 +79,8 @@ public double Lacunarity /// public QualityMode Quality { - get { return m_quality; } - set { m_quality = value; } + get { return _quality; } + set { _quality = value; } } /// @@ -88,8 +88,8 @@ public QualityMode Quality /// public int OctaveCount { - get { return m_octaveCount; } - set { m_octaveCount = Mathf.Clamp(value, 1, Utils.OctavesMaximum); } + get { return _octaveCount; } + set { _octaveCount = Mathf.Clamp(value, 1, Utils.OctavesMaximum); } } /// @@ -97,8 +97,8 @@ public int OctaveCount /// public int Seed { - get { return m_seed; } - set { m_seed = value; } + get { return _seed; } + set { _seed = value; } } #endregion @@ -113,8 +113,8 @@ private void UpdateWeights() var f = 1.0; for (var i = 0; i < Utils.OctavesMaximum; i++) { - m_weights[i] = Math.Pow(f, -1.0); - f *= m_lacunarity; + _weights[i] = Math.Pow(f, -1.0); + f *= _lacunarity; } } @@ -131,31 +131,30 @@ private void UpdateWeights() /// The resulting output value. public override double GetValue(double x, double y, double z) { - x *= m_frequency; - y *= m_frequency; - z *= m_frequency; - var signal = 0.0; + x *= _frequency; + y *= _frequency; + z *= _frequency; var value = 0.0; var weight = 1.0; - var offset = 1.0; - var gain = 2.0; - for (var i = 0; i < m_octaveCount; i++) + var offset = 1.0; // TODO: Review why Offset is never assigned + var gain = 2.0; // TODO: Review why gain is never assigned + for (var i = 0; i < _octaveCount; i++) { var nx = Utils.MakeInt32Range(x); var ny = Utils.MakeInt32Range(y); var nz = Utils.MakeInt32Range(z); - long seed = (m_seed + i) & 0x7fffffff; - signal = Utils.GradientCoherentNoise3D(nx, ny, nz, seed, m_quality); + long seed = (_seed + i) & 0x7fffffff; + var signal = Utils.GradientCoherentNoise3D(nx, ny, nz, seed, _quality); signal = Math.Abs(signal); signal = offset - signal; signal *= signal; signal *= weight; weight = signal * gain; weight = Mathf.Clamp01((float) weight); - value += (signal * m_weights[i]); - x *= m_lacunarity; - y *= m_lacunarity; - z *= m_lacunarity; + value += (signal * _weights[i]); + x *= _lacunarity; + y *= _lacunarity; + z *= _lacunarity; } return (value * 1.25) - 1.0; } diff --git a/Generator/Spheres.cs b/Generator/Spheres.cs index 28de68f..f74af04 100755 --- a/Generator/Spheres.cs +++ b/Generator/Spheres.cs @@ -9,7 +9,7 @@ public class Spheres : ModuleBase { #region Fields - private double m_frequency = 1.0; + private double _frequency = 1.0; #endregion @@ -42,8 +42,8 @@ public Spheres(double frequency) /// public double Frequency { - get { return m_frequency; } - set { m_frequency = value; } + get { return _frequency; } + set { _frequency = value; } } #endregion @@ -59,9 +59,9 @@ public double Frequency /// The resulting output value. public override double GetValue(double x, double y, double z) { - x *= m_frequency; - y *= m_frequency; - z *= m_frequency; + x *= _frequency; + y *= _frequency; + z *= _frequency; var dfc = Math.Sqrt(x * x + y * y + z * z); var dfss = dfc - Math.Floor(dfc); var dfls = 1.0 - dfss; diff --git a/Generator/Voronoi.cs b/Generator/Voronoi.cs index 5e9de07..bcd887e 100755 --- a/Generator/Voronoi.cs +++ b/Generator/Voronoi.cs @@ -9,10 +9,10 @@ public class Voronoi : ModuleBase { #region Fields - private double m_displacement = 1.0; - private double m_frequency = 1.0; - private int m_seed; - private bool m_distance; + private double _displacement = 1.0; + private double _frequency = 1.0; + private int _seed; + private bool _distance; #endregion @@ -31,7 +31,6 @@ public Voronoi() /// /// The frequency of the first octave. /// The displacement of the ridged-multifractal noise. - /// The persistence of the ridged-multifractal noise. /// The seed of the ridged-multifractal noise. /// Indicates whether the distance from the nearest seed point is applied to the output value. public Voronoi(double frequency, double displacement, int seed, bool distance) @@ -53,8 +52,8 @@ public Voronoi(double frequency, double displacement, int seed, bool distance) /// public double Displacement { - get { return m_displacement; } - set { m_displacement = value; } + get { return _displacement; } + set { _displacement = value; } } /// @@ -62,8 +61,8 @@ public double Displacement /// public double Frequency { - get { return m_frequency; } - set { m_frequency = value; } + get { return _frequency; } + set { _frequency = value; } } /// @@ -71,8 +70,8 @@ public double Frequency /// public int Seed { - get { return m_seed; } - set { m_seed = value; } + get { return _seed; } + set { _seed = value; } } /// @@ -80,8 +79,8 @@ public int Seed /// public bool UseDistance { - get { return m_distance; } - set { m_distance = value; } + get { return _distance; } + set { _distance = value; } } #endregion @@ -97,9 +96,9 @@ public bool UseDistance /// The resulting output value. public override double GetValue(double x, double y, double z) { - x *= m_frequency; - y *= m_frequency; - z *= m_frequency; + x *= _frequency; + y *= _frequency; + z *= _frequency; var xi = (x > 0.0 ? (int) x : (int) x - 1); var iy = (y > 0.0 ? (int) y : (int) y - 1); var iz = (z > 0.0 ? (int) z : (int) z - 1); @@ -113,9 +112,9 @@ public override double GetValue(double x, double y, double z) { for (var xcu = xi - 2; xcu <= xi + 2; xcu++) { - var xp = xcu + Utils.ValueNoise3D(xcu, ycu, zcu, m_seed); - var yp = ycu + Utils.ValueNoise3D(xcu, ycu, zcu, m_seed + 1); - var zp = zcu + Utils.ValueNoise3D(xcu, ycu, zcu, m_seed + 2); + var xp = xcu + Utils.ValueNoise3D(xcu, ycu, zcu, _seed); + var yp = ycu + Utils.ValueNoise3D(xcu, ycu, zcu, _seed + 1); + var zp = zcu + Utils.ValueNoise3D(xcu, ycu, zcu, _seed + 2); var xd = xp - x; var yd = yp - y; var zd = zp - z; @@ -131,7 +130,7 @@ public override double GetValue(double x, double y, double z) } } double v; - if (m_distance) + if (_distance) { var xd = xc - x; var yd = yc - y; @@ -142,7 +141,7 @@ public override double GetValue(double x, double y, double z) { v = 0.0; } - return v + (m_displacement * Utils.ValueNoise3D((int) (Math.Floor(xc)), (int) (Math.Floor(yc)), + return v + (_displacement * Utils.ValueNoise3D((int) (Math.Floor(xc)), (int) (Math.Floor(yc)), (int) (Math.Floor(zc)), 0)); } diff --git a/GradientPresets.cs b/GradientPresets.cs index d713d5a..9f0e6c5 100755 --- a/GradientPresets.cs +++ b/GradientPresets.cs @@ -26,43 +26,47 @@ public static class GradientPresets static GradientPresets() { // Grayscale gradient color keys - var grayscaleColorKeys = new List(); - grayscaleColorKeys.Add(new GradientColorKey(Color.black, 0)); - grayscaleColorKeys.Add(new GradientColorKey(Color.white, 1)); + var grayscaleColorKeys = new List + { + new GradientColorKey(Color.black, 0), + new GradientColorKey(Color.white, 1) + }; // RGB gradient color keys - var rgbColorKeys = new List(); - rgbColorKeys.Add(new GradientColorKey(Color.red, 0)); - rgbColorKeys.Add(new GradientColorKey(Color.green, 0.5f)); - rgbColorKeys.Add(new GradientColorKey(Color.blue, 1)); + var rgbColorKeys = new List + { + new GradientColorKey(Color.red, 0), + new GradientColorKey(Color.green, 0.5f), + new GradientColorKey(Color.blue, 1) + }; // RGBA gradient color keys - var rgbaColorKeys = new List(); - rgbaColorKeys.Add(new GradientColorKey(Color.red, 0)); - rgbaColorKeys.Add(new GradientColorKey(Color.green, 1 / 3f)); - rgbaColorKeys.Add(new GradientColorKey(Color.blue, 2 / 3f)); - rgbaColorKeys.Add(new GradientColorKey(Color.black, 1)); + var rgbaColorKeys = new List + { + new GradientColorKey(Color.red, 0), + new GradientColorKey(Color.green, 1 / 3f), + new GradientColorKey(Color.blue, 2 / 3f), + new GradientColorKey(Color.black, 1) + }; // RGBA gradient alpha keys - var rgbaAlphaKeys = new List(); - rgbaAlphaKeys.Add(new GradientAlphaKey(0, 2 / 3f)); - rgbaAlphaKeys.Add(new GradientAlphaKey(1, 1)); + var rgbaAlphaKeys = new List {new GradientAlphaKey(0, 2 / 3f), new GradientAlphaKey(1, 1)}; // Terrain gradient color keys - var terrainColorKeys = new List(); - terrainColorKeys.Add(new GradientColorKey(new Color(0, 0, 0.5f), 0)); - terrainColorKeys.Add(new GradientColorKey(new Color(0.125f, 0.25f, 0.5f), 0.4f)); - terrainColorKeys.Add(new GradientColorKey(new Color(0.25f, 0.375f, 0.75f), 0.48f)); - terrainColorKeys.Add(new GradientColorKey(new Color(0, 0.75f, 0), 0.5f)); - terrainColorKeys.Add(new GradientColorKey(new Color(0.75f, 0.75f, 0), 0.625f)); - terrainColorKeys.Add(new GradientColorKey(new Color(0.625f, 0.375f, 0.25f), 0.75f)); - terrainColorKeys.Add(new GradientColorKey(new Color(0.5f, 1, 1), 0.875f)); - terrainColorKeys.Add(new GradientColorKey(Color.white, 1)); + var terrainColorKeys = new List + { + new GradientColorKey(new Color(0, 0, 0.5f), 0), + new GradientColorKey(new Color(0.125f, 0.25f, 0.5f), 0.4f), + new GradientColorKey(new Color(0.25f, 0.375f, 0.75f), 0.48f), + new GradientColorKey(new Color(0, 0.75f, 0), 0.5f), + new GradientColorKey(new Color(0.75f, 0.75f, 0), 0.625f), + new GradientColorKey(new Color(0.625f, 0.375f, 0.25f), 0.75f), + new GradientColorKey(new Color(0.5f, 1, 1), 0.875f), + new GradientColorKey(Color.white, 1) + }; // Generic gradient alpha keys - var alphaKeys = new List(); - alphaKeys.Add(new GradientAlphaKey(1, 0)); - alphaKeys.Add(new GradientAlphaKey(1, 1)); + var alphaKeys = new List {new GradientAlphaKey(1, 0), new GradientAlphaKey(1, 1)}; _empty = new Gradient(); diff --git a/ModuleBase.cs b/ModuleBase.cs index 749241d..8b7ac20 100755 --- a/ModuleBase.cs +++ b/ModuleBase.cs @@ -27,7 +27,7 @@ public abstract class ModuleBase : IDisposable { #region Fields - protected ModuleBase[] m_modules = null; + private ModuleBase[] _modules; #endregion @@ -41,7 +41,7 @@ protected ModuleBase(int count) { if (count > 0) { - m_modules = new ModuleBase[count]; + _modules = new ModuleBase[count]; } } @@ -58,22 +58,22 @@ public virtual ModuleBase this[int index] { get { - Debug.Assert(m_modules != null); - Debug.Assert(m_modules.Length > 0); - if (index < 0 || index >= m_modules.Length) + Debug.Assert(_modules != null); + Debug.Assert(_modules.Length > 0); + if (index < 0 || index >= _modules.Length) { throw new ArgumentOutOfRangeException("Index out of valid module range"); } - if (m_modules[index] == null) + if (_modules[index] == null) { throw new ArgumentNullException("Desired element is null"); } - return m_modules[index]; + return _modules[index]; } set { - Debug.Assert(m_modules.Length > 0); - if (index < 0 || index >= m_modules.Length) + Debug.Assert(_modules.Length > 0); + if (index < 0 || index >= _modules.Length) { throw new ArgumentOutOfRangeException("Index out of valid module range"); } @@ -81,20 +81,24 @@ public virtual ModuleBase this[int index] { throw new ArgumentNullException("Value should not be null"); } - m_modules[index] = value; + _modules[index] = value; } } #endregion #region Properties + protected ModuleBase[] Modules + { + get { return _modules; } + } /// /// Gets the number of source modules required by this noise module. /// public int SourceModuleCount { - get { return (m_modules == null) ? 0 : m_modules.Length; } + get { return (_modules == null) ? 0 : _modules.Length; } } #endregion @@ -138,14 +142,14 @@ public double GetValue(ref Vector3 coordinate) #if !XBOX360 && !ZUNE [NonSerialized] #endif - private bool m_disposed; + private bool _disposed; /// /// Gets a value whether the object is disposed. /// public bool IsDisposed { - get { return m_disposed; } + get { return _disposed; } } /// @@ -153,9 +157,9 @@ public bool IsDisposed /// public void Dispose() { - if (!m_disposed) + if (!_disposed) { - m_disposed = Disposing(); + _disposed = Disposing(); } GC.SuppressFinalize(this); } @@ -166,14 +170,14 @@ public void Dispose() /// True if the object is completely disposed. protected virtual bool Disposing() { - if (m_modules != null) + if (_modules != null) { - for (var i = 0; i < m_modules.Length; i++) + for (var i = 0; i < _modules.Length; i++) { - m_modules[i].Dispose(); - m_modules[i] = null; + _modules[i].Dispose(); + _modules[i] = null; } - m_modules = null; + _modules = null; } return true; } diff --git a/Noise2D.cs b/Noise2D.cs index 4faf66f..3efeaee 100755 --- a/Noise2D.cs +++ b/Noise2D.cs @@ -26,18 +26,18 @@ public class Noise2D : IDisposable #region Fields - private int m_width; - private int m_height; - private float[,] m_data; - private readonly int m_ucWidth; - private readonly int m_ucHeight; - private int m_ucBorder = 1; // Border size of extra noise for uncropped data. - - private readonly float[,] m_ucData; + private int _width; + private int _height; + private float[,] _data; + private readonly int _ucWidth; + private readonly int _ucHeight; + private int _ucBorder = 1; // Border size of extra noise for uncropped data. + + private readonly float[,] _ucData; // Uncropped data. This has a border of extra noise data used for calculating normal map edges. - private float m_borderValue = float.NaN; - private ModuleBase m_generator; + private float _borderValue = float.NaN; + private ModuleBase _generator; #endregion @@ -69,31 +69,21 @@ public Noise2D(int size, ModuleBase generator) { } - /// - /// Initializes a new instance of Noise2D. - /// - /// The width of the noise map. - /// The height of the noise map. - public Noise2D(int width, int height) - : this(width, height, null) - { - } - /// /// Initializes a new instance of Noise2D. /// /// The width of the noise map. /// The height of the noise map. /// The generator module. - public Noise2D(int width, int height, ModuleBase generator) + public Noise2D(int width, int height, ModuleBase generator = null) { - m_generator = generator; - m_width = width; - m_height = height; - m_data = new float[width, height]; - m_ucWidth = width + m_ucBorder * 2; - m_ucHeight = height + m_ucBorder * 2; - m_ucData = new float[width + m_ucBorder * 2, height + m_ucBorder * 2]; + _generator = generator; + _width = width; + _height = height; + _data = new float[width, height]; + _ucWidth = width + _ucBorder * 2; + _ucHeight = height + _ucBorder * 2; + _ucData = new float[width + _ucBorder * 2, height + _ucBorder * 2]; } #endregion @@ -113,51 +103,51 @@ public Noise2D(int width, int height, ModuleBase generator) { if (isCropped) { - if (x < 0 && x >= m_width) + if (x < 0 && x >= _width) { throw new ArgumentOutOfRangeException("Invalid x position"); } - if (y < 0 && y >= m_height) + if (y < 0 && y >= _height) { throw new ArgumentOutOfRangeException("Invalid y position"); } - return m_data[x, y]; + return _data[x, y]; } - if (x < 0 && x >= m_ucWidth) + if (x < 0 && x >= _ucWidth) { throw new ArgumentOutOfRangeException("Invalid x position"); } - if (y < 0 && y >= m_ucHeight) + if (y < 0 && y >= _ucHeight) { throw new ArgumentOutOfRangeException("Invalid y position"); } - return m_ucData[x, y]; + return _ucData[x, y]; } set { if (isCropped) { - if (x < 0 && x >= m_width) + if (x < 0 && x >= _width) { throw new ArgumentOutOfRangeException("Invalid x position"); } - if (y < 0 && y >= m_height) + if (y < 0 && y >= _height) { throw new ArgumentOutOfRangeException("Invalid y position"); } - m_data[x, y] = value; + _data[x, y] = value; } else { - if (x < 0 && x >= m_ucWidth) + if (x < 0 && x >= _ucWidth) { throw new ArgumentOutOfRangeException("Invalid x position"); } - if (y < 0 && y >= m_ucHeight) + if (y < 0 && y >= _ucHeight) { throw new ArgumentOutOfRangeException("Invalid y position"); } - m_ucData[x, y] = value; + _ucData[x, y] = value; } } } @@ -171,8 +161,8 @@ public Noise2D(int width, int height, ModuleBase generator) /// public float Border { - get { return m_borderValue; } - set { m_borderValue = value; } + get { return _borderValue; } + set { _borderValue = value; } } /// @@ -180,8 +170,8 @@ public float Border /// public ModuleBase Generator { - get { return m_generator; } - set { m_generator = value; } + get { return _generator; } + set { _generator = value; } } /// @@ -189,7 +179,7 @@ public ModuleBase Generator /// public int Height { - get { return m_height; } + get { return _height; } } /// @@ -197,7 +187,7 @@ public int Height /// public int Width { - get { return m_width; } + get { return _width; } } #endregion @@ -230,15 +220,15 @@ public int Width float[,] data; if (isCropped) { - width = m_width; - height = m_height; - data = m_data; + width = _width; + height = _height; + data = _data; } else { - width = m_ucWidth; - height = m_ucHeight; - data = m_ucData; + width = _ucWidth; + height = _ucHeight; + data = _ucData; } width -= xCrop; height -= yCrop; @@ -268,11 +258,11 @@ public int Width /// The constant value to clear the noise map with. public void Clear(float value = 0f) { - for (var x = 0; x < m_width; x++) + for (var x = 0; x < _width; x++) { - for (var y = 0; y < m_height; y++) + for (var y = 0; y < _height; y++) { - m_data[x, y] = value; + _data[x, y] = value; } } } @@ -285,7 +275,7 @@ public void Clear(float value = 0f) /// The corresponding noise map value. private double GeneratePlanar(double x, double y) { - return m_generator.GetValue(x, 0.0, y); + return _generator.GetValue(x, 0.0, y); } /// @@ -302,22 +292,21 @@ public void GeneratePlanar(double left, double right, double top, double bottom, { throw new ArgumentException("Invalid right/left or bottom/top combination"); } - if (m_generator == null) + if (_generator == null) { throw new ArgumentNullException("Generator is null"); } var xe = right - left; var ze = bottom - top; - var xd = xe / ((double) m_width - m_ucBorder); - var zd = ze / ((double) m_height - m_ucBorder); + var xd = xe / ((double) _width - _ucBorder); + var zd = ze / ((double) _height - _ucBorder); var xc = left; - var zc = top; - var fv = 0.0f; - for (var x = 0; x < m_ucWidth; x++) + for (var x = 0; x < _ucWidth; x++) { - zc = top; - for (var y = 0; y < m_ucHeight; y++) + var zc = top; + for (var y = 0; y < _ucHeight; y++) { + float fv; if (isSeamless) { fv = (float) GeneratePlanar(xc, zc); @@ -334,11 +323,11 @@ public void GeneratePlanar(double left, double right, double top, double bottom, var z1 = Utils.InterpolateLinear(nwv, nev, xb); fv = (float) Utils.InterpolateLinear(z0, z1, zb); } - m_ucData[x, y] = fv; - if (x >= m_ucBorder && y >= m_ucBorder && x < m_width + m_ucBorder && - y < m_height + m_ucBorder) + _ucData[x, y] = fv; + if (x >= _ucBorder && y >= _ucBorder && x < _width + _ucBorder && + y < _height + _ucBorder) { - m_data[x - m_ucBorder, y - m_ucBorder] = fv; // Cropped data + _data[x - _ucBorder, y - _ucBorder] = fv; // Cropped data } zc += zd; } @@ -357,7 +346,7 @@ private double GenerateCylindrical(double angle, double height) var x = Math.Cos(angle * Mathf.Deg2Rad); var y = height; var z = Math.Sin(angle * Mathf.Deg2Rad); - return m_generator.GetValue(x, y, z); + return _generator.GetValue(x, y, z); } /// @@ -373,26 +362,25 @@ public void GenerateCylindrical(double angleMin, double angleMax, double heightM { throw new ArgumentException("Invalid angle or height parameters"); } - if (m_generator == null) + if (_generator == null) { throw new ArgumentNullException("Generator is null"); } var ae = angleMax - angleMin; var he = heightMax - heightMin; - var xd = ae / ((double) m_width - m_ucBorder); - var yd = he / ((double) m_height - m_ucBorder); + var xd = ae / ((double) _width - _ucBorder); + var yd = he / ((double) _height - _ucBorder); var ca = angleMin; - var ch = heightMin; - for (var x = 0; x < m_ucWidth; x++) + for (var x = 0; x < _ucWidth; x++) { - ch = heightMin; - for (var y = 0; y < m_ucHeight; y++) + var ch = heightMin; + for (var y = 0; y < _ucHeight; y++) { - m_ucData[x, y] = (float) GenerateCylindrical(ca, ch); - if (x >= m_ucBorder && y >= m_ucBorder && x < m_width + m_ucBorder && - y < m_height + m_ucBorder) + _ucData[x, y] = (float) GenerateCylindrical(ca, ch); + if (x >= _ucBorder && y >= _ucBorder && x < _width + _ucBorder && + y < _height + _ucBorder) { - m_data[x - m_ucBorder, y - m_ucBorder] = (float) GenerateCylindrical(ca, ch); + _data[x - _ucBorder, y - _ucBorder] = (float) GenerateCylindrical(ca, ch); // Cropped data } ch += yd; @@ -410,7 +398,7 @@ public void GenerateCylindrical(double angleMin, double angleMax, double heightM private double GenerateSpherical(double lat, double lon) { var r = Math.Cos(Mathf.Deg2Rad * lat); - return m_generator.GetValue(r * Math.Cos(Mathf.Deg2Rad * lon), Math.Sin(Mathf.Deg2Rad * lat), + return _generator.GetValue(r * Math.Cos(Mathf.Deg2Rad * lon), Math.Sin(Mathf.Deg2Rad * lat), r * Math.Sin(Mathf.Deg2Rad * lon)); } @@ -427,26 +415,25 @@ public void GenerateSpherical(double south, double north, double west, double ea { throw new ArgumentException("Invalid east/west or north/south combination"); } - if (m_generator == null) + if (_generator == null) { throw new ArgumentNullException("Generator is null"); } var loe = east - west; var lae = north - south; - var xd = loe / ((double) m_width - m_ucBorder); - var yd = lae / ((double) m_height - m_ucBorder); + var xd = loe / ((double) _width - _ucBorder); + var yd = lae / ((double) _height - _ucBorder); var clo = west; - var cla = south; - for (var x = 0; x < m_ucWidth; x++) + for (var x = 0; x < _ucWidth; x++) { - cla = south; - for (var y = 0; y < m_ucHeight; y++) + var cla = south; + for (var y = 0; y < _ucHeight; y++) { - m_ucData[x, y] = (float) GenerateSpherical(cla, clo); - if (x >= m_ucBorder && y >= m_ucBorder && x < m_width + m_ucBorder && - y < m_height + m_ucBorder) + _ucData[x, y] = (float) GenerateSpherical(cla, clo); + if (x >= _ucBorder && y >= _ucBorder && x < _width + _ucBorder && + y < _height + _ucBorder) { - m_data[x - m_ucBorder, y - m_ucBorder] = (float) GenerateSpherical(cla, clo); + _data[x - _ucBorder, y - _ucBorder] = (float) GenerateSpherical(cla, clo); // Cropped data } cla += yd; @@ -471,23 +458,23 @@ public Texture2D GetTexture() /// The created texture map. public Texture2D GetTexture(Gradient gradient) { - var texture = new Texture2D(m_width, m_height); - var pixels = new Color[m_width * m_height]; - for (var x = 0; x < m_width; x++) + var texture = new Texture2D(_width, _height); + var pixels = new Color[_width * _height]; + for (var x = 0; x < _width; x++) { - for (var y = 0; y < m_height; y++) + for (var y = 0; y < _height; y++) { - var sample = 0.0f; - if (!float.IsNaN(m_borderValue) && - (x == 0 || x == m_width - m_ucBorder || y == 0 || y == m_height - m_ucBorder)) + float sample; + if (!float.IsNaN(_borderValue) && + (x == 0 || x == _width - _ucBorder || y == 0 || y == _height - _ucBorder)) { - sample = m_borderValue; + sample = _borderValue; } else { - sample = m_data[x, y]; + sample = _data[x, y]; } - pixels[x + y * m_width] = gradient.Evaluate((sample + 1) / 2); + pixels[x + y * _width] = gradient.Evaluate((sample + 1) / 2); } } texture.SetPixels(pixels); @@ -503,16 +490,16 @@ public Texture2D GetTexture(Gradient gradient) /// The created normal map. public Texture2D GetNormalMap(float intensity) { - var texture = new Texture2D(m_width, m_height); - var pixels = new Color[m_width * m_height]; - for (var x = 0; x < m_ucWidth; x++) + var texture = new Texture2D(_width, _height); + var pixels = new Color[_width * _height]; + for (var x = 0; x < _ucWidth; x++) { - for (var y = 0; y < m_ucHeight; y++) + for (var y = 0; y < _ucHeight; y++) { - var xPos = (m_ucData[Mathf.Max(0, x - m_ucBorder), y] - - m_ucData[Mathf.Min(x + m_ucBorder, m_height + m_ucBorder), y]) / 2; - var yPos = (m_ucData[x, Mathf.Max(0, y - m_ucBorder)] - - m_ucData[x, Mathf.Min(y + m_ucBorder, m_width + m_ucBorder)]) / 2; + var xPos = (_ucData[Mathf.Max(0, x - _ucBorder), y] - + _ucData[Mathf.Min(x + _ucBorder, _height + _ucBorder), y]) / 2; + var yPos = (_ucData[x, Mathf.Max(0, y - _ucBorder)] - + _ucData[x, Mathf.Min(y + _ucBorder, _width + _ucBorder)]) / 2; var normalX = new Vector3(xPos * intensity, 0, 1); var normalY = new Vector3(0, yPos * intensity, 1); // Get normal vector @@ -523,11 +510,11 @@ public Texture2D GetNormalMap(float intensity) colorVector.x = (normalVector.x + 1) / 2; colorVector.y = (normalVector.y + 1) / 2; colorVector.z = (normalVector.z + 1) / 2; - // Start at (x + m_ucBorder, y + m_ucBorder) so that resulting normal map aligns with cropped data - if (x >= m_ucBorder && y >= m_ucBorder && x < m_width + m_ucBorder && - y < m_height + m_ucBorder) + // Start at (x + _ucBorder, y + _ucBorder) so that resulting normal map aligns with cropped data + if (x >= _ucBorder && y >= _ucBorder && x < _width + _ucBorder && + y < _height + _ucBorder) { - pixels[(x - m_ucBorder) + (y - m_ucBorder) * m_width] = new Color(colorVector.x, + pixels[(x - _ucBorder) + (y - _ucBorder) * _width] = new Color(colorVector.x, colorVector.y, colorVector.z); } } @@ -546,14 +533,14 @@ public Texture2D GetNormalMap(float intensity) #if !XBOX360 && !ZUNE [NonSerialized] #endif - private bool m_disposed; + private bool _disposed; /// /// Gets a value whether the object is disposed. /// public bool IsDisposed { - get { return m_disposed; } + get { return _disposed; } } /// @@ -561,9 +548,9 @@ public bool IsDisposed /// public void Dispose() { - if (!m_disposed) + if (!_disposed) { - m_disposed = Disposing(); + _disposed = Disposing(); } GC.SuppressFinalize(this); } @@ -574,12 +561,9 @@ public void Dispose() /// True if the object is completely disposed. protected virtual bool Disposing() { - if (m_data != null) - { - m_data = null; - } - m_width = 0; - m_height = 0; + _data = null; + _width = 0; + _height = 0; return true; } diff --git a/Operator/Abs.cs b/Operator/Abs.cs index b75ec48..f6ca945 100755 --- a/Operator/Abs.cs +++ b/Operator/Abs.cs @@ -26,7 +26,7 @@ public Abs() public Abs(ModuleBase input) : base(1) { - m_modules[0] = input; + Modules[0] = input; } #endregion @@ -42,8 +42,8 @@ public Abs(ModuleBase input) /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); - return Math.Abs(m_modules[0].GetValue(x, y, z)); + Debug.Assert(Modules[0] != null); + return Math.Abs(Modules[0].GetValue(x, y, z)); } #endregion diff --git a/Operator/Add.cs b/Operator/Add.cs index 64b15c9..8a3709b 100755 --- a/Operator/Add.cs +++ b/Operator/Add.cs @@ -26,8 +26,8 @@ public Add() public Add(ModuleBase lhs, ModuleBase rhs) : base(2) { - m_modules[0] = lhs; - m_modules[1] = rhs; + Modules[0] = lhs; + Modules[1] = rhs; } #endregion @@ -43,9 +43,9 @@ public Add(ModuleBase lhs, ModuleBase rhs) /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); - Debug.Assert(m_modules[1] != null); - return m_modules[0].GetValue(x, y, z) + m_modules[1].GetValue(x, y, z); + Debug.Assert(Modules[0] != null); + Debug.Assert(Modules[1] != null); + return Modules[0].GetValue(x, y, z) + Modules[1].GetValue(x, y, z); } #endregion diff --git a/Operator/Blend.cs b/Operator/Blend.cs index aabeb3c..4d60c25 100755 --- a/Operator/Blend.cs +++ b/Operator/Blend.cs @@ -27,9 +27,9 @@ public Blend() public Blend(ModuleBase lhs, ModuleBase rhs, ModuleBase controller) : base(3) { - m_modules[0] = lhs; - m_modules[1] = rhs; - m_modules[2] = controller; + Modules[0] = lhs; + Modules[1] = rhs; + Modules[2] = controller; } #endregion @@ -41,11 +41,11 @@ public Blend(ModuleBase lhs, ModuleBase rhs, ModuleBase controller) /// public ModuleBase Controller { - get { return m_modules[2]; } + get { return Modules[2]; } set { Debug.Assert(value != null); - m_modules[2] = value; + Modules[2] = value; } } @@ -62,12 +62,12 @@ public ModuleBase Controller /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); - Debug.Assert(m_modules[1] != null); - Debug.Assert(m_modules[2] != null); - var a = m_modules[0].GetValue(x, y, z); - var b = m_modules[1].GetValue(x, y, z); - var c = (m_modules[2].GetValue(x, y, z) + 1.0) / 2.0; + 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); } diff --git a/Operator/Cache.cs b/Operator/Cache.cs index a4f2d32..cf8a3f7 100755 --- a/Operator/Cache.cs +++ b/Operator/Cache.cs @@ -10,11 +10,11 @@ public class Cache : ModuleBase { #region Fields - private double m_value; - private bool m_cached; - private double m_x; - private double m_y; - private double m_z; + private double _value; + private bool _cached; + private double _x; + private double _y; + private double _z; #endregion @@ -31,11 +31,11 @@ public Cache() /// /// Initializes a new instance of Cache. /// - /// The input module. + /// The input module. public Cache(ModuleBase input) : base(1) { - m_modules[0] = input; + Modules[0] = input; } #endregion @@ -53,7 +53,7 @@ public override ModuleBase this[int index] set { base[index] = value; - m_cached = false; + _cached = false; } } @@ -66,16 +66,16 @@ public override ModuleBase this[int index] /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); - if (!(m_cached && m_x == x && m_y == y && m_z == z)) + Debug.Assert(Modules[0] != null); + if (!(_cached && _x == x && _y == y && _z == z)) { - m_value = m_modules[0].GetValue(x, y, z); - m_x = x; - m_y = y; - m_z = z; + _value = Modules[0].GetValue(x, y, z); + _x = x; + _y = y; + _z = z; } - m_cached = true; - return m_value; + _cached = true; + return _value; } #endregion diff --git a/Operator/Clamp.cs b/Operator/Clamp.cs index af4eb01..283d613 100755 --- a/Operator/Clamp.cs +++ b/Operator/Clamp.cs @@ -10,8 +10,8 @@ public class Clamp : ModuleBase { #region Fields - private double m_min = -1.0; - private double m_max = 1.0; + private double _min = -1.0; + private double _max = 1.0; #endregion @@ -32,7 +32,7 @@ public Clamp() public Clamp(ModuleBase input) : base(1) { - m_modules[0] = input; + Modules[0] = input; } /// @@ -46,7 +46,7 @@ public Clamp(double min, double max, ModuleBase input) { Minimum = min; Maximum = max; - m_modules[0] = input; + Modules[0] = input; } #endregion @@ -58,8 +58,8 @@ public Clamp(double min, double max, ModuleBase input) /// public double Maximum { - get { return m_max; } - set { m_max = value; } + get { return _max; } + set { _max = value; } } /// @@ -67,8 +67,8 @@ public double Maximum /// public double Minimum { - get { return m_min; } - set { m_min = value; } + get { return _min; } + set { _min = value; } } #endregion @@ -83,8 +83,8 @@ public double Minimum public void SetBounds(double min, double max) { Debug.Assert(min < max); - m_min = min; - m_max = max; + _min = min; + _max = max; } #endregion @@ -100,21 +100,21 @@ public void SetBounds(double min, double max) /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); - if (m_min > m_max) + Debug.Assert(Modules[0] != null); + if (_min > _max) { - var t = m_min; - m_min = m_max; - m_max = t; + var t = _min; + _min = _max; + _max = t; } - var v = m_modules[0].GetValue(x, y, z); - if (v < m_min) + var v = Modules[0].GetValue(x, y, z); + if (v < _min) { - return m_min; + return _min; } - if (v > m_max) + if (v > _max) { - return m_max; + return _max; } return v; } diff --git a/Operator/Curve.cs b/Operator/Curve.cs index 22c92c9..0aa9b8b 100755 --- a/Operator/Curve.cs +++ b/Operator/Curve.cs @@ -12,7 +12,7 @@ public class Curve : ModuleBase { #region Fields - private readonly List> m_data = new List>(); + private readonly List> _data = new List>(); #endregion @@ -33,7 +33,7 @@ public Curve() public Curve(ModuleBase input) : base(1) { - m_modules[0] = input; + Modules[0] = input; } #endregion @@ -45,7 +45,7 @@ public Curve(ModuleBase input) /// public int ControlPointCount { - get { return m_data.Count; } + get { return _data.Count; } } /// @@ -53,7 +53,7 @@ public int ControlPointCount /// public List> ControlPoints { - get { return m_data; } + get { return _data; } } #endregion @@ -68,11 +68,11 @@ public List> ControlPoints public void Add(double input, double output) { var kvp = new KeyValuePair(input, output); - if (!m_data.Contains(kvp)) + if (!_data.Contains(kvp)) { - m_data.Add(kvp); + _data.Add(kvp); } - m_data.Sort( + _data.Sort( delegate(KeyValuePair lhs, KeyValuePair rhs) { return lhs.Key.CompareTo(rhs.Key); @@ -84,7 +84,7 @@ public void Add(double input, double output) /// public void Clear() { - m_data.Clear(); + _data.Clear(); } #endregion @@ -100,32 +100,32 @@ public void Clear() /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); + Debug.Assert(Modules[0] != null); Debug.Assert(ControlPointCount >= 4); - var smv = m_modules[0].GetValue(x, y, z); + var smv = Modules[0].GetValue(x, y, z); int ip; - for (ip = 0; ip < m_data.Count; ip++) + for (ip = 0; ip < _data.Count; ip++) { - if (smv < m_data[ip].Key) + if (smv < _data[ip].Key) { break; } } - var i0 = Mathf.Clamp(ip - 2, 0, m_data.Count - 1); - var i1 = Mathf.Clamp(ip - 1, 0, m_data.Count - 1); - var i2 = Mathf.Clamp(ip, 0, m_data.Count - 1); - var i3 = Mathf.Clamp(ip + 1, 0, m_data.Count - 1); + var i0 = Mathf.Clamp(ip - 2, 0, _data.Count - 1); + var i1 = Mathf.Clamp(ip - 1, 0, _data.Count - 1); + var i2 = Mathf.Clamp(ip, 0, _data.Count - 1); + var i3 = Mathf.Clamp(ip + 1, 0, _data.Count - 1); if (i1 == i2) { - return m_data[i1].Value; + return _data[i1].Value; } - //double ip0 = m_data[i1].Value; - //double ip1 = m_data[i2].Value; - var ip0 = m_data[i1].Key; - var ip1 = m_data[i2].Key; + //double ip0 = _data[i1].Value; + //double ip1 = _data[i2].Value; + var ip0 = _data[i1].Key; + var ip1 = _data[i2].Key; var a = (smv - ip0) / (ip1 - ip0); - return Utils.InterpolateCubic(m_data[i0].Value, m_data[i1].Value, m_data[i2].Value, - m_data[i3].Value, a); + return Utils.InterpolateCubic(_data[i0].Value, _data[i1].Value, _data[i2].Value, + _data[i3].Value, a); } #endregion diff --git a/Operator/Displace.cs b/Operator/Displace.cs index 1eba86c..7d780dc 100755 --- a/Operator/Displace.cs +++ b/Operator/Displace.cs @@ -29,10 +29,10 @@ public Displace() public Displace(ModuleBase input, ModuleBase x, ModuleBase y, ModuleBase z) : base(4) { - m_modules[0] = input; - m_modules[1] = x; - m_modules[2] = y; - m_modules[3] = z; + Modules[0] = input; + Modules[1] = x; + Modules[2] = y; + Modules[3] = z; } #endregion @@ -44,11 +44,11 @@ public Displace(ModuleBase input, ModuleBase x, ModuleBase y, ModuleBase z) /// public ModuleBase X { - get { return m_modules[1]; } + get { return Modules[1]; } set { Debug.Assert(value != null); - m_modules[1] = value; + Modules[1] = value; } } @@ -57,11 +57,11 @@ public ModuleBase X /// public ModuleBase Y { - get { return m_modules[2]; } + get { return Modules[2]; } set { Debug.Assert(value != null); - m_modules[2] = value; + Modules[2] = value; } } @@ -70,11 +70,11 @@ public ModuleBase Y /// public ModuleBase Z { - get { return m_modules[3]; } + get { return Modules[3]; } set { Debug.Assert(value != null); - m_modules[3] = value; + Modules[3] = value; } } @@ -91,14 +91,14 @@ public ModuleBase Z /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); - Debug.Assert(m_modules[1] != null); - Debug.Assert(m_modules[2] != null); - Debug.Assert(m_modules[3] != null); - var dx = x + m_modules[1].GetValue(x, y, z); - var dy = y + m_modules[2].GetValue(x, y, z); - var dz = z + m_modules[3].GetValue(x, y, z); - return m_modules[0].GetValue(dx, dy, dz); + Debug.Assert(Modules[0] != null); + Debug.Assert(Modules[1] != null); + Debug.Assert(Modules[2] != null); + Debug.Assert(Modules[3] != null); + var dx = x + Modules[1].GetValue(x, y, z); + var dy = y + Modules[2].GetValue(x, y, z); + var dz = z + Modules[3].GetValue(x, y, z); + return Modules[0].GetValue(dx, dy, dz); } #endregion diff --git a/Operator/Exponent.cs b/Operator/Exponent.cs index 7c5826a..bd72e50 100755 --- a/Operator/Exponent.cs +++ b/Operator/Exponent.cs @@ -11,7 +11,7 @@ public class Exponent : ModuleBase { #region Fields - private double m_exponent = 1.0; + private double _exponent = 1.0; #endregion @@ -32,7 +32,7 @@ public Exponent() public Exponent(ModuleBase input) : base(1) { - m_modules[0] = input; + Modules[0] = input; } /// @@ -43,7 +43,7 @@ public Exponent(ModuleBase input) public Exponent(double exponent, ModuleBase input) : base(1) { - m_modules[0] = input; + Modules[0] = input; Value = exponent; } @@ -56,8 +56,8 @@ public Exponent(double exponent, ModuleBase input) /// public double Value { - get { return m_exponent; } - set { m_exponent = value; } + get { return _exponent; } + set { _exponent = value; } } #endregion @@ -73,9 +73,9 @@ public double Value /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); - var v = m_modules[0].GetValue(x, y, z); - return (Math.Pow(Math.Abs((v + 1.0) / 2.0), m_exponent) * 2.0 - 1.0); + Debug.Assert(Modules[0] != null); + var v = Modules[0].GetValue(x, y, z); + return (Math.Pow(Math.Abs((v + 1.0) / 2.0), _exponent) * 2.0 - 1.0); } #endregion diff --git a/Operator/Invert.cs b/Operator/Invert.cs index 12015ed..e6cf0f6 100755 --- a/Operator/Invert.cs +++ b/Operator/Invert.cs @@ -24,7 +24,7 @@ public Invert() public Invert(ModuleBase input) : base(1) { - m_modules[0] = input; + Modules[0] = input; } #endregion @@ -40,8 +40,8 @@ public Invert(ModuleBase input) /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); - return -m_modules[0].GetValue(x, y, z); + Debug.Assert(Modules[0] != null); + return -Modules[0].GetValue(x, y, z); } #endregion diff --git a/Operator/Max.cs b/Operator/Max.cs index 92a13b4..115cd53 100755 --- a/Operator/Max.cs +++ b/Operator/Max.cs @@ -27,8 +27,8 @@ public Max() public Max(ModuleBase lhs, ModuleBase rhs) : base(2) { - m_modules[0] = lhs; - m_modules[1] = rhs; + Modules[0] = lhs; + Modules[1] = rhs; } #endregion @@ -44,10 +44,10 @@ public Max(ModuleBase lhs, ModuleBase rhs) /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); - Debug.Assert(m_modules[1] != null); - var a = m_modules[0].GetValue(x, y, z); - var b = m_modules[1].GetValue(x, y, z); + Debug.Assert(Modules[0] != null); + Debug.Assert(Modules[1] != null); + var a = Modules[0].GetValue(x, y, z); + var b = Modules[1].GetValue(x, y, z); return Math.Max(a, b); } diff --git a/Operator/Min.cs b/Operator/Min.cs index a855e6d..e64d118 100755 --- a/Operator/Min.cs +++ b/Operator/Min.cs @@ -27,8 +27,8 @@ public Min() public Min(ModuleBase lhs, ModuleBase rhs) : base(2) { - m_modules[0] = lhs; - m_modules[1] = rhs; + Modules[0] = lhs; + Modules[1] = rhs; } #endregion @@ -44,10 +44,10 @@ public Min(ModuleBase lhs, ModuleBase rhs) /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); - Debug.Assert(m_modules[1] != null); - var a = m_modules[0].GetValue(x, y, z); - var b = m_modules[1].GetValue(x, y, z); + Debug.Assert(Modules[0] != null); + Debug.Assert(Modules[1] != null); + var a = Modules[0].GetValue(x, y, z); + var b = Modules[1].GetValue(x, y, z); return Math.Min(a, b); } diff --git a/Operator/Multiply.cs b/Operator/Multiply.cs index 2558ffc..1b779de 100755 --- a/Operator/Multiply.cs +++ b/Operator/Multiply.cs @@ -26,8 +26,8 @@ public Multiply() public Multiply(ModuleBase lhs, ModuleBase rhs) : base(2) { - m_modules[0] = lhs; - m_modules[1] = rhs; + Modules[0] = lhs; + Modules[1] = rhs; } #endregion @@ -43,9 +43,9 @@ public Multiply(ModuleBase lhs, ModuleBase rhs) /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); - Debug.Assert(m_modules[1] != null); - return m_modules[0].GetValue(x, y, z) * m_modules[1].GetValue(x, y, z); + Debug.Assert(Modules[0] != null); + Debug.Assert(Modules[1] != null); + return Modules[0].GetValue(x, y, z) * Modules[1].GetValue(x, y, z); } #endregion diff --git a/Operator/Power.cs b/Operator/Power.cs index fe68267..c8fe006 100755 --- a/Operator/Power.cs +++ b/Operator/Power.cs @@ -27,8 +27,8 @@ public Power() public Power(ModuleBase lhs, ModuleBase rhs) : base(2) { - m_modules[0] = lhs; - m_modules[1] = rhs; + Modules[0] = lhs; + Modules[1] = rhs; } #endregion @@ -44,9 +44,9 @@ public Power(ModuleBase lhs, ModuleBase rhs) /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); - Debug.Assert(m_modules[1] != null); - return Math.Pow(m_modules[0].GetValue(x, y, z), m_modules[1].GetValue(x, y, z)); + Debug.Assert(Modules[0] != null); + Debug.Assert(Modules[1] != null); + return Math.Pow(Modules[0].GetValue(x, y, z), Modules[1].GetValue(x, y, z)); } #endregion diff --git a/Operator/Rotate.cs b/Operator/Rotate.cs index 1adc258..8998571 100755 --- a/Operator/Rotate.cs +++ b/Operator/Rotate.cs @@ -12,18 +12,18 @@ public class Rotate : ModuleBase { #region Fields - private double m_x; - private double m_x1Matrix; - private double m_x2Matrix; - private double m_x3Matrix; - private double m_y; - private double m_y1Matrix; - private double m_y2Matrix; - private double m_y3Matrix; - private double m_z; - private double m_z1Matrix; - private double m_z2Matrix; - private double m_z3Matrix; + private double _x; + private double _x1Matrix; + private double _x2Matrix; + private double _x3Matrix; + private double _y; + private double _y1Matrix; + private double _y2Matrix; + private double _y3Matrix; + private double _z; + private double _z1Matrix; + private double _z2Matrix; + private double _z3Matrix; #endregion @@ -45,7 +45,7 @@ public Rotate() public Rotate(ModuleBase input) : base(1) { - m_modules[0] = input; + Modules[0] = input; } /// @@ -58,7 +58,7 @@ public Rotate(ModuleBase input) public Rotate(double x, double y, double z, ModuleBase input) : base(1) { - m_modules[0] = input; + Modules[0] = input; SetAngles(x, y, z); } @@ -71,8 +71,8 @@ public Rotate(double x, double y, double z, ModuleBase input) /// public double X { - get { return m_x; } - set { SetAngles(value, m_y, m_z); } + get { return _x; } + set { SetAngles(value, _y, _z); } } /// @@ -80,8 +80,8 @@ public double X /// public double Y { - get { return m_y; } - set { SetAngles(m_x, value, m_z); } + get { return _y; } + set { SetAngles(_x, value, _z); } } /// @@ -89,8 +89,8 @@ public double Y /// public double Z { - get { return m_x; } - set { SetAngles(m_x, m_y, value); } + get { return _x; } + set { SetAngles(_x, _y, value); } } #endregion @@ -111,18 +111,18 @@ private void SetAngles(double x, double y, double z) var xs = Math.Sin(x * Mathf.Deg2Rad); var ys = Math.Sin(y * Mathf.Deg2Rad); var zs = Math.Sin(z * Mathf.Deg2Rad); - m_x1Matrix = ys * xs * zs + yc * zc; - m_y1Matrix = xc * zs; - m_z1Matrix = ys * zc - yc * xs * zs; - m_x2Matrix = ys * xs * zc - yc * zs; - m_y2Matrix = xc * zc; - m_z2Matrix = -yc * xs * zc - ys * zs; - m_x3Matrix = -ys * xc; - m_y3Matrix = xs; - m_z3Matrix = yc * xc; - m_x = x; - m_y = y; - m_z = z; + _x1Matrix = ys * xs * zs + yc * zc; + _y1Matrix = xc * zs; + _z1Matrix = ys * zc - yc * xs * zs; + _x2Matrix = ys * xs * zc - yc * zs; + _y2Matrix = xc * zc; + _z2Matrix = -yc * xs * zc - ys * zs; + _x3Matrix = -ys * xc; + _y3Matrix = xs; + _z3Matrix = yc * xc; + _x = x; + _y = y; + _z = z; } #endregion @@ -138,11 +138,11 @@ private void SetAngles(double x, double y, double z) /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); - var nx = (m_x1Matrix * x) + (m_y1Matrix * y) + (m_z1Matrix * z); - var ny = (m_x2Matrix * x) + (m_y2Matrix * y) + (m_z2Matrix * z); - var nz = (m_x3Matrix * x) + (m_y3Matrix * y) + (m_z3Matrix * z); - return m_modules[0].GetValue(nx, ny, nz); + Debug.Assert(Modules[0] != null); + var nx = (_x1Matrix * x) + (_y1Matrix * y) + (_z1Matrix * z); + var ny = (_x2Matrix * x) + (_y2Matrix * y) + (_z2Matrix * z); + var nz = (_x3Matrix * x) + (_y3Matrix * y) + (_z3Matrix * z); + return Modules[0].GetValue(nx, ny, nz); } #endregion diff --git a/Operator/Scale.cs b/Operator/Scale.cs index a75d429..f2c8ff5 100755 --- a/Operator/Scale.cs +++ b/Operator/Scale.cs @@ -10,9 +10,9 @@ public class Scale : ModuleBase { #region Fields - private double m_x = 1.0; - private double m_y = 1.0; - private double m_z = 1.0; + private double _x = 1.0; + private double _y = 1.0; + private double _z = 1.0; #endregion @@ -33,7 +33,7 @@ public Scale() public Scale(ModuleBase input) : base(1) { - m_modules[0] = input; + Modules[0] = input; } /// @@ -46,7 +46,7 @@ public Scale(ModuleBase input) public Scale(double x, double y, double z, ModuleBase input) : base(1) { - m_modules[0] = input; + Modules[0] = input; X = x; Y = y; Z = z; @@ -61,8 +61,8 @@ public Scale(double x, double y, double z, ModuleBase input) /// public double X { - get { return m_x; } - set { m_x = value; } + get { return _x; } + set { _x = value; } } /// @@ -70,8 +70,8 @@ public double X /// public double Y { - get { return m_y; } - set { m_y = value; } + get { return _y; } + set { _y = value; } } /// @@ -79,8 +79,8 @@ public double Y /// public double Z { - get { return m_z; } - set { m_z = value; } + get { return _z; } + set { _z = value; } } #endregion @@ -96,8 +96,8 @@ public double Z /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); - return m_modules[0].GetValue(x * m_x, y * m_y, z * m_z); + Debug.Assert(Modules[0] != null); + return Modules[0].GetValue(x * _x, y * _y, z * _z); } #endregion diff --git a/Operator/ScaleBias.cs b/Operator/ScaleBias.cs index 0ca11c4..d1f8ab3 100755 --- a/Operator/ScaleBias.cs +++ b/Operator/ScaleBias.cs @@ -10,8 +10,8 @@ public class ScaleBias : ModuleBase { #region Fields - private double m_scale = 1.0; - private double m_bias; + private double _scale = 1.0; + private double _bias; #endregion @@ -32,7 +32,7 @@ public ScaleBias() public ScaleBias(ModuleBase input) : base(1) { - m_modules[0] = input; + Modules[0] = input; } /// @@ -44,7 +44,7 @@ public ScaleBias(ModuleBase input) public ScaleBias(double scale, double bias, ModuleBase input) : base(1) { - m_modules[0] = input; + Modules[0] = input; Bias = bias; Scale = scale; } @@ -58,8 +58,8 @@ public ScaleBias(double scale, double bias, ModuleBase input) /// public double Bias { - get { return m_bias; } - set { m_bias = value; } + get { return _bias; } + set { _bias = value; } } /// @@ -67,8 +67,8 @@ public double Bias /// public double Scale { - get { return m_scale; } - set { m_scale = value; } + get { return _scale; } + set { _scale = value; } } #endregion @@ -84,8 +84,8 @@ public double Scale /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); - return m_modules[0].GetValue(x, y, z) * m_scale + m_bias; + Debug.Assert(Modules[0] != null); + return Modules[0].GetValue(x, y, z) * _scale + _bias; } #endregion diff --git a/Operator/Select.cs b/Operator/Select.cs index 1576a96..f13557d 100755 --- a/Operator/Select.cs +++ b/Operator/Select.cs @@ -10,10 +10,10 @@ public class Select : ModuleBase { #region Fields - private double m_fallOff; - private double m_raw; - private double m_min = -1.0; - private double m_max = 1.0; + private double _fallOff; + private double _raw; + private double _min = -1.0; + private double _max = 1.0; #endregion @@ -32,13 +32,13 @@ public Select() /// /// The first input module. /// The second input module. - /// The controller module. + /// The controller module. public Select(ModuleBase inputA, ModuleBase inputB, ModuleBase controller) : base(3) { - m_modules[0] = inputA; - m_modules[1] = inputB; - m_modules[2] = controller; + Modules[0] = inputA; + Modules[1] = inputB; + Modules[2] = controller; } /// @@ -52,8 +52,8 @@ public Select(ModuleBase inputA, ModuleBase inputB, ModuleBase controller) public Select(double min, double max, double fallOff, ModuleBase inputA, ModuleBase inputB) : this(inputA, inputB, null) { - m_min = min; - m_max = max; + _min = min; + _max = max; FallOff = fallOff; } @@ -66,11 +66,11 @@ public Select(double min, double max, double fallOff, ModuleBase inputA, ModuleB /// public ModuleBase Controller { - get { return m_modules[2]; } + get { return Modules[2]; } set { Debug.Assert(value != null); - m_modules[2] = value; + Modules[2] = value; } } @@ -79,12 +79,12 @@ public ModuleBase Controller /// public double FallOff { - get { return m_fallOff; } + get { return _fallOff; } set { - var bs = m_max - m_min; - m_raw = value; - m_fallOff = (value > bs / 2) ? bs / 2 : value; + var bs = _max - _min; + _raw = value; + _fallOff = (value > bs / 2) ? bs / 2 : value; } } @@ -93,11 +93,11 @@ public double FallOff /// public double Maximum { - get { return m_max; } + get { return _max; } set { - m_max = value; - FallOff = m_raw; + _max = value; + FallOff = _raw; } } @@ -106,11 +106,11 @@ public double Maximum /// public double Minimum { - get { return m_min; } + get { return _min; } set { - m_min = value; - FallOff = m_raw; + _min = value; + FallOff = _raw; } } @@ -126,9 +126,9 @@ public double Minimum public void SetBounds(double min, double max) { Debug.Assert(min < max); - m_min = min; - m_max = max; - FallOff = m_fallOff; + _min = min; + _max = max; + FallOff = _fallOff; } #endregion @@ -144,44 +144,44 @@ public void SetBounds(double min, double max) /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); - Debug.Assert(m_modules[1] != null); - Debug.Assert(m_modules[2] != null); - var cv = m_modules[2].GetValue(x, y, z); - double a; - if (m_fallOff > 0.0) + Debug.Assert(Modules[0] != null); + Debug.Assert(Modules[1] != null); + Debug.Assert(Modules[2] != null); + var cv = Modules[2].GetValue(x, y, z); + if (_fallOff > 0.0) { - if (cv < (m_min - m_fallOff)) + double a; + if (cv < (_min - _fallOff)) { - return m_modules[0].GetValue(x, y, z); + return Modules[0].GetValue(x, y, z); } - if (cv < (m_min + m_fallOff)) + if (cv < (_min + _fallOff)) { - var lc = (m_min - m_fallOff); - var uc = (m_min + m_fallOff); + var lc = (_min - _fallOff); + var uc = (_min + _fallOff); a = Utils.MapCubicSCurve((cv - lc) / (uc - lc)); - return Utils.InterpolateLinear(m_modules[0].GetValue(x, y, z), - m_modules[1].GetValue(x, y, z), a); + return Utils.InterpolateLinear(Modules[0].GetValue(x, y, z), + Modules[1].GetValue(x, y, z), a); } - if (cv < (m_max - m_fallOff)) + if (cv < (_max - _fallOff)) { - return m_modules[1].GetValue(x, y, z); + return Modules[1].GetValue(x, y, z); } - if (cv < (m_max + m_fallOff)) + if (cv < (_max + _fallOff)) { - var lc = (m_max - m_fallOff); - var uc = (m_max + m_fallOff); + var lc = (_max - _fallOff); + var uc = (_max + _fallOff); a = Utils.MapCubicSCurve((cv - lc) / (uc - lc)); - return Utils.InterpolateLinear(m_modules[1].GetValue(x, y, z), - m_modules[0].GetValue(x, y, z), a); + return Utils.InterpolateLinear(Modules[1].GetValue(x, y, z), + Modules[0].GetValue(x, y, z), a); } - return m_modules[0].GetValue(x, y, z); + return Modules[0].GetValue(x, y, z); } - if (cv < m_min || cv > m_max) + if (cv < _min || cv > _max) { - return m_modules[0].GetValue(x, y, z); + return Modules[0].GetValue(x, y, z); } - return m_modules[1].GetValue(x, y, z); + return Modules[1].GetValue(x, y, z); } #endregion diff --git a/Operator/Subtract.cs b/Operator/Subtract.cs index 03d49d3..f3b43a3 100755 --- a/Operator/Subtract.cs +++ b/Operator/Subtract.cs @@ -26,8 +26,8 @@ public Subtract() public Subtract(ModuleBase lhs, ModuleBase rhs) : base(2) { - m_modules[0] = lhs; - m_modules[1] = rhs; + Modules[0] = lhs; + Modules[1] = rhs; } #endregion @@ -43,9 +43,9 @@ public Subtract(ModuleBase lhs, ModuleBase rhs) /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); - Debug.Assert(m_modules[1] != null); - return m_modules[0].GetValue(x, y, z) - m_modules[1].GetValue(x, y, z); + Debug.Assert(Modules[0] != null); + Debug.Assert(Modules[1] != null); + return Modules[0].GetValue(x, y, z) - Modules[1].GetValue(x, y, z); } #endregion diff --git a/Operator/Terrace.cs b/Operator/Terrace.cs index 6b2ade6..217e88a 100755 --- a/Operator/Terrace.cs +++ b/Operator/Terrace.cs @@ -13,8 +13,8 @@ public class Terrace : ModuleBase { #region Fields - private readonly List m_data = new List(); - private bool m_inverted; + private readonly List _data = new List(); + private bool _inverted; #endregion @@ -35,7 +35,7 @@ public Terrace() public Terrace(ModuleBase input) : base(1) { - m_modules[0] = input; + Modules[0] = input; } /// @@ -46,7 +46,7 @@ public Terrace(ModuleBase input) public Terrace(bool inverted, ModuleBase input) : base(1) { - m_modules[0] = input; + Modules[0] = input; IsInverted = inverted; } @@ -59,7 +59,7 @@ public Terrace(bool inverted, ModuleBase input) /// public int ControlPointCount { - get { return m_data.Count; } + get { return _data.Count; } } /// @@ -67,7 +67,7 @@ public int ControlPointCount /// public List ControlPoints { - get { return m_data; } + get { return _data; } } /// @@ -75,8 +75,8 @@ public List ControlPoints /// public bool IsInverted { - get { return m_inverted; } - set { m_inverted = value; } + get { return _inverted; } + set { _inverted = value; } } #endregion @@ -89,11 +89,11 @@ public bool IsInverted /// The curves input value. public void Add(double input) { - if (!m_data.Contains(input)) + if (!_data.Contains(input)) { - m_data.Add(input); + _data.Add(input); } - m_data.Sort(delegate(double lhs, double rhs) { return lhs.CompareTo(rhs); }); + _data.Sort(delegate(double lhs, double rhs) { return lhs.CompareTo(rhs); }); } /// @@ -101,7 +101,7 @@ public void Add(double input) /// public void Clear() { - m_data.Clear(); + _data.Clear(); } /// @@ -137,27 +137,27 @@ public void Generate(int steps) /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); + Debug.Assert(Modules[0] != null); Debug.Assert(ControlPointCount >= 2); - var smv = m_modules[0].GetValue(x, y, z); + var smv = Modules[0].GetValue(x, y, z); int ip; - for (ip = 0; ip < m_data.Count; ip++) + for (ip = 0; ip < _data.Count; ip++) { - if (smv < m_data[ip]) + if (smv < _data[ip]) { break; } } - var i0 = Mathf.Clamp(ip - 1, 0, m_data.Count - 1); - var i1 = Mathf.Clamp(ip, 0, m_data.Count - 1); + var i0 = Mathf.Clamp(ip - 1, 0, _data.Count - 1); + var i1 = Mathf.Clamp(ip, 0, _data.Count - 1); if (i0 == i1) { - return m_data[i1]; + return _data[i1]; } - var v0 = m_data[i0]; - var v1 = m_data[i1]; + var v0 = _data[i0]; + var v1 = _data[i1]; var a = (smv - v0) / (v1 - v0); - if (m_inverted) + if (_inverted) { a = 1.0 - a; var t = v0; diff --git a/Operator/Translate.cs b/Operator/Translate.cs index 6e9799e..e17a037 100755 --- a/Operator/Translate.cs +++ b/Operator/Translate.cs @@ -10,9 +10,9 @@ public class Translate : ModuleBase { #region Fields - private double m_x = 1.0; - private double m_y = 1.0; - private double m_z = 1.0; + private double _x = 1.0; + private double _y = 1.0; + private double _z = 1.0; #endregion @@ -33,7 +33,7 @@ public Translate() public Translate(ModuleBase input) : base(1) { - m_modules[0] = input; + Modules[0] = input; } /// @@ -46,7 +46,7 @@ public Translate(ModuleBase input) public Translate(double x, double y, double z, ModuleBase input) : base(1) { - m_modules[0] = input; + Modules[0] = input; X = x; Y = y; Z = z; @@ -61,8 +61,8 @@ public Translate(double x, double y, double z, ModuleBase input) /// public double X { - get { return m_x; } - set { m_x = value; } + get { return _x; } + set { _x = value; } } /// @@ -70,8 +70,8 @@ public double X /// public double Y { - get { return m_y; } - set { m_y = value; } + get { return _y; } + set { _y = value; } } /// @@ -79,8 +79,8 @@ public double Y /// public double Z { - get { return m_z; } - set { m_z = value; } + get { return _z; } + set { _z = value; } } #endregion @@ -96,8 +96,8 @@ public double Z /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); - return m_modules[0].GetValue(x + m_x, y + m_y, z + m_z); + Debug.Assert(Modules[0] != null); + return Modules[0].GetValue(x + _x, y + _y, z + _z); } #endregion diff --git a/Operator/Turbulence.cs b/Operator/Turbulence.cs index 96f7b19..f0a15b2 100755 --- a/Operator/Turbulence.cs +++ b/Operator/Turbulence.cs @@ -25,10 +25,10 @@ public class Turbulence : ModuleBase #region Fields - private double m_power = 1.0; - private readonly Perlin m_xDistort; - private readonly Perlin m_yDistort; - private readonly Perlin m_zDistort; + private double _power = 1.0; + private readonly Perlin _xDistort; + private readonly Perlin _yDistort; + private readonly Perlin _zDistort; #endregion @@ -40,9 +40,9 @@ public class Turbulence : ModuleBase public Turbulence() : base(1) { - m_xDistort = new Perlin(); - m_yDistort = new Perlin(); - m_zDistort = new Perlin(); + _xDistort = new Perlin(); + _yDistort = new Perlin(); + _zDistort = new Perlin(); } /// @@ -52,10 +52,10 @@ public Turbulence() public Turbulence(ModuleBase input) : base(1) { - m_xDistort = new Perlin(); - m_yDistort = new Perlin(); - m_zDistort = new Perlin(); - m_modules[0] = input; + _xDistort = new Perlin(); + _yDistort = new Perlin(); + _zDistort = new Perlin(); + Modules[0] = input; } /// @@ -77,10 +77,10 @@ public Turbulence(double power, ModuleBase input) public Turbulence(Perlin x, Perlin y, Perlin z, double power, ModuleBase input) : base(1) { - m_xDistort = x; - m_yDistort = y; - m_zDistort = z; - m_modules[0] = input; + _xDistort = x; + _yDistort = y; + _zDistort = z; + Modules[0] = input; Power = power; } @@ -93,12 +93,12 @@ public Turbulence(Perlin x, Perlin y, Perlin z, double power, ModuleBase input) /// public double Frequency { - get { return m_xDistort.Frequency; } + get { return _xDistort.Frequency; } set { - m_xDistort.Frequency = value; - m_yDistort.Frequency = value; - m_zDistort.Frequency = value; + _xDistort.Frequency = value; + _yDistort.Frequency = value; + _zDistort.Frequency = value; } } @@ -107,8 +107,8 @@ public double Frequency /// public double Power { - get { return m_power; } - set { m_power = value; } + get { return _power; } + set { _power = value; } } /// @@ -116,12 +116,12 @@ public double Power /// public int Roughness { - get { return m_xDistort.OctaveCount; } + get { return _xDistort.OctaveCount; } set { - m_xDistort.OctaveCount = value; - m_yDistort.OctaveCount = value; - m_zDistort.OctaveCount = value; + _xDistort.OctaveCount = value; + _yDistort.OctaveCount = value; + _zDistort.OctaveCount = value; } } @@ -130,12 +130,12 @@ public int Roughness /// public int Seed { - get { return m_xDistort.Seed; } + get { return _xDistort.Seed; } set { - m_xDistort.Seed = value; - m_yDistort.Seed = value + 1; - m_zDistort.Seed = value + 2; + _xDistort.Seed = value; + _yDistort.Seed = value + 1; + _zDistort.Seed = value + 2; } } @@ -152,11 +152,11 @@ public int Seed /// The resulting output value. public override double GetValue(double x, double y, double z) { - Debug.Assert(m_modules[0] != null); - var xd = x + (m_xDistort.GetValue(x + X0, y + Y0, z + Z0) * m_power); - var yd = y + (m_yDistort.GetValue(x + X1, y + Y1, z + Z1) * m_power); - var zd = z + (m_zDistort.GetValue(x + X2, y + Y2, z + Z2) * m_power); - return m_modules[0].GetValue(xd, yd, zd); + Debug.Assert(Modules[0] != null); + var xd = x + (_xDistort.GetValue(x + X0, y + Y0, z + Z0) * _power); + var yd = y + (_yDistort.GetValue(x + X1, y + Y1, z + Z1) * _power); + var zd = z + (_zDistort.GetValue(x + X2, y + Y2, z + Z2) * _power); + return Modules[0].GetValue(xd, yd, zd); } #endregion diff --git a/Utils.cs b/Utils.cs index 4199d8f..2b29933 100755 --- a/Utils.cs +++ b/Utils.cs @@ -27,7 +27,7 @@ internal static class Utils #region Fields - internal static double[] _randoms = + internal static readonly double[] Randoms = { -0.763874, -0.596439, -0.246489, 0.0, 0.396055, 0.904518, -0.158073, 0.0, -0.499004, -0.8665, -0.0131631, 0.0, 0.468724, -0.824756, 0.316346, 0.0, @@ -196,21 +196,20 @@ internal static double GradientCoherentNoise3D(double x, double y, double z, lon break; } } - double n0, n1, ix0, ix1, iy0, iy1; - n0 = GradientNoise3D(x, y, z, x0, y0, z0, seed); - n1 = GradientNoise3D(x, y, z, x1, y0, z0, seed); - ix0 = InterpolateLinear(n0, n1, xs); + var n0 = GradientNoise3D(x, y, z, x0, y0, z0, seed); + var n1 = GradientNoise3D(x, y, z, x1, y0, z0, seed); + var ix0 = InterpolateLinear(n0, n1, xs); n0 = GradientNoise3D(x, y, z, x0, y1, z0, seed); n1 = GradientNoise3D(x, y, z, x1, y1, z0, seed); - ix1 = InterpolateLinear(n0, n1, xs); - iy0 = InterpolateLinear(ix0, ix1, ys); + var ix1 = InterpolateLinear(n0, n1, xs); + var iy0 = InterpolateLinear(ix0, ix1, ys); n0 = GradientNoise3D(x, y, z, x0, y0, z1, seed); n1 = GradientNoise3D(x, y, z, x1, y0, z1, seed); ix0 = InterpolateLinear(n0, n1, xs); n0 = GradientNoise3D(x, y, z, x0, y1, z1, seed); n1 = GradientNoise3D(x, y, z, x1, y1, z1, seed); ix1 = InterpolateLinear(n0, n1, xs); - iy1 = InterpolateLinear(ix0, ix1, ys); + var iy1 = InterpolateLinear(ix0, ix1, ys); return InterpolateLinear(iy0, iy1, zs); } @@ -220,9 +219,9 @@ internal static double GradientNoise3D(double fx, double fy, double fz, int ix, GeneratorSeed * seed) & 0xffffffff; i ^= (i >> GeneratorShift); i &= 0xff; - var xvg = _randoms[(i << 2)]; - var yvg = _randoms[(i << 2) + 1]; - var zvg = _randoms[(i << 2) + 2]; + var xvg = Randoms[(i << 2)]; + var yvg = Randoms[(i << 2) + 1]; + var zvg = Randoms[(i << 2) + 2]; var xvp = (fx - ix); var yvp = (fy - iy); var zvp = (fz - iz); From a3fd10f33d8f2df45c12e85c18f87b5638a7a64e Mon Sep 17 00:00:00 2001 From: "Ricardo J. Mendez" Date: Mon, 21 Jul 2014 13:36:37 +0300 Subject: [PATCH 3/7] Added note to Noise2D about its noiseutils equivalence --- Noise2D.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Noise2D.cs b/Noise2D.cs index 3efeaee..8a62314 100755 --- a/Noise2D.cs +++ b/Noise2D.cs @@ -7,6 +7,9 @@ namespace LibNoise.Unity /// /// Provides a two-dimensional noise map. /// + /// This covers most of the functionality from LibNoise's noiseutils library, but + /// the method calls might not be the same. See the tutorials project if you're wondering + /// which calls are equivalent. public class Noise2D : IDisposable { #region Constants From 82f4858e231d2fb902f64fb544da7d35f01698c0 Mon Sep 17 00:00:00 2001 From: "Ricardo J. Mendez" Date: Mon, 21 Jul 2014 14:52:07 +0300 Subject: [PATCH 4/7] Referencing tutorial/samples project on README --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index acbf618..92211c8 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ an example scene, which can be found [here](http://forum.unity3d.com/threads/68764-LibNoise-Ported-to-Unity). Please note that LibNoise.Unity is only a repository for the library code itself and contains no example files. +[You can also see the converted tutorials examples on this repository](https://github.com/ricardojmendez/LibNoiseTutorials). + Other contributors to LibNoise.Unity include [Teddy Bradford](https://github.com/teddybradford) who reworked much of the Noise2D class to improve tiling support for noise maps. From 782f209182c5997b695b27c092370bda109a28f3 Mon Sep 17 00:00:00 2001 From: "Ricardo J. Mendez" Date: Tue, 22 Jul 2014 00:30:51 +0300 Subject: [PATCH 5/7] Removed .Unity from the namespace It was redundant, since it's not like someone is going to accidentally import LibNoise.Python into their Unity project. --- Generator/Billow.cs | 2 +- Generator/Checker.cs | 2 +- Generator/Const.cs | 2 +- Generator/Cylinders.cs | 2 +- Generator/Perlin.cs | 2 +- Generator/RidgedMultifractal.cs | 2 +- Generator/Spheres.cs | 2 +- Generator/Voronoi.cs | 2 +- GradientPresets.cs | 2 +- ModuleBase.cs | 2 +- Noise2D.cs | 2 +- Operator/Abs.cs | 2 +- Operator/Add.cs | 2 +- Operator/Blend.cs | 2 +- Operator/Cache.cs | 2 +- Operator/Clamp.cs | 2 +- Operator/Curve.cs | 2 +- Operator/Displace.cs | 2 +- Operator/Exponent.cs | 2 +- Operator/Invert.cs | 2 +- Operator/Max.cs | 2 +- Operator/Min.cs | 2 +- Operator/Multiply.cs | 2 +- Operator/Power.cs | 2 +- Operator/Rotate.cs | 2 +- Operator/Scale.cs | 2 +- Operator/ScaleBias.cs | 2 +- Operator/Select.cs | 2 +- Operator/Subtract.cs | 2 +- Operator/Terrace.cs | 2 +- Operator/Translate.cs | 2 +- Operator/Turbulence.cs | 4 ++-- Utils.cs | 2 +- 33 files changed, 34 insertions(+), 34 deletions(-) diff --git a/Generator/Billow.cs b/Generator/Billow.cs index cf323d6..dc9af92 100755 --- a/Generator/Billow.cs +++ b/Generator/Billow.cs @@ -1,7 +1,7 @@ using System; using UnityEngine; -namespace LibNoise.Unity.Generator +namespace LibNoise.Generator { /// /// Provides a noise module that outputs a three-dimensional billowy noise. [GENERATOR] diff --git a/Generator/Checker.cs b/Generator/Checker.cs index 29c1641..affe2df 100755 --- a/Generator/Checker.cs +++ b/Generator/Checker.cs @@ -1,6 +1,6 @@ using System; -namespace LibNoise.Unity.Generator +namespace LibNoise.Generator { /// /// Provides a noise module that outputs a checkerboard pattern. [GENERATOR] diff --git a/Generator/Const.cs b/Generator/Const.cs index 5aa4f9c..27ac870 100755 --- a/Generator/Const.cs +++ b/Generator/Const.cs @@ -1,4 +1,4 @@ -namespace LibNoise.Unity.Generator +namespace LibNoise.Generator { /// /// Provides a noise module that outputs a constant value. [GENERATOR] diff --git a/Generator/Cylinders.cs b/Generator/Cylinders.cs index 6dc1911..ea2142f 100755 --- a/Generator/Cylinders.cs +++ b/Generator/Cylinders.cs @@ -1,6 +1,6 @@ using System; -namespace LibNoise.Unity.Generator +namespace LibNoise.Generator { /// /// Provides a noise module that outputs concentric cylinders. [GENERATOR] diff --git a/Generator/Perlin.cs b/Generator/Perlin.cs index 0e37d40..ee9381f 100755 --- a/Generator/Perlin.cs +++ b/Generator/Perlin.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace LibNoise.Unity.Generator +namespace LibNoise.Generator { /// /// Provides a noise module that outputs a three-dimensional perlin noise. [GENERATOR] diff --git a/Generator/RidgedMultifractal.cs b/Generator/RidgedMultifractal.cs index 83a173d..939faf2 100755 --- a/Generator/RidgedMultifractal.cs +++ b/Generator/RidgedMultifractal.cs @@ -1,7 +1,7 @@ using System; using UnityEngine; -namespace LibNoise.Unity.Generator +namespace LibNoise.Generator { /// /// Provides a noise module that outputs 3-dimensional ridged-multifractal noise. [GENERATOR] diff --git a/Generator/Spheres.cs b/Generator/Spheres.cs index f74af04..5f35cea 100755 --- a/Generator/Spheres.cs +++ b/Generator/Spheres.cs @@ -1,6 +1,6 @@ using System; -namespace LibNoise.Unity.Generator +namespace LibNoise.Generator { /// /// Provides a noise module that outputs concentric spheres. [GENERATOR] diff --git a/Generator/Voronoi.cs b/Generator/Voronoi.cs index bcd887e..83cb597 100755 --- a/Generator/Voronoi.cs +++ b/Generator/Voronoi.cs @@ -1,6 +1,6 @@ using System; -namespace LibNoise.Unity.Generator +namespace LibNoise.Generator { /// /// Provides a noise module that outputs Voronoi cells. [GENERATOR] diff --git a/GradientPresets.cs b/GradientPresets.cs index 9f0e6c5..782d498 100755 --- a/GradientPresets.cs +++ b/GradientPresets.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using UnityEngine; -namespace LibNoise.Unity +namespace LibNoise { /// /// Provides a series of gradient presets diff --git a/ModuleBase.cs b/ModuleBase.cs index 8b7ac20..c6cef0f 100755 --- a/ModuleBase.cs +++ b/ModuleBase.cs @@ -3,7 +3,7 @@ using UnityEngine; using Debug = System.Diagnostics.Debug; -namespace LibNoise.Unity +namespace LibNoise { #region Enumerations diff --git a/Noise2D.cs b/Noise2D.cs index 8a62314..fdc2c6d 100755 --- a/Noise2D.cs +++ b/Noise2D.cs @@ -2,7 +2,7 @@ using System.Xml.Serialization; using UnityEngine; -namespace LibNoise.Unity +namespace LibNoise { /// /// Provides a two-dimensional noise map. diff --git a/Operator/Abs.cs b/Operator/Abs.cs index f6ca945..e56064f 100755 --- a/Operator/Abs.cs +++ b/Operator/Abs.cs @@ -1,7 +1,7 @@ using System; using System.Diagnostics; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that outputs the absolute value of the output value from diff --git a/Operator/Add.cs b/Operator/Add.cs index 8a3709b..4c3393b 100755 --- a/Operator/Add.cs +++ b/Operator/Add.cs @@ -1,6 +1,6 @@ using System.Diagnostics; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that outputs the sum of the two output values from two diff --git a/Operator/Blend.cs b/Operator/Blend.cs index 4d60c25..f8dae28 100755 --- a/Operator/Blend.cs +++ b/Operator/Blend.cs @@ -1,6 +1,6 @@ using System.Diagnostics; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that outputs a weighted blend of the output values from diff --git a/Operator/Cache.cs b/Operator/Cache.cs index cf8a3f7..a8013e0 100755 --- a/Operator/Cache.cs +++ b/Operator/Cache.cs @@ -1,6 +1,6 @@ using System.Diagnostics; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that caches the last output value generated by a source diff --git a/Operator/Clamp.cs b/Operator/Clamp.cs index 283d613..f25b447 100755 --- a/Operator/Clamp.cs +++ b/Operator/Clamp.cs @@ -1,6 +1,6 @@ using System.Diagnostics; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that clamps the output value from a source module to a diff --git a/Operator/Curve.cs b/Operator/Curve.cs index 0aa9b8b..186cd8c 100755 --- a/Operator/Curve.cs +++ b/Operator/Curve.cs @@ -2,7 +2,7 @@ using UnityEngine; using Debug = System.Diagnostics.Debug; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that maps the output value from a source module onto an diff --git a/Operator/Displace.cs b/Operator/Displace.cs index 7d780dc..c14b836 100755 --- a/Operator/Displace.cs +++ b/Operator/Displace.cs @@ -1,6 +1,6 @@ using System.Diagnostics; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that uses three source modules to displace each diff --git a/Operator/Exponent.cs b/Operator/Exponent.cs index bd72e50..707aab3 100755 --- a/Operator/Exponent.cs +++ b/Operator/Exponent.cs @@ -1,7 +1,7 @@ using System; using System.Diagnostics; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that maps the output value from a source module onto an diff --git a/Operator/Invert.cs b/Operator/Invert.cs index e6cf0f6..2a88494 100755 --- a/Operator/Invert.cs +++ b/Operator/Invert.cs @@ -1,6 +1,6 @@ using System.Diagnostics; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that inverts the output value from a source module. [OPERATOR] diff --git a/Operator/Max.cs b/Operator/Max.cs index 115cd53..8a50d14 100755 --- a/Operator/Max.cs +++ b/Operator/Max.cs @@ -1,7 +1,7 @@ using System; using System.Diagnostics; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that outputs the larger of the two output values from two diff --git a/Operator/Min.cs b/Operator/Min.cs index e64d118..614a3e7 100755 --- a/Operator/Min.cs +++ b/Operator/Min.cs @@ -1,7 +1,7 @@ using System; using System.Diagnostics; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that outputs the smaller of the two output values from two diff --git a/Operator/Multiply.cs b/Operator/Multiply.cs index 1b779de..61c512d 100755 --- a/Operator/Multiply.cs +++ b/Operator/Multiply.cs @@ -1,6 +1,6 @@ using System.Diagnostics; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that outputs the product of the two output values from diff --git a/Operator/Power.cs b/Operator/Power.cs index c8fe006..274dc3f 100755 --- a/Operator/Power.cs +++ b/Operator/Power.cs @@ -1,7 +1,7 @@ using System; using System.Diagnostics; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that outputs value from a first source module diff --git a/Operator/Rotate.cs b/Operator/Rotate.cs index 8998571..a0a6794 100755 --- a/Operator/Rotate.cs +++ b/Operator/Rotate.cs @@ -2,7 +2,7 @@ using UnityEngine; using Debug = System.Diagnostics.Debug; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that rotates the input value around the origin before diff --git a/Operator/Scale.cs b/Operator/Scale.cs index f2c8ff5..b58a564 100755 --- a/Operator/Scale.cs +++ b/Operator/Scale.cs @@ -1,6 +1,6 @@ using System.Diagnostics; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that scales the coordinates of the input value before diff --git a/Operator/ScaleBias.cs b/Operator/ScaleBias.cs index d1f8ab3..e4e9b28 100755 --- a/Operator/ScaleBias.cs +++ b/Operator/ScaleBias.cs @@ -1,6 +1,6 @@ using System.Diagnostics; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that applies a scaling factor and a bias to the output diff --git a/Operator/Select.cs b/Operator/Select.cs index f13557d..28cc99a 100755 --- a/Operator/Select.cs +++ b/Operator/Select.cs @@ -1,6 +1,6 @@ using System.Diagnostics; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that outputs the value selected from one of two source diff --git a/Operator/Subtract.cs b/Operator/Subtract.cs index f3b43a3..a44cd2b 100755 --- a/Operator/Subtract.cs +++ b/Operator/Subtract.cs @@ -1,6 +1,6 @@ using System.Diagnostics; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that outputs the difference of the two output values from two diff --git a/Operator/Terrace.cs b/Operator/Terrace.cs index 217e88a..5b80f64 100755 --- a/Operator/Terrace.cs +++ b/Operator/Terrace.cs @@ -3,7 +3,7 @@ using UnityEngine; using Debug = System.Diagnostics.Debug; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that maps the output value from a source module onto a diff --git a/Operator/Translate.cs b/Operator/Translate.cs index e17a037..cce770f 100755 --- a/Operator/Translate.cs +++ b/Operator/Translate.cs @@ -1,6 +1,6 @@ using System.Diagnostics; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that moves the coordinates of the input value before diff --git a/Operator/Turbulence.cs b/Operator/Turbulence.cs index f0a15b2..9d3d486 100755 --- a/Operator/Turbulence.cs +++ b/Operator/Turbulence.cs @@ -1,7 +1,7 @@ using System.Diagnostics; -using LibNoise.Unity.Generator; +using LibNoise.Generator; -namespace LibNoise.Unity.Operator +namespace LibNoise.Operator { /// /// Provides a noise module that that randomly displaces the input value before diff --git a/Utils.cs b/Utils.cs index 2b29933..d1867cd 100755 --- a/Utils.cs +++ b/Utils.cs @@ -1,6 +1,6 @@ using System; -namespace LibNoise.Unity +namespace LibNoise { internal static class Utils { From f77e67af30b40991debf8e1078adc922092b7c69 Mon Sep 17 00:00:00 2001 From: "Ricardo J. Mendez" Date: Wed, 23 Jul 2014 08:16:34 +0300 Subject: [PATCH 6/7] Expanded Select property documentation --- Operator/Select.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Operator/Select.cs b/Operator/Select.cs index 28cc99a..d29a101 100755 --- a/Operator/Select.cs +++ b/Operator/Select.cs @@ -77,6 +77,9 @@ public ModuleBase Controller /// /// Gets or sets the falloff value at the edge transition. /// + /// + /// Called SetEdgeFallOff() on the original LibNoise. + /// public double FallOff { get { return _fallOff; } @@ -89,7 +92,7 @@ public double FallOff } /// - /// Gets or sets the maximum. + /// Gets or sets the maximum, and re-calculated the fall-off accordingly. /// public double Maximum { @@ -102,7 +105,7 @@ public double Maximum } /// - /// Gets or sets the minimum. + /// Gets or sets the minimum, and re-calculated the fall-off accordingly. /// public double Minimum { From 256d4b2d66ce7cbb765ffe77d19b0482f6f89714 Mon Sep 17 00:00:00 2001 From: "Ricardo J. Mendez" Date: Thu, 24 Jul 2014 10:13:27 +0300 Subject: [PATCH 7/7] Removed unnecessary backing fields from ScaleBias --- Operator/ScaleBias.cs | 170 +++++++++++++++++++----------------------- 1 file changed, 78 insertions(+), 92 deletions(-) diff --git a/Operator/ScaleBias.cs b/Operator/ScaleBias.cs index e4e9b28..8da7799 100755 --- a/Operator/ScaleBias.cs +++ b/Operator/ScaleBias.cs @@ -1,93 +1,79 @@ -using System.Diagnostics; - -namespace LibNoise.Operator -{ - /// - /// Provides a noise module that applies a scaling factor and a bias to the output - /// value from a source module. [OPERATOR] - /// - public class ScaleBias : ModuleBase - { - #region Fields - - private double _scale = 1.0; - private double _bias; - - #endregion - - #region Constructors - - /// - /// Initializes a new instance of ScaleBias. - /// - public ScaleBias() - : base(1) - { - } - - /// - /// Initializes a new instance of ScaleBias. - /// - /// The input module. - public ScaleBias(ModuleBase input) - : base(1) - { - Modules[0] = input; - } - - /// - /// Initializes a new instance of ScaleBias. - /// - /// The scaling factor to apply to the output value from the source module. - /// The bias to apply to the scaled output value from the source module. - /// The input module. - public ScaleBias(double scale, double bias, ModuleBase input) - : base(1) - { - Modules[0] = input; - Bias = bias; - Scale = scale; - } - - #endregion - - #region Properties - - /// - /// Gets or sets the bias to apply to the scaled output value from the source module. - /// - public double Bias - { - get { return _bias; } - set { _bias = value; } - } - - /// - /// Gets or sets the scaling factor to apply to the output value from the source module. - /// - public double Scale - { - get { return _scale; } - set { _scale = 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); - return Modules[0].GetValue(x, y, z) * _scale + _bias; - } - - #endregion - } +using System.Diagnostics; + +namespace LibNoise.Operator +{ + /// + /// Provides a noise module that applies a scaling factor and a bias to the output + /// value from a source module. [OPERATOR] + /// + public class ScaleBias : ModuleBase + { + #region Constructors + + /// + /// Initializes a new instance of ScaleBias. + /// + public ScaleBias() + : base(1) + { + Scale = 1; + } + + /// + /// Initializes a new instance of ScaleBias. + /// + /// The input module. + public ScaleBias(ModuleBase input) + : base(1) + { + Modules[0] = input; + Scale = 1; + } + + /// + /// Initializes a new instance of ScaleBias. + /// + /// The scaling factor to apply to the output value from the source module. + /// The bias to apply to the scaled output value from the source module. + /// The input module. + public ScaleBias(double scale, double bias, ModuleBase input) + : base(1) + { + Modules[0] = input; + Bias = bias; + Scale = scale; + } + + #endregion + + #region Properties + + /// + /// Gets or sets the bias to apply to the scaled output value from the source module. + /// + public double Bias { get; set; } + + /// + /// Gets or sets the scaling factor to apply to the output value from the source module. + /// + public double Scale { get; set; } + #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); + return Modules[0].GetValue(x, y, z) * Scale + Bias; + } + + #endregion + } } \ No newline at end of file