diff --git a/CubicNoise/Builders/NoiseBuilder.cs b/CubicNoise/Builders/NoiseBuilder.cs new file mode 100644 index 0000000..62ff9b4 --- /dev/null +++ b/CubicNoise/Builders/NoiseBuilder.cs @@ -0,0 +1,49 @@ +using System; +using System.Collections.Generic; +using System.Text; +using CubicNoise.Contracts; + +namespace CubicNoise.Builders +{ + public sealed class NoiseBuilder + { + public NoiseTypes NoiseType { get; set; } = NoiseTypes.UNKNOWN; + + public int NoiseSeed { get; set; } = new Random().Next(); + + public Dictionary NoiseIntParameters = new Dictionary(); + + private NoiseBuilder() + { + } + + public static NoiseBuilder New() + { + return new NoiseBuilder(); + } + + public NoiseBuilder Type(NoiseTypes type) + { + this.NoiseType = type; + return this; + } + + public NoiseBuilder Seed(int seed) + { + this.NoiseSeed = seed; + return this; + } + + public NoiseBuilder Seed(string seed) + { + this.NoiseSeed = seed.GetHashCode(); + return this; + } + + public NoiseBuilder SetParam(IParameterName param, int value) + { + this.NoiseIntParameters[param] = value; + return this; + } + } +} diff --git a/CubicNoise/Builders/Parameters.cs b/CubicNoise/Builders/Parameters.cs new file mode 100644 index 0000000..593a55c --- /dev/null +++ b/CubicNoise/Builders/Parameters.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; +using CubicNoise.Noisers; + +namespace CubicNoise.Builders +{ + public sealed class Parameters + { + private Parameters() + { + } + + public static CubicNoiseParameterKinds Cubic(CubicNoiseParameterKinds kind) + { + return kind; + } + } +} diff --git a/CubicNoise/Contracts/INoiseEngine.cs b/CubicNoise/Contracts/INoiseEngine.cs new file mode 100644 index 0000000..40e2943 --- /dev/null +++ b/CubicNoise/Contracts/INoiseEngine.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CubicNoise.Contracts +{ + public interface INoiseEngine + { + float Get(float x); + + float Get(float x, float y); + } +} diff --git a/CubicNoise/Contracts/IParameterName.cs b/CubicNoise/Contracts/IParameterName.cs new file mode 100644 index 0000000..6c7398f --- /dev/null +++ b/CubicNoise/Contracts/IParameterName.cs @@ -0,0 +1,6 @@ +namespace CubicNoise.Contracts +{ + public interface IParameterName + { + } +} diff --git a/CubicNoise/Extensions.cs b/CubicNoise/Extensions.cs new file mode 100644 index 0000000..007cadf --- /dev/null +++ b/CubicNoise/Extensions.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; +using CubicNoise.Noisers; + +namespace CubicNoise +{ + public static class Extensions + { + + } +} diff --git a/CubicNoise/NoiseEngine.cs b/CubicNoise/NoiseEngine.cs new file mode 100644 index 0000000..add8248 --- /dev/null +++ b/CubicNoise/NoiseEngine.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Text; +using CubicNoise.Builders; +using CubicNoise.Contracts; +using CubicNoise.Noisers; + +namespace CubicNoise +{ + public sealed class NoiseEngine : INoiseEngine + { + private readonly INoiseEngine engine; + + private NoiseEngine(NoiseTypes type, int seed, Dictionary intParameters) + { + this.engine = type switch + { + NoiseTypes.UNKNOWN => new RandomNumberEngine(seed), + + NoiseTypes.CUBIC_NOISE => new CubicNoiseEngine(seed, intParameters), + + _ => throw new ArgumentOutOfRangeException(nameof(type), type, "The provided noise type is unknown.") + }; + } + + public static NoiseEngine CreateEngine(NoiseBuilder builder) => new NoiseEngine(builder.NoiseType, builder.NoiseSeed, builder.NoiseIntParameters); + + public float Get(float x) => this.engine.Get(x); + + public float Get(float x, float y) => this.engine.Get(x, y); + } +} diff --git a/CubicNoise/NoiseTypes.cs b/CubicNoise/NoiseTypes.cs new file mode 100644 index 0000000..0306436 --- /dev/null +++ b/CubicNoise/NoiseTypes.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CubicNoise +{ + public enum NoiseTypes + { + UNKNOWN = 0, + CUBIC_NOISE = 1_000, + } +} diff --git a/CubicNoise/Noisers/CubicNoiseEngine.cs b/CubicNoise/Noisers/CubicNoiseEngine.cs new file mode 100644 index 0000000..4ad1199 --- /dev/null +++ b/CubicNoise/Noisers/CubicNoiseEngine.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Text; +using CubicNoise.Contracts; + +namespace CubicNoise.Noisers +{ + public sealed class CubicNoiseEngine : INoiseEngine + { + private Dictionary intParameters; + private int seed; + + public CubicNoiseEngine(int seed, Dictionary intParameters) + { + this.intParameters = intParameters; + this.seed = seed; + } + + public float Get(float x) + { + throw new NotImplementedException(); + } + + public float Get(float x, float y) + { + throw new NotImplementedException(); + } + } +} diff --git a/CubicNoise/Noisers/CubicNoiseIntParameters.cs b/CubicNoise/Noisers/CubicNoiseIntParameters.cs new file mode 100644 index 0000000..73f8de9 --- /dev/null +++ b/CubicNoise/Noisers/CubicNoiseIntParameters.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; +using CubicNoise.Builders; +using CubicNoise.Contracts; + +namespace CubicNoise.Noisers +{ + public class CubicNoiseIntParameters : IParameterName + { + public static readonly IParameterName OCTAVE = new CubicNoiseIntParameters(); + public static readonly IParameterName PERIOD_X = new CubicNoiseIntParameters(); + public static readonly IParameterName PERIOD_Y = new CubicNoiseIntParameters(); + + private CubicNoiseIntParameters() + { + } + } +} diff --git a/CubicNoise/Noisers/CubicNoiseParameterKinds.cs b/CubicNoise/Noisers/CubicNoiseParameterKinds.cs new file mode 100644 index 0000000..deeedb1 --- /dev/null +++ b/CubicNoise/Noisers/CubicNoiseParameterKinds.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Dynamic; +using System.Text; +using CubicNoise.Builders; +using CubicNoise.Contracts; + +namespace CubicNoise.Noisers +{ + public sealed class CubicNoiseParameterKinds + { + private CubicNoiseParameterKinds() + { + } + + public static CubicNoiseParameterKinds Int { get; } = new CubicNoiseParameterKinds(); + + public IParameterName Use(CubicNoiseIntParameters name) => name; + } +} diff --git a/CubicNoise/Noisers/RandomNumberEngine.cs b/CubicNoise/Noisers/RandomNumberEngine.cs new file mode 100644 index 0000000..3e8afca --- /dev/null +++ b/CubicNoise/Noisers/RandomNumberEngine.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Text; +using CubicNoise.Contracts; + +namespace CubicNoise.Noisers +{ + public sealed class RandomNumberEngine : INoiseEngine + { + private Random rng; + + public RandomNumberEngine(int seed) + { + this.rng = new Random(seed); + } + + public float Get(float x) + { + return this.rng.Next(); + } + + public float Get(float x, float y) + { + return this.rng.Next(); + } + } +} diff --git a/CubicNoiseTests/NoiseBuilderTests.cs b/CubicNoiseTests/NoiseBuilderTests.cs new file mode 100644 index 0000000..075f7de --- /dev/null +++ b/CubicNoiseTests/NoiseBuilderTests.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; +using CubicNoise; +using CubicNoise.Builders; +using CubicNoise.Noisers; +using NUnit.Framework; + +namespace CubicNoiseTests +{ + public class NoiseBuilderTests + { + [Test] + public void SimpleBuild() + { + var engine = NoiseEngine.CreateEngine(NoiseBuilder.New().Type(NoiseTypes.CUBIC_NOISE).Seed("test seed").SetParam(Parameters.Cubic(CubicNoiseParameterKinds.Int.Use(CubicNoiseIntParameters.OCTAVE)))) + } + } +}