(client) chore:Clean code
This commit is contained in:
@ -2,20 +2,18 @@ using System;
|
||||
|
||||
namespace Utils
|
||||
{
|
||||
public class PerlinNoise : Utils.Singleton<PerlinNoise>
|
||||
public class PerlinNoise : Singleton<PerlinNoise>
|
||||
{
|
||||
private int[] _p; // 混淆表
|
||||
private const int DefaultSeed = 0; // 默认种子
|
||||
private readonly int[] _p = new int[512]; // 混淆表
|
||||
|
||||
public PerlinNoise()
|
||||
{
|
||||
Initialize(DefaultSeed);
|
||||
Initialize();
|
||||
}
|
||||
|
||||
// 初始化混淆表
|
||||
private void Initialize(int seed)
|
||||
private void Initialize(int seed = 0)
|
||||
{
|
||||
_p = new int[512]; // 混淆表加倍以方便使用
|
||||
var permutation = new int[256];
|
||||
var random = new Random(seed);
|
||||
|
||||
@ -26,9 +24,8 @@ namespace Utils
|
||||
for (var i = 0; i < 256; i++)
|
||||
{
|
||||
var swapIndex = random.Next(256);
|
||||
var temp = permutation[i];
|
||||
permutation[i] = permutation[swapIndex];
|
||||
permutation[swapIndex] = temp;
|
||||
|
||||
(permutation[i], permutation[swapIndex]) = (permutation[swapIndex], permutation[i]);
|
||||
}
|
||||
|
||||
// 将打乱后的数组复制两次,生成512个元素的混淆表
|
||||
@ -86,7 +83,7 @@ namespace Utils
|
||||
/// 为给定的(x, y, z)坐标生成3D Perlin噪声。
|
||||
/// 输出值通常在-1到1之间。
|
||||
/// </summary>
|
||||
public double Noise(double x, double y=0, double z = 0)
|
||||
public double Noise(double x, double y = 0, double z = 0)
|
||||
{
|
||||
var X = (int)Math.Floor(x) & 255;
|
||||
var Y = (int)Math.Floor(y) & 255;
|
||||
|
Reference in New Issue
Block a user