Skip to content

Commit 2f00e21

Browse files
sync stuff again
1 parent 55dd691 commit 2f00e21

11 files changed

Lines changed: 667 additions & 157 deletions

‎Imaging.Texture/NoiseGenerator.cs‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,32 @@ public sealed class NoiseGenerator
3636
/// </summary>
3737
/// <param name="width">The width of the noise map.</param>
3838
/// <param name="height">The height of the noise map.</param>
39-
public NoiseGenerator(int width, int height)
39+
public NoiseGenerator(int width, int height) : this(width, height, null)
40+
{
41+
}
42+
43+
/// <summary>
44+
/// Initializes a new instance of the <see cref="NoiseGenerator" /> class with a deterministic seed.
45+
/// The same seed and size always produce the same noise map, which is what texture variants rely on.
46+
/// </summary>
47+
/// <param name="width">The width of the noise map.</param>
48+
/// <param name="height">The height of the noise map.</param>
49+
/// <param name="seed">Seed for the random source. <c>null</c> keeps the legacy non-deterministic behavior.</param>
50+
public NoiseGenerator(int width, int height, int? seed)
4051
{
4152
_width = width;
4253
_height = height;
43-
_noise = GenerateNoise();
54+
_noise = GenerateNoise(seed);
4455
}
4556

4657
/// <summary>
4758
/// Generates a 2D array filled with random noise values between 0 and 1.
4859
/// </summary>
4960
/// <returns>A 2D array representing the noise map.</returns>
50-
private double[,] GenerateNoise()
61+
/// <param name="seed">Optional deterministic seed.</param>
62+
private double[,] GenerateNoise(int? seed)
5163
{
52-
var rand = new Random();
64+
var rand = seed.HasValue ? new Random(seed.Value) : new Random();
5365
var noiseData = new double[_height, _width];
5466

5567
for (var y = 0; y < _height; y++)

‎Imaging.Texture/TextureConfig.cs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ public sealed class TextureConfig
9696
/// Defines how many cells across the texture will contain a stone center.
9797
/// A higher number means smaller, more densely packed stones.
9898
/// </summary>
99+
/// <value>
100+
/// The size of the voronoi grid.
101+
/// </value>
99102
public int VoronoiGridSize { get; init; } = 4; // Default to 4
100103
}
101104
}

0 commit comments

Comments
 (0)