private int GetSeed(NoiseConfiguration config) { if (Seeds.TryGetValue(config.Seed, out int value)) { return(value); } else { Seeds.Add(config.Seed, (int)Math.Sqrt(Math.Abs(13 * config.Seed * config.Seed))); return(GetSeed(config)); } }
public float[][] GetNoiseValues(NoiseConfiguration config, double zoom, Area area, double maxDistanceInMeters, int imageWidth, int imageHeight) { if (imageWidth == 0 || imageHeight == 0) { return(null); } //float factor = Math.Max(imageWidth / 256f, imageHeight / 256f); float factor = 1; int calcWidth = (int)(imageWidth / factor); int calcHeight = (int)(imageHeight / factor); float[][] result = new float[calcWidth][]; for (int i = 0; i < result.Length; i++) { result[i] = new float[calcHeight]; } FastNoise noiseGenerator = new FastNoise(GetSeed(config)); double xMovementPerPixel = (area.XEnd - area.XStart) / calcWidth; double yMovementPerPixel = (area.YEnd - area.YStart) / calcHeight; //Optimisation possibility: we don't have to calculate haversine for each pixel. //Calculate the rectangle that needs to be calculated and set all the other cells to //Color.FromArgb(0, 0, 0, 0) //i.e. start in the middle and move to the right and left. Stop calculating when the calculationborder is reached bool allPointsIncluded = maxDistanceInMeters == 0 || WSG84Math.GetDistanceInMeters(area.Center, area.TopLeftCorner) < maxDistanceInMeters; for (int x = 0; x < calcWidth; x++) { for (int y = 0; y < calcHeight; y++) { double pixelX = area.XStart + xMovementPerPixel * x; double pixelY = area.YStart + yMovementPerPixel * y; result[x][y] = 0; if (allPointsIncluded || WSG84Math.GetDistanceInMeters(pixelY, pixelX, area.YCenter, area.XCenter) < maxDistanceInMeters) { result[x][y] = GetValue(noiseGenerator, (NoiseType)config.Type, pixelX * zoom, pixelY * zoom); } } } return(result); }
public float GetNoiseValue(NoiseConfiguration config, double zoom, double latitude, double longitude) { FastNoise noiseGenerator = new FastNoise(GetSeed(config)); return(GetValue(noiseGenerator, (NoiseType)config.Type, longitude * zoom, latitude * zoom)); }