001// This file was originally from https://github.com/Auburns/FastNoise_Java as:
002// FastNoise.java
003//
004// MIT License
005//
006// Copyright(c) 2017 Jordan Peck
007//
008// Permission is hereby granted, free of charge, to any person obtaining a copy
009// of this software and associated documentation files(the "Software"), to deal
010// in the Software without restriction, including without limitation the rights
011// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
012// copies of the Software, and to permit persons to whom the Software is
013// furnished to do so, subject to the following conditions :
014//
015// The above copyright notice and this permission notice shall be included in all
016// copies or substantial portions of the Software.
017//
018// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
021// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
023// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
024// SOFTWARE.
025//
026// The developer's email is jorzixdan.me2@gzixmail.com (for great email, take
027// off every 'zix'.)
028//
029
030package squidpony.squidmath;
031
032import java.io.Serializable;
033
034/**
035 * A wide range of noise functions that can all be called from one configurable object. Originally from Jordan Peck's
036 * FastNoise library, hence the name (these functions are sometimes, but not always, very fast for noise that doesn't
037 * use the GPU). This implements Noise2D, Noise3D, Noise4D, and Noise6D, and this is the fastest continuous noise
038 * algorithm in the library. Though it doesn't implement an interface for them, you can also use this to get
039 * ridged-multi simplex noise (the same type as {@link Noise.Ridged2D}) with {@link #ridged2D(float, float, int, int)},
040 * {@link #ridged3D(float, float, float, int, int)}, or any of the overloads that allow specifying alternate lacunarity
041 * and gain.
042 */
043public class FastNoise implements Serializable, Noise.Noise2D, Noise.Noise3D, Noise.Noise4D, Noise.Noise6D {
044    private static final long serialVersionUID = 3L;
045    public static final int VALUE = 0, VALUE_FRACTAL = 1, PERLIN = 2, PERLIN_FRACTAL = 3,
046            SIMPLEX = 4, SIMPLEX_FRACTAL = 5, CELLULAR = 6, WHITE_NOISE = 7, CUBIC = 8, CUBIC_FRACTAL = 9, 
047            FOAM = 10, FOAM_FRACTAL = 11;
048
049    public static final int LINEAR = 0, HERMITE = 1, QUINTIC = 2;
050
051    public static final int FBM = 0, BILLOW = 1, RIDGED_MULTI = 2;
052
053    public static final int EUCLIDEAN = 0, MANHATTAN = 1, NATURAL = 2;
054
055    public static final int CELL_VALUE = 0, NOISE_LOOKUP = 1, DISTANCE = 2, DISTANCE_2 = 3,
056            DISTANCE_2_ADD = 4, DISTANCE_2_SUB = 5, DISTANCE_2_MUL = 6, DISTANCE_2_DIV = 7;
057
058    private int seed;
059    private float frequency = 0.03125f;
060    private int interpolation = HERMITE;
061    private int noiseType = SIMPLEX_FRACTAL;
062
063    private int octaves = 1;
064    private float lacunarity = 2f;
065    private float gain = 0.5f;
066    private int fractalType = FBM;
067
068    private float fractalBounding;
069
070    private int cellularDistanceFunction = EUCLIDEAN;
071    private int cellularReturnType = CELL_VALUE;
072    private FastNoise cellularNoiseLookup;
073    private IPointHash pointHash = new IntPointHash();
074
075    private float gradientPerturbAmp = 1f / 0.45f;
076
077    /**
078     * A publicly available FastNoise object with seed 1337, frequency 1.0f/32.0f, 1 octave of Simplex noise using
079     * SIMPLEX_FRACTAL noiseType, 2f lacunarity and 0.5f gain. It's encouraged to use methods that temporarily configure
080     * this variable, like {@link #getNoiseWithSeed(float, float, int)} rather than changing its settings and using a
081     * method that needs that lasting configuration, like {@link #getConfiguredNoise(float, float)}.
082     */
083    public static final FastNoise instance = new FastNoise();
084    /**
085     * A constructor that takes no parameters, and uses all default settings with a seed of 1337. An example call to
086     * this would be {@code new FastNoise()}, which makes noise with the seed 1337, a default frequency of 1.0f/32.0f, 1
087     * octave of Simplex noise (since this doesn't specify octave count, it always uses 1 even for the 
088     * SIMPLEX_FRACTAL noiseType this uses, but you can call {@link #setFractalOctaves(int)} later to benefit from the
089     * fractal noiseType), and normal lacunarity and gain (when unspecified, they are 2f and 0.5f).
090     */
091    public FastNoise() {
092        this(1337);
093    }
094
095    /**
096     * A constructor that takes only a parameter for the FastNoise's seed, which should produce different results for
097     * any different seeds. An example call to this would be {@code new FastNoise(1337)}, which makes noise with the
098     * seed 1337, a default frequency of 1.0f/32.0f, 1 octave of Simplex noise (since this doesn't specify octave count,
099     * it always uses 1 even for the SIMPLEX_FRACTAL noiseType this uses, but you can call
100     * {@link #setFractalOctaves(int)} later to benefit from the fractal noiseType), and normal lacunarity and gain
101     * (when unspecified, they are 2f and 0.5f).
102     * @param seed the int seed for the noise, which should significantly affect the produced noise
103     */
104    public FastNoise(int seed) {
105        this.seed = seed;
106        calculateFractalBounding();
107    }
108    /**
109     * A constructor that takes two parameters to specify the FastNoise from the start. An example call to this
110     * would be {@code new FastNoise(1337, 0.02f)}, which makes noise with the seed 1337, a lower
111     * frequency, 1 octave of Simplex noise (since this doesn't specify octave count, it always uses 1 even for the 
112     * SIMPLEX_FRACTAL noiseType this uses, but you can call {@link #setFractalOctaves(int)} later to benefit from the
113     * fractal noiseType), and normal lacunarity and gain (when unspecified, they are 2f and 0.5f).
114     * @param seed the int seed for the noise, which should significantly affect the produced noise
115     * @param frequency the multiplier for all dimensions, which is usually fairly small (1.0f/32.0f is the default)
116     */
117    public FastNoise(int seed, float frequency)
118    {
119        this(seed, frequency, SIMPLEX_FRACTAL, 1, 2f, 0.5f);
120    }
121    /**
122     * A constructor that takes a few parameters to specify the FastNoise from the start. An example call to this
123     * would be {@code new FastNoise(1337, 0.02f, FastNoise.SIMPLEX)}, which makes noise with the seed 1337, a lower
124     * frequency, 1 octave of Simplex noise (since this doesn't specify octave count, it always uses 1 even for 
125     * noiseTypes like SIMPLEX_FRACTAL, but using a fractal noiseType can make sense if you call
126     * {@link #setFractalOctaves(int)} later), and normal lacunarity and gain (when unspecified, they are 2f and 0.5f).
127     * @param seed the int seed for the noise, which should significantly affect the produced noise
128     * @param frequency the multiplier for all dimensions, which is usually fairly small (1.0f/32.0f is the default)
129     * @param noiseType the noiseType, which should be a constant from this class (see {@link #setNoiseType(int)})
130     */
131    public FastNoise(int seed, float frequency, int noiseType)
132    {
133        this(seed, frequency, noiseType, 1, 2f, 0.5f);
134    }
135
136    /**
137     * A constructor that takes several parameters to specify the FastNoise from the start. An example call to this
138     * would be {@code new FastNoise(1337, 0.02f, FastNoise.SIMPLEX_FRACTAL, 4)}, which makes noise with the seed 1337, a lower
139     * frequency, 4 octaves of Simplex noise, and normal lacunarity and gain (when unspecified, they are 2f and 0.5f).
140     * @param seed the int seed for the noise, which should significantly affect the produced noise
141     * @param frequency the multiplier for all dimensions, which is usually fairly small (1.0f/32.0f is the default)
142     * @param noiseType the noiseType, which should be a constant from this class (see {@link #setNoiseType(int)})
143     * @param octaves how many octaves of noise to use when the noiseType is one of the _FRACTAL types
144     */
145    public FastNoise(int seed, float frequency, int noiseType, int octaves)
146    {
147        this(seed, frequency, noiseType, octaves, 2f, 0.5f);
148    }
149
150    /**
151     * A constructor that takes a lot of parameters to specify the FastNoise from the start. An example call to this
152     * would be {@code new FastNoise(1337, 0.02f, FastNoise.SIMPLEX_FRACTAL, 4, 0.5f, 2f)}, which makes noise with a
153     * lower frequency, 4 octaves of Simplex noise, and the "inverse" effect on how those octaves work (which makes
154     * the extra added octaves be more significant to the final result and also have a lower frequency, while normally
155     * added octaves have a higher frequency and tend to have a minor effect on the large-scale shape of the noise).
156     * @param seed the int seed for the noise, which should significantly affect the produced noise
157     * @param frequency the multiplier for all dimensions, which is usually fairly small (1.0f/32.0f is the default)
158     * @param noiseType the noiseType, which should be a constant from this class (see {@link #setNoiseType(int)})
159     * @param octaves how many octaves of noise to use when the noiseType is one of the _FRACTAL types
160     * @param lacunarity typically 2.0, or 0.5 to change how extra octaves work (inverse mode) 
161     * @param gain typically 0.5, or 2.0 to change how extra octaves work (inverse mode)
162     */
163    public FastNoise(int seed, float frequency, int noiseType, int octaves, float lacunarity, float gain)
164    {
165        this.seed = seed;
166        this.frequency = frequency;
167        this.noiseType = noiseType;
168        this.octaves = octaves;
169        this.lacunarity = lacunarity;
170        this.gain = gain;
171        calculateFractalBounding();
172    }
173
174    protected static float dotf(final float[] g, final float x, final float y) {
175        return g[0] * x + g[1] * y;
176    }
177
178    /**
179     * @return Returns the seed used by this object
180     */
181    public int getSeed() {
182        return seed;
183    }
184
185    /**
186     * Sets the seed used for all noise types, as a long.
187     * If this is not called, defaults to 1337L.
188     * @param seed a seed as a long
189     */
190    public void setSeed(int seed) {
191        this.seed = seed;
192    }
193
194    /**
195     * Sets the frequency for all noise types. If this is not called, it defaults to 0.03125f (or 1f/32f).
196     * @param frequency the frequency for all noise types, as a positive non-zero float
197     */
198    public void setFrequency(float frequency) {
199        this.frequency = frequency;
200    }
201
202    /**
203     * Gets the frequency for all noise types. The default is 0.03125f, or 1f/32f.
204     * @return the frequency for all noise types, which should be a positive non-zero float
205     */
206    public float getFrequency()
207    {
208        return frequency;
209    }
210
211    /**
212     * Changes the interpolation method used to smooth between noise values, using on of the following constants from
213     * this class (lowest to highest quality): {@link #LINEAR} (0), {@link #HERMITE} (1), or {@link #QUINTIC} (2). If
214     * this is not called, it defaults to HERMITE. This is used in Value, Gradient Noise and Position Perturbing.
215     * @param interpolation an int (0, 1, or 2) corresponding  to a constant from this class for an interpolation level
216     */
217    public void setInterpolation(int interpolation) {
218        this.interpolation = interpolation;
219    }
220
221    /**
222     * Sets the default type of noise returned by {@link #getConfiguredNoise(float, float)}, using one of the following constants
223     * in this class:
224     * {@link #VALUE} (0), {@link #VALUE_FRACTAL} (1), {@link #PERLIN} (2), {@link #PERLIN_FRACTAL} (3),
225     * {@link #SIMPLEX} (4), {@link #SIMPLEX_FRACTAL} (5), {@link #CELLULAR} (6), {@link #WHITE_NOISE} (7),
226     * {@link #CUBIC} (8), or {@link #CUBIC_FRACTAL} (9). If this isn't called, getConfiguredNoise() will default to SIMPLEX.
227     * @param noiseType an int from 0 to 9 corresponding to a constant from this class for a noise type
228     */
229    public void setNoiseType(int noiseType) {
230        this.noiseType = noiseType;
231    }
232
233    /**
234     * Gets the default type of noise returned by {@link #getConfiguredNoise(float, float)}, using one of the following constants
235     * in this class:
236     * {@link #VALUE} (0), {@link #VALUE_FRACTAL} (1), {@link #PERLIN} (2), {@link #PERLIN_FRACTAL} (3),
237     * {@link #SIMPLEX} (4), {@link #SIMPLEX_FRACTAL} (5), {@link #CELLULAR} (6), {@link #WHITE_NOISE} (7),
238     * {@link #CUBIC} (8), or {@link #CUBIC_FRACTAL} (9). The default is SIMPLEX.
239     * @return the noise type as a code, from 0 to 9 inclusive
240     */
241    public int getNoiseType()
242    {
243        return noiseType;
244    }
245
246    /**
247     * Sets the octave count for all fractal noise types.
248     * If this isn't called, it will default to 3.
249     * @param octaves the number of octaves to use for fractal noise types, as a positive non-zero int
250     */
251    public void setFractalOctaves(int octaves) {
252        this.octaves = octaves;
253        calculateFractalBounding();
254    }
255
256    /**
257     * Gets the octave count for all fractal noise types. The default is 3.
258     * @return the number of octaves to use for fractal noise types, as a positive non-zero int
259     */
260    public int getFractalOctaves()
261    {
262        return octaves;
263    }
264
265    /**
266     * Sets the octave lacunarity for all fractal noise types.
267     * Lacunarity is a multiplicative change to frequency between octaves. If this isn't called, it defaults to 2.
268     * @param lacunarity a non-0 float that will be used for the lacunarity of fractal noise types; commonly 2.0 or 0.5
269     */
270    public void setFractalLacunarity(float lacunarity) {
271        this.lacunarity = lacunarity;
272    }
273
274    /**
275     * Sets the octave gain for all fractal noise types.
276     * If this isn't called, it defaults to 0.5.
277     * @param gain the gain between octaves, as a float
278     */
279    public void setFractalGain(float gain) {
280        this.gain = gain;
281        calculateFractalBounding();
282    }
283
284    /**
285     * Sets the method for combining octaves in all fractal noise types, allowing an int argument corresponding to one
286     * of the following constants from this class: {@link #FBM} (0), {@link #BILLOW} (1), or {@link #RIDGED_MULTI} (2).
287     * If this hasn't been called, it will use FBM.
288     * @param fractalType an int (0, 1, or 2) that corresponds to a constant like {@link #FBM} or {@link #RIDGED_MULTI}
289     */
290    public void setFractalType(int fractalType) {
291        this.fractalType = fractalType;
292    }
293
294    /**
295     * Gets the method for combining octaves in all fractal noise types, allowing an int argument corresponding to one
296     * of the following constants from this class: {@link #FBM} (0), {@link #BILLOW} (1), or {@link #RIDGED_MULTI} (2).
297     * The default is FBM.     
298     * @return the fractal type as a code; 0, 1, or 2
299     */
300    public int getFractalType()
301    {
302        return fractalType;
303    }
304    /**
305     * Sets the distance function used in cellular noise calculations, allowing an int argument corresponding to one of
306     * the following constants from this class: {@link #EUCLIDEAN} (0), {@link #MANHATTAN} (1), or {@link #NATURAL} (2).
307     * If this hasn't been called, it will use EUCLIDEAN.
308     * @param cellularDistanceFunction an int that can be 0, 1, or 2, corresponding to a constant from this class
309     */
310    public void setCellularDistanceFunction(int cellularDistanceFunction) {
311        this.cellularDistanceFunction = cellularDistanceFunction;
312    }
313    // Sets
314    // Note: NoiseLookup requires another FastNoise object be set with setCellularNoiseLookup() to function
315    // Default: CellValue
316
317    /**
318     * Sets the return type from cellular noise calculations, allowing an int argument corresponding to one of the
319     * following constants from this class: {@link #CELL_VALUE} (0), {@link #NOISE_LOOKUP} (1), {@link #DISTANCE} (2),
320     * {@link #DISTANCE_2} (3), {@link #DISTANCE_2_ADD} (4), {@link #DISTANCE_2_SUB} (5), {@link #DISTANCE_2_MUL} (6),
321     * or {@link #DISTANCE_2_DIV} (7). If this isn't called, it will use CELL_VALUE.
322     * @param cellularReturnType
323     */
324    public void setCellularReturnType(int cellularReturnType) {
325        this.cellularReturnType = cellularReturnType;
326    }
327
328    // FastNoise used to calculate a cell value if cellular return type is NoiseLookup
329    // The lookup value is acquired through getConfiguredNoise() so ensure you setNoiseType() on the noise lookup, value, gradient or simplex is recommended
330
331    /**
332     * Sets the FastNoise used to calculate a cell value if cellular return type is {@link #NOISE_LOOKUP}.
333     * There is no default value; this must be called if using noise lookup to set the noise to a non-null value.
334     * The lookup value is acquired through getConfiguredNoise() so ensure you setNoiseType() on the noise lookup. Value, Foam, Perlin, or Simplex is recommended.
335     * @param noise another FastNoise object that should be configured already
336     */
337    public void setCellularNoiseLookup(FastNoise noise) {
338        cellularNoiseLookup = noise;
339    }
340
341    /**
342     * Sets the maximum perturb distance from original location when using {@link #gradientPerturb2(float[])},
343     * {@link #gradientPerturb3(float[])}, {@link #gradientPerturbFractal2(float[])}, or
344     * {@link #gradientPerturbFractal3(float[])}; the default is 1.0.
345     * @param gradientPerturbAmp the maximum perturb distance from the original location when using relevant methods
346     */
347    public void setGradientPerturbAmp(float gradientPerturbAmp) {
348        this.gradientPerturbAmp = gradientPerturbAmp / (float) 0.45;
349    }
350    
351    public void setPointHash(IPointHash hash){
352        if(hash != null) this.pointHash = hash;
353    }
354
355    private int hashAll(int x, int y, int s){
356        return pointHash.hashWithState(x, y, s);
357    }
358
359    private int hashAll(int x, int y, int z, int s){
360        return pointHash.hashWithState(x, y, z, s);
361    }
362
363    private int hashAll(int x, int y, int z, int w, int s){
364        return pointHash.hashWithState(x, y, z, w, s);
365    }
366
367    private int hashAll(int x, int y, int z, int w, int u, int v, int s){
368        return pointHash.hashWithState(x, y, z, w, u, v, s);
369    }
370
371    private int hash32(int x, int y, int s){
372        return pointHash.hashWithState(x, y, s) >>> 27;
373    }
374
375    private int hash32(int x, int y, int z, int s){
376        return pointHash.hashWithState(x, y, z, s) >>> 27;
377    }
378
379    private int hash32(int x, int y, int z, int w, int s){
380        return pointHash.hashWithState(x, y, z, w, s) >>> 27;
381    }
382
383    private int hash32(int x, int y, int z, int w, int u, int v, int s){
384        return pointHash.hashWithState(x, y, z, w, u, v, s) >>> 27;
385    }
386
387    private int hash256(int x, int y, int s){
388        return pointHash.hashWithState(x, y, s) >>> 24;
389    }
390
391    private int hash256(int x, int y, int z, int s){
392        return pointHash.hashWithState(x, y, z, s) >>> 24;
393    }
394
395    private int hash256(int x, int y, int z, int w, int s){
396        return pointHash.hashWithState(x, y, z, w, s) >>> 24;
397    }
398
399    private int hash256(int x, int y, int z, int w, int u, int v, int s){
400        return pointHash.hashWithState(x, y, z, w, u, v, s) >>> 24;
401    }
402
403    public double getNoise(double x, double y) {
404        return getConfiguredNoise((float)x, (float)y);
405    }
406
407    public double getNoiseWithSeed(double x, double y, long seed) {
408        int s = this.seed;
409        this.seed = (int) (seed ^ seed >>> 32);
410        double r = getConfiguredNoise((float)x, (float)y);
411        this.seed = s;
412        return r;
413    }
414
415    public double getNoise(double x, double y, double z) {
416        return getConfiguredNoise((float)x, (float)y, (float)z);
417    }
418
419    public double getNoiseWithSeed(double x, double y, double z, long seed) {
420        int s = this.seed;
421        this.seed = (int) (seed ^ seed >>> 32);
422        double r = getConfiguredNoise((float)x, (float)y, (float)z);
423        this.seed = s;
424        return r;
425    }
426
427    public double getNoise(double x, double y, double z, double w) {
428        return getConfiguredNoise((float)x, (float)y, (float)z, (float)w);
429    }
430
431    public double getNoiseWithSeed(double x, double y, double z, double w, long seed) {
432        int s = this.seed;
433        this.seed = (int) (seed ^ seed >>> 32);
434        double r = getConfiguredNoise((float)x, (float)y, (float)z, (float)w);
435        this.seed = s;
436        return r;
437    }
438
439    public double getNoise(double x, double y, double z, double w, double u, double v) {
440        return getConfiguredNoise((float)x, (float)y, (float)z, (float)w, (float)u, (float)v);
441    }
442
443    public double getNoiseWithSeed(double x, double y, double z, double w, double u, double v, long seed) {
444        int s = this.seed;
445        this.seed = (int) (seed ^ seed >>> 32);
446        double r = getConfiguredNoise((float)x, (float)y, (float)z, (float)w, (float)u, (float)v);
447        this.seed = s;
448        return r;
449    }
450
451
452    public float getNoiseWithSeed(float x, float y, int seed) {
453        final int s = this.seed;
454        this.seed = seed;
455        float r = getConfiguredNoise(x, y);
456        this.seed = s;
457        return r;
458    }
459    public float getNoiseWithSeed(float x, float y, float z, int seed) {
460        final int s = this.seed;
461        this.seed = seed;
462        float r = getConfiguredNoise(x, y, z);
463        this.seed = s;
464        return r;
465    }
466    public float getNoiseWithSeed(float x, float y, float z, float w, int seed) {
467        final int s = this.seed;
468        this.seed = seed;
469        float r = getConfiguredNoise(x, y, z, w);
470        this.seed = s;
471        return r;
472    }
473
474    public float getNoiseWithSeed(float x, float y, float z, float w, float u, float v, int seed) {
475        final int s = this.seed;
476        this.seed = seed;
477        float r = getConfiguredNoise(x, y, z, w, u, v);
478        this.seed = s;
479        return r;
480    }
481
482    private static int fastFloor(float f) {
483        return (f >= 0 ? (int) f : (int) f - 1);
484    }
485
486
487    private static int fastRound(float f) {
488        return (f >= 0) ? (int) (f + 0.5f) : (int) (f - 0.5f);
489    }
490
491
492    private static float lerp(float a, float b, float t) {
493        return a + t * (b - a);
494    }
495
496
497    private static float hermiteInterpolator(float t) {
498        return t * t * (3 - 2 * t);
499    }
500
501
502    private static float quinticInterpolator(float t) {
503        return t * t * t * (t * (t * 6 - 15) + 10);
504    }
505
506
507    private static float cubicLerp(float a, float b, float c, float d, float t) {
508        float p = (d - c) - (a - b);
509        return t * (t * t * p + t * ((a - b) - p) + (c - a)) + b;
510    }
511
512    private void calculateFractalBounding() {
513        float amp = gain;
514        float ampFractal = 1;
515        for (int i = 1; i < octaves; i++) {
516            ampFractal += amp;
517            amp *= gain;
518        }
519        fractalBounding = 1 / ampFractal;
520    }
521
522    private float valCoord2D(int seed, int x, int y) {
523        return (hashAll(x, y, seed) >> 7) * 0x1.0p-24f;
524    }
525
526    private float valCoord3D(int seed, int x, int y, int z) {
527        return (hashAll(x, y, z, seed) >> 7) * 0x1.0p-24f;
528    }
529
530    private float valCoord4D(int seed, int x, int y, int z, int w) {
531        return (hashAll(x, y, z, w, seed) >> 7) * 0x1.0p-24f;
532    }
533
534    private float valCoord6D(int seed, int x, int y, int z, int w, int u, int v) {
535        return (hashAll(x, y, z, w, u, v, seed) >> 7) * 0x1.0p-24f;
536    }
537
538    protected float gradCoord2D(int seed, int x, int y, float xd, float yd) {
539        final float[] g = phiGrad2f[hash256(x, y, seed)];
540        return xd * g[0] + yd * g[1];
541    }
542
543    protected float gradCoord3D(int seed, int x, int y, int z, float xd, float yd, float zd) {
544        final Float3 g = GRAD_3D[hash32(x, y, z, seed)];
545        return xd * g.x + yd * g.y + zd * g.z;
546    }
547
548    protected float gradCoord4D(int seed, int x, int y, int z, int w, float xd, float yd, float zd, float wd) {
549        final int hash = hash256(x, y, z, w, seed) & 0xFC;
550        return xd * grad4f[hash] + yd * grad4f[hash + 1] + zd * grad4f[hash + 2] + wd * grad4f[hash + 3];
551    }
552
553    protected float gradCoord6D(int seed, int x, int y, int z, int w, int u, int v,
554                                       float xd, float yd, float zd, float wd, float ud, float vd) {
555        final int hash = hash256(x, y, z, w, u, v, seed) * 6;
556        return xd * grad6f[hash] + yd * grad6f[hash + 1] + zd * grad6f[hash + 2]
557                + wd * grad6f[hash + 3] + ud * grad6f[hash + 4] + vd * grad6f[hash + 5];
558    }
559
560
561    /**
562     * After being configured with the setters in this class, such as {@link #setNoiseType(int)},
563     * {@link #setFrequency(float)}, {@link #setFractalOctaves(int)}, and {@link #setFractalType(int)}, among others,
564     * you can call this method to get the particular variety of noise you specified, in 2D.
565     * @param x
566     * @param y
567     * @return noise as a float from -1f to 1f
568     */
569    public float getConfiguredNoise(float x, float y) {
570        x *= frequency;
571        y *= frequency;
572
573        switch (noiseType) {
574            case VALUE:
575                return singleValue(seed, x, y);
576            case VALUE_FRACTAL:
577                switch (fractalType) {
578                    case BILLOW:
579                        return singleValueFractalBillow(x, y);
580                    case RIDGED_MULTI:
581                        return singleValueFractalRidgedMulti(x, y);
582                    default:
583                        return singleValueFractalFBM(x, y);
584                }
585            case FOAM:
586                return singleFoam(seed, x, y);
587            case FOAM_FRACTAL:
588                switch (fractalType) {
589                    case BILLOW:
590                        return singleFoamFractalBillow(x, y);
591                    case RIDGED_MULTI:
592                        return singleFoamFractalRidgedMulti(x, y);
593                    default:
594                        return singleFoamFractalFBM(x, y);
595                }
596            case PERLIN:
597                return singlePerlin(seed, x, y);
598            case PERLIN_FRACTAL:
599                switch (fractalType) {
600                    case BILLOW:
601                        return singlePerlinFractalBillow(x, y);
602                    case RIDGED_MULTI:
603                        return singlePerlinFractalRidgedMulti(x, y);
604                    default:
605                        return singlePerlinFractalFBM(x, y);
606                }
607            case SIMPLEX_FRACTAL:
608                switch (fractalType) {
609                    case BILLOW:
610                        return singleSimplexFractalBillow(x, y);
611                    case RIDGED_MULTI:
612                        return singleSimplexFractalRidgedMulti(x, y);
613                    default:
614                        return singleSimplexFractalFBM(x, y);
615                }
616            case CELLULAR:
617                switch (cellularReturnType) {
618                    case CELL_VALUE:
619                    case NOISE_LOOKUP:
620                    case DISTANCE:
621                        return singleCellular(x, y);
622                    default:
623                        return singleCellular2Edge(x, y);
624                }
625            case WHITE_NOISE:
626                return getWhiteNoise(x, y);
627            case CUBIC:
628                return singleCubic(seed, x, y);
629            case CUBIC_FRACTAL:
630                switch (fractalType) {
631                    case BILLOW:
632                        return singleCubicFractalBillow(x, y);
633                    case RIDGED_MULTI:
634                        return singleCubicFractalRidgedMulti(x, y);
635                    default:
636                        return singleCubicFractalFBM(x, y);
637                }
638            default:
639                return singleSimplex(seed, x, y);
640        }
641    }
642
643    /**
644     * After being configured with the setters in this class, such as {@link #setNoiseType(int)},
645     * {@link #setFrequency(float)}, {@link #setFractalOctaves(int)}, and {@link #setFractalType(int)}, among others,
646     * you can call this method to get the particular variety of noise you specified, in 3D.
647     * @param x
648     * @param y
649     * @param z
650     * @return noise as a float from -1f to 1f
651     */
652    public float getConfiguredNoise(float x, float y, float z) {
653        x *= frequency;
654        y *= frequency;
655        z *= frequency;
656
657        switch (noiseType) {
658            case VALUE:
659                return singleValue(seed, x, y, z);
660            case VALUE_FRACTAL:
661                switch (fractalType) {
662                    case BILLOW:
663                        return singleValueFractalBillow(x, y, z);
664                    case RIDGED_MULTI:
665                        return singleValueFractalRidgedMulti(x, y, z);
666                    default:
667                        return singleValueFractalFBM(x, y, z);
668                }
669            case FOAM:
670                return singleFoam(seed, x, y, z);
671            case FOAM_FRACTAL:
672                switch (fractalType) {
673                    case BILLOW:
674                        return singleFoamFractalBillow(x, y, z);
675                    case RIDGED_MULTI:
676                        return singleFoamFractalRidgedMulti(x, y, z);
677                    default:
678                        return singleFoamFractalFBM(x, y, z);
679                }
680            case PERLIN:
681                return singlePerlin(seed, x, y, z);
682            case PERLIN_FRACTAL:
683                switch (fractalType) {
684                    case BILLOW:
685                        return singlePerlinFractalBillow(x, y, z);
686                    case RIDGED_MULTI:
687                        return singlePerlinFractalRidgedMulti(x, y, z);
688                    default:
689                        return singlePerlinFractalFBM(x, y, z);
690                }
691            case SIMPLEX_FRACTAL:
692                switch (fractalType) {
693                    case BILLOW:
694                        return singleSimplexFractalBillow(x, y, z);
695                    case RIDGED_MULTI:
696                        return singleSimplexFractalRidgedMulti(x, y, z);
697                    default:
698                        return singleSimplexFractalFBM(x, y, z);
699                }
700            case CELLULAR:
701                switch (cellularReturnType) {
702                    case CELL_VALUE:
703                    case NOISE_LOOKUP:
704                    case DISTANCE:
705                        return singleCellular(x, y, z);
706                    default:
707                        return singleCellular2Edge(x, y, z);
708                }
709            case WHITE_NOISE:
710                return getWhiteNoise(x, y, z);
711            case CUBIC:
712                return singleCubic(seed, x, y, z);
713            case CUBIC_FRACTAL:
714                switch (fractalType) {
715                    case BILLOW:
716                        return singleCubicFractalBillow(x, y, z);
717                    case RIDGED_MULTI:
718                        return singleCubicFractalRidgedMulti(x, y, z);
719                    default:
720                        return singleCubicFractalFBM(x, y, z);
721                }
722            default:
723                return singleSimplex(seed, x, y, z);
724        }
725    }
726    /**
727     * After being configured with the setters in this class, such as {@link #setNoiseType(int)},
728     * {@link #setFrequency(float)}, {@link #setFractalOctaves(int)}, and {@link #setFractalType(int)}, among others,
729     * you can call this method to get the particular variety of noise you specified, in 3D.
730     * @param x
731     * @param y
732     * @param z
733     * @param w
734     * @return noise as a float from -1f to 1f
735     */
736    public float getConfiguredNoise(float x, float y, float z, float w) {
737        x *= frequency;
738        y *= frequency;
739        z *= frequency;
740        w *= frequency;
741
742        switch (noiseType) {
743            case VALUE:
744                return singleValue(seed, x, y, z, w);
745            case VALUE_FRACTAL:
746                switch (fractalType) {
747                    case BILLOW:
748                        return singleValueFractalBillow(x, y, z, w);
749                    case RIDGED_MULTI:
750                        return singleValueFractalRidgedMulti(x, y, z, w);
751                    default:
752                        return singleValueFractalFBM(x, y, z, w);
753                }
754            case FOAM:
755                return singleFoam(seed, x, y, z, w);
756            case FOAM_FRACTAL:
757                switch (fractalType) {
758                    case BILLOW:
759                        return singleFoamFractalBillow(x, y, z, w);
760                    case RIDGED_MULTI:
761                        return singleFoamFractalRidgedMulti(x, y, z, w);
762                    default:
763                        return singleFoamFractalFBM(x, y, z, w);
764                }
765            case PERLIN:
766                return singlePerlin(seed, x, y, z, w);
767            case PERLIN_FRACTAL:
768                switch (fractalType) {
769                    case BILLOW:
770                        return singlePerlinFractalBillow(x, y, z, w);
771                    case RIDGED_MULTI:
772                        return singlePerlinFractalRidgedMulti(x, y, z, w);
773                    default:
774                        return singlePerlinFractalFBM(x, y, z, w);
775                }
776            case SIMPLEX_FRACTAL:
777                switch (fractalType) {
778                    case BILLOW:
779                        return singleSimplexFractalBillow(x, y, z, w);
780                    case RIDGED_MULTI:
781                        return singleSimplexFractalRidgedMulti(x, y, z, w);
782                    default:
783                        return singleSimplexFractalFBM(x, y, z, w);
784                }
785//            case CELLULAR:
786//                switch (cellularReturnType) {
787//                    case CELL_VALUE:
788//                    case NOISE_LOOKUP:
789//                    case DISTANCE:
790//                        return singleCellular(x, y, z);
791//                    default:
792//                        return singleCellular2Edge(x, y, z);
793//                }
794            case WHITE_NOISE:
795                return getWhiteNoise(x, y, z, w);
796            default:
797                return singleSimplex(seed, x, y, z, w);
798        }
799    }
800
801    /**
802     * After being configured with the setters in this class, such as {@link #setNoiseType(int)},
803     * {@link #setFrequency(float)}, {@link #setFractalOctaves(int)}, and {@link #setFractalType(int)}, among others,
804     * you can call this method to get the particular variety of noise you specified, in 3D.
805     * @param x
806     * @param y
807     * @param z
808     * @param w
809     * @param u
810     * @param v
811     * @return noise as a float from -1f to 1f
812     */
813    public float getConfiguredNoise(float x, float y, float z, float w, float u, float v) {
814        x *= frequency;
815        y *= frequency;
816        z *= frequency;
817        w *= frequency;
818        u *= frequency;
819        v *= frequency;
820
821        switch (noiseType) {
822            case VALUE:
823                return singleValue(seed, x, y, z, w, u, v);
824            case VALUE_FRACTAL:
825                switch (fractalType) {
826                    case BILLOW:
827                        return singleValueFractalBillow(x, y, z, w, u, v);
828                    case RIDGED_MULTI:
829                        return singleValueFractalRidgedMulti(x, y, z, w, u, v);
830                    default:
831                        return singleValueFractalFBM(x, y, z, w, u, v);
832                }
833            case FOAM:
834                return singleFoam(seed, x, y, z, w, u, v);
835            case FOAM_FRACTAL:
836                switch (fractalType) {
837                    case BILLOW:
838                        return singleFoamFractalBillow(x, y, z, w, u, v);
839                    case RIDGED_MULTI:
840                        return singleFoamFractalRidgedMulti(x, y, z, w, u, v);
841                    default:
842                        return singleFoamFractalFBM(x, y, z, w, u, v);
843                }
844            case PERLIN:
845                return singlePerlin(seed, x, y, z, w, u, v);
846            case PERLIN_FRACTAL:
847                switch (fractalType) {
848                    case BILLOW:
849                        return singlePerlinFractalBillow(x, y, z, w, u, v);
850                    case RIDGED_MULTI:
851                        return singlePerlinFractalRidgedMulti(x, y, z, w, u, v);
852                    default:
853                        return singlePerlinFractalFBM(x, y, z, w, u, v);
854                }
855            case SIMPLEX_FRACTAL:
856                switch (fractalType) {
857                    case BILLOW:
858                        return singleSimplexFractalBillow(x, y, z, w, u, v);
859                    case RIDGED_MULTI:
860                        return singleSimplexFractalRidgedMulti(x, y, z, w, u, v);
861                    default:
862                        return singleSimplexFractalFBM(x, y, z, w, u, v);
863                }
864            case WHITE_NOISE:
865                return getWhiteNoise(x, y, z, w, u, v);
866            default:
867                return singleSimplex(seed, x, y, z, w, u, v);
868        }
869    }
870
871    // White Noise
872
873    private int floatToIntMixed(final float f) {
874        final int i = NumberTools.floatToIntBits(f);
875        return i ^ i >>> 16;
876    }
877
878    public float getWhiteNoise(float x, float y, float z, float w, float u, float v) {
879        int xi = floatToIntMixed(x);
880        int yi = floatToIntMixed(y);
881        int zi = floatToIntMixed(z);
882        int wi = floatToIntMixed(w);
883        int ui = floatToIntMixed(u);
884        int vi = floatToIntMixed(v);
885
886        return valCoord6D(seed, xi, yi, zi, wi, ui, vi);
887    }
888
889    public float getWhiteNoise(float x, float y, float z, float w) {
890        int xi = floatToIntMixed(x);
891        int yi = floatToIntMixed(y);
892        int zi = floatToIntMixed(z);
893        int wi = floatToIntMixed(w);
894
895        return valCoord4D(seed, xi, yi, zi, wi);
896    }
897
898    public float getWhiteNoise(float x, float y, float z) {
899        int xi = floatToIntMixed(x);
900        int yi = floatToIntMixed(y);
901        int zi = floatToIntMixed(z);
902
903        return valCoord3D(seed, xi, yi, zi);
904    }
905
906    public float getWhiteNoise(float x, float y) {
907        int xi = floatToIntMixed(x);
908        int yi = floatToIntMixed(y);
909
910        return valCoord2D(seed, xi, yi);
911    }
912
913    public float getWhiteNoiseInt(int x, int y, int z, int w, int u, int v) {
914        return valCoord6D(seed, x, y, z, w, u, v);
915    }
916
917    public float getWhiteNoiseInt(int x, int y, int z, int w) {
918        return valCoord4D(seed, x, y, z, w);
919    }
920
921    public float getWhiteNoiseInt(int x, int y, int z) {
922        return valCoord3D(seed, x, y, z);
923    }
924
925    public float getWhiteNoiseInt(int x, int y) {
926        return valCoord2D(seed, x, y);
927    }
928
929    // Value Noise
930    //x should be premultiplied by 0xD1B55
931    //y should be premultiplied by 0xABC99
932    private static int hashPart1024(final int x, final int y, int s) {
933        s += x ^ y;
934        return (s ^ (s << 19 | s >>> 13) ^ (s << 5 | s >>> 27) ^ 0xD1B54A35) * 0x125493 >> 22;
935    }
936    //x should be premultiplied by 0xDB4F1
937    //y should be premultiplied by 0xBBE05
938    //z should be premultiplied by 0xA0F2F
939    private static int hashPart1024(final int x, final int y, final int z, int s) {
940        s += x ^ y ^ z;
941        return (s ^ (s << 19 | s >>> 13) ^ (s << 5 | s >>> 27) ^ 0xD1B54A35) * 0x125493 >> 22;
942    }
943    //x should be premultiplied by 0xE19B1
944    //y should be premultiplied by 0xC6D1D
945    //z should be premultiplied by 0xAF36D
946    //w should be premultiplied by 0x9A695
947    private static int hashPart1024(final int x, final int y, final int z, final int w, int s) {
948        s += x ^ y ^ z ^ w;
949        return (s ^ (s << 19 | s >>> 13) ^ (s << 5 | s >>> 27) ^ 0xD1B54A35) * 0x125493 >> 22;
950    }
951    //x should be premultiplied by 0xE95E1
952    //y should be premultiplied by 0xD4BC7
953    //z should be premultiplied by 0xC1EDB
954    //w should be premultiplied by 0xB0C8B
955    //u should be premultiplied by 0xA127B
956    //v should be premultiplied by 0x92E85
957    private static int hashPart1024(final int x, final int y, final int z, final int w, final int u, final int v, int s) {
958        s += x ^ y ^ z ^ w ^ u ^ v;
959        return (s ^ (s << 19 | s >>> 13) ^ (s << 5 | s >>> 27) ^ 0xD1B54A35) * 0x125493 >> 22;
960    }
961
962
963    public float getValueFractal(float x, float y) {
964        x *= frequency;
965        y *= frequency;
966
967        switch (fractalType) {
968            case FBM:
969                return singleValueFractalFBM(x, y);
970            case BILLOW:
971                return singleValueFractalBillow(x, y);
972            case RIDGED_MULTI:
973                return singleValueFractalRidgedMulti(x, y);
974            default:
975                return 0;
976        }
977    }
978
979    private float singleValueFractalFBM(float x, float y) {
980        int seed = this.seed;
981        float sum = singleValue(seed, x, y);
982        float amp = 1;
983
984        for (int i = 1; i < octaves; i++) {
985            x *= lacunarity;
986            y *= lacunarity;
987
988            amp *= gain;
989            sum += singleValue(++seed, x, y) * amp;
990        }
991
992        return sum * fractalBounding;
993    }
994
995    private float singleValueFractalBillow(float x, float y) {
996        int seed = this.seed;
997        float sum = Math.abs(singleValue(seed, x, y)) * 2 - 1;
998        float amp = 1;
999
1000        for (int i = 1; i < octaves; i++) {
1001            x *= lacunarity;
1002            y *= lacunarity;
1003            amp *= gain;
1004            sum += (Math.abs(singleValue(++seed, x, y)) * 2 - 1) * amp;
1005        }
1006
1007        return sum * fractalBounding;
1008    }
1009
1010    private float singleValueFractalRidgedMulti(float x, float y) {
1011        int seed = this.seed;
1012        float sum = 0, amp = 1, ampBias = 1f, spike;
1013        for (int i = 0; i < octaves; i++) {
1014            spike = 1f - Math.abs(singleValue(seed + i, x, y));
1015            spike *= spike * amp;
1016            amp = Math.max(0f, Math.min(1f, spike * 2f));
1017            sum += (spike * ampBias);
1018            ampBias *= 2f;
1019            x *= lacunarity;
1020            y *= lacunarity;
1021        }
1022        return sum / ((ampBias - 1f) * 0.5f) - 1f;
1023    }
1024
1025    public float getValue(float x, float y) {
1026        return singleValue(seed, x * frequency, y * frequency);
1027    }
1028
1029
1030    public float singleValue (int seed, float x, float y) {
1031        int xFloor = x >= 0 ? (int) x : (int) x - 1;
1032        x -= xFloor;
1033        int yFloor = y >= 0 ? (int) y : (int) y - 1;
1034        y -= yFloor;
1035        switch (interpolation) {
1036            case HERMITE:
1037                x = hermiteInterpolator(x);
1038                y = hermiteInterpolator(y);
1039                break;
1040            case QUINTIC:
1041                x = quinticInterpolator(x);
1042                y = quinticInterpolator(y);
1043                break;
1044        }
1045        xFloor *= 0xD1B55;
1046        yFloor *= 0xABC99;
1047        return ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, seed) + x * hashPart1024(xFloor + 0xD1B55, yFloor, seed))
1048                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xABC99, seed) + x * hashPart1024(xFloor + 0xD1B55, yFloor + 0xABC99, seed)))
1049                * 0x1p-9f;
1050    }
1051
1052    /**
1053     * Produces noise from 0 to 1, instead of the normal -1 to 1.
1054     * @param seed
1055     * @param x
1056     * @param y
1057     * @return noise from 0 to 1.
1058     */
1059    private static float valueNoise (int seed, float x, float y) {
1060        int xFloor = x >= 0 ? (int) x : (int) x - 1;
1061        x -= xFloor;
1062        x *= x * (3 - 2 * x);
1063        int yFloor = y >= 0 ? (int) y : (int) y - 1;
1064        y -= yFloor;
1065        y *= y * (3 - 2 * y);
1066        xFloor *= 0xD1B55;
1067        yFloor *= 0xABC99;
1068        return ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, seed) + x * hashPart1024(xFloor + 0xD1B55, yFloor, seed))
1069                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xABC99, seed) + x * hashPart1024(xFloor + 0xD1B55, yFloor + 0xABC99, seed)))
1070                * 0x1p-10f + 0.5f;
1071    }
1072    public float getValueFractal(float x, float y, float z) {
1073        x *= frequency;
1074        y *= frequency;
1075        z *= frequency;
1076
1077        switch (fractalType) {
1078            case BILLOW:
1079                return singleValueFractalBillow(x, y, z);
1080            case RIDGED_MULTI:
1081                return singleValueFractalRidgedMulti(x, y, z);
1082            default:
1083                return singleValueFractalFBM(x, y, z);
1084        }
1085    }
1086
1087    private float singleValueFractalFBM(float x, float y, float z) {
1088        int seed = this.seed;
1089        float sum = singleValue(seed, x, y, z);
1090        float amp = 1;
1091
1092        for (int i = 1; i < octaves; i++) {
1093            x *= lacunarity;
1094            y *= lacunarity;
1095            z *= lacunarity;
1096
1097            amp *= gain;
1098            sum += singleValue(++seed, x, y, z) * amp;
1099        }
1100
1101        return sum * fractalBounding;
1102    }
1103
1104    private float singleValueFractalBillow(float x, float y, float z) {
1105        int seed = this.seed;
1106        float sum = Math.abs(singleValue(seed, x, y, z)) * 2 - 1;
1107        float amp = 1;
1108
1109        for (int i = 1; i < octaves; i++) {
1110            x *= lacunarity;
1111            y *= lacunarity;
1112            z *= lacunarity;
1113
1114            amp *= gain;
1115            sum += (Math.abs(singleValue(++seed, x, y, z)) * 2 - 1) * amp;
1116        }
1117
1118        return sum * fractalBounding;
1119    }
1120
1121    private float singleValueFractalRidgedMulti(float x, float y, float z) {
1122        int seed = this.seed;
1123        float sum = 0, amp = 1, ampBias = 1f, spike;
1124        for (int i = 0; i < octaves; i++) {
1125            spike = 1f - Math.abs(singleValue(seed + i, x, y, z));
1126            spike *= spike * amp;
1127            amp = Math.max(0f, Math.min(1f, spike * 2f));
1128            sum += (spike * ampBias);
1129            ampBias *= 2f;
1130            x *= lacunarity;
1131            y *= lacunarity;
1132            z *= lacunarity;
1133        }
1134        return sum / ((ampBias - 1f) * 0.5f) - 1f;
1135    }
1136
1137    public float getValue(float x, float y, float z) {
1138        return singleValue(seed, x * frequency, y * frequency, z * frequency);
1139    }
1140
1141    private float singleValue(int seed, float x, float y, float z) {
1142        int xFloor = x >= 0 ? (int) x : (int) x - 1;
1143        x -= xFloor;
1144        int yFloor = y >= 0 ? (int) y : (int) y - 1;
1145        y -= yFloor;
1146        int zFloor = z >= 0 ? (int) z : (int) z - 1;
1147        z -= zFloor;
1148        switch (interpolation) {
1149            case HERMITE:
1150                x = hermiteInterpolator(x);
1151                y = hermiteInterpolator(y);
1152                z = hermiteInterpolator(z);
1153                break;
1154            case QUINTIC:
1155                x = quinticInterpolator(x);
1156                y = quinticInterpolator(y);
1157                z = quinticInterpolator(z);
1158                break;
1159        }
1160        //0xDB4F1, 0xBBE05, 0xA0F2F
1161        xFloor *= 0xDB4F1;
1162        yFloor *= 0xBBE05;
1163        zFloor *= 0xA0F2F;
1164        return ((1 - z) *
1165                ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, seed) + x * hashPart1024(xFloor + 0xDB4F1, yFloor, zFloor, seed))
1166                        + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xBBE05, zFloor, seed) + x * hashPart1024(xFloor + 0xDB4F1, yFloor + 0xBBE05, zFloor, seed)))
1167                + z *
1168                ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xA0F2F, seed) + x * hashPart1024(xFloor + 0xDB4F1, yFloor, zFloor + 0xA0F2F, seed))
1169                        + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xBBE05, zFloor + 0xA0F2F, seed) + x * hashPart1024(xFloor + 0xDB4F1, yFloor + 0xBBE05, zFloor + 0xA0F2F, seed)))
1170        ) * 0x1p-9f;
1171    }
1172    /**
1173     * Produces noise from 0 to 1, instead of the normal -1 to 1.
1174     * @param seed
1175     * @param x
1176     * @param y
1177     * @param z
1178     * @return noise from 0 to 1.
1179     */
1180    private static float valueNoise (int seed, float x, float y, float z)
1181    {
1182        int xFloor = x >= 0 ? (int) x : (int) x - 1;
1183        x -= xFloor;
1184        x *= x * (3 - 2 * x);
1185        int yFloor = y >= 0 ? (int) y : (int) y - 1;
1186        y -= yFloor;
1187        y *= y * (3 - 2 * y);
1188        int zFloor = z >= 0 ? (int) z : (int) z - 1;
1189        z -= zFloor;
1190        z *= z * (3 - 2 * z);
1191        //0xDB4F1, 0xBBE05, 0xA0F2F
1192        xFloor *= 0xDB4F1;
1193        yFloor *= 0xBBE05;
1194        zFloor *= 0xA0F2F;
1195        return ((1 - z) *
1196                ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, seed) + x * hashPart1024(xFloor + 0xDB4F1, yFloor, zFloor, seed))
1197                        + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xBBE05, zFloor, seed) + x * hashPart1024(xFloor + 0xDB4F1, yFloor + 0xBBE05, zFloor, seed)))
1198                + z *
1199                ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xA0F2F, seed) + x * hashPart1024(xFloor + 0xDB4F1, yFloor, zFloor + 0xA0F2F, seed))
1200                        + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xBBE05, zFloor + 0xA0F2F, seed) + x * hashPart1024(xFloor + 0xDB4F1, yFloor + 0xBBE05, zFloor + 0xA0F2F, seed)))
1201        ) * 0x1p-10f + 0.5f;
1202
1203    }
1204    public float getValueFractal(float x, float y, float z, float w) {
1205        x *= frequency;
1206        y *= frequency;
1207        z *= frequency;
1208        w *= frequency;
1209
1210        switch (fractalType) {
1211            case BILLOW:
1212                return singleValueFractalBillow(x, y, z, w);
1213            case RIDGED_MULTI:
1214                return singleValueFractalRidgedMulti(x, y, z, w);
1215            default:
1216                return singleValueFractalFBM(x, y, z, w);
1217        }
1218    }
1219
1220    private float singleValueFractalFBM(float x, float y, float z, float w) {
1221        int seed = this.seed;
1222        float sum = singleValue(seed, x, y, z, w);
1223        float amp = 1;
1224
1225        for (int i = 1; i < octaves; i++) {
1226            x *= lacunarity;
1227            y *= lacunarity;
1228            z *= lacunarity;
1229            w *= lacunarity;
1230
1231            amp *= gain;
1232            sum += singleValue(++seed, x, y, z, w) * amp;
1233        }
1234
1235        return sum * fractalBounding;
1236    }
1237
1238    private float singleValueFractalBillow(float x, float y, float z, float w) {
1239        int seed = this.seed;
1240        float sum = Math.abs(singleValue(seed, x, y, z, w)) * 2 - 1;
1241        float amp = 1;
1242
1243        for (int i = 1; i < octaves; i++) {
1244            x *= lacunarity;
1245            y *= lacunarity;
1246            z *= lacunarity;
1247            w *= lacunarity;
1248
1249            amp *= gain;
1250            sum += (Math.abs(singleValue(++seed, x, y, z, w)) * 2 - 1) * amp;
1251        }
1252
1253        return sum * fractalBounding;
1254    }
1255
1256    private float singleValueFractalRidgedMulti(float x, float y, float z, float w) {
1257        int seed = this.seed;
1258        float sum = 0, amp = 1, ampBias = 1f, spike;
1259        for (int i = 0; i < octaves; i++) {
1260            spike = 1f - Math.abs(singleValue(seed + i, x, y, z, w));
1261            spike *= spike * amp;
1262            amp = Math.max(0f, Math.min(1f, spike * 2f));
1263            sum += (spike * ampBias);
1264            ampBias *= 2f;
1265            x *= lacunarity;
1266            y *= lacunarity;
1267            z *= lacunarity;
1268            w *= lacunarity;
1269        }
1270        return sum / ((ampBias - 1f) * 0.5f) - 1f;
1271    }
1272
1273    public float getValue(float x, float y, float z, float w) {
1274        return singleValue(seed, x * frequency, y * frequency, z * frequency, w * frequency);
1275    }
1276
1277    private float singleValue(int seed, float x, float y, float z, float w) {
1278        int xFloor = x >= 0 ? (int) x : (int) x - 1;
1279        x -= xFloor;
1280        int yFloor = y >= 0 ? (int) y : (int) y - 1;
1281        y -= yFloor;
1282        int zFloor = z >= 0 ? (int) z : (int) z - 1;
1283        z -= zFloor;
1284        int wFloor = w >= 0 ? (int) w : (int) w - 1;
1285        w -= wFloor;
1286        switch (interpolation) {
1287            case HERMITE:
1288                x = hermiteInterpolator(x);
1289                y = hermiteInterpolator(y);
1290                z = hermiteInterpolator(z);
1291                w = hermiteInterpolator(w);
1292                break;
1293            case QUINTIC:
1294                x = quinticInterpolator(x);
1295                y = quinticInterpolator(y);
1296                z = quinticInterpolator(z);
1297                w = quinticInterpolator(w);
1298                break;
1299        }
1300        //0xE19B1, 0xC6D1D, 0xAF36D, 0x9A695
1301        xFloor *= 0xE19B1;
1302        yFloor *= 0xC6D1D;
1303        zFloor *= 0xAF36D;
1304        wFloor *= 0x9A695;
1305        return ((1 - w) *
1306                ((1 - z) *
1307                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, wFloor, seed) + x * hashPart1024(xFloor + 0xE19B1, yFloor, zFloor, wFloor, seed))
1308                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xC6D1D, zFloor, wFloor, seed) + x * hashPart1024(xFloor + 0xE19B1, yFloor + 0xC6D1D, zFloor, wFloor, seed)))
1309                        + z *
1310                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xAF36D, wFloor, seed) + x * hashPart1024(xFloor + 0xE19B1, yFloor, zFloor + 0xAF36D, wFloor, seed))
1311                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xC6D1D, zFloor + 0xAF36D, wFloor, seed) + x * hashPart1024(xFloor + 0xE19B1, yFloor + 0xC6D1D, zFloor + 0xAF36D, wFloor, seed))))
1312                + (w *
1313                ((1 - z) *
1314                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, wFloor + 0x9A695, seed) + x * hashPart1024(xFloor + 0xE19B1, yFloor, zFloor, wFloor + 0x9A695, seed))
1315                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xC6D1D, zFloor, wFloor + 0x9A695, seed) + x * hashPart1024(xFloor + 0xE19B1, yFloor + 0xC6D1D, zFloor, wFloor + 0x9A695, seed)))
1316                        + z *
1317                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xAF36D, wFloor + 0x9A695, seed) + x * hashPart1024(xFloor + 0xE19B1, yFloor, zFloor + 0xAF36D, wFloor + 0x9A695, seed))
1318                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xC6D1D, zFloor + 0xAF36D, wFloor + 0x9A695, seed) + x * hashPart1024(xFloor + 0xE19B1, yFloor + 0xC6D1D, zFloor + 0xAF36D, wFloor + 0x9A695, seed)))
1319                ))) * 0x1p-9f;
1320    }
1321    private static float valueNoise(int seed, float x, float y, float z, float w)
1322    {
1323        int xFloor = x >= 0 ? (int) x : (int) x - 1;
1324        x -= xFloor;
1325        x *= x * (3 - 2 * x);
1326        int yFloor = y >= 0 ? (int) y : (int) y - 1;
1327        y -= yFloor;
1328        y *= y * (3 - 2 * y);
1329        int zFloor = z >= 0 ? (int) z : (int) z - 1;
1330        z -= zFloor;
1331        z *= z * (3 - 2 * z);
1332        int wFloor = w >= 0 ? (int) w : (int) w - 1;
1333        w -= wFloor;
1334        w *= w * (3 - 2 * w);
1335        //0xE19B1, 0xC6D1D, 0xAF36D, 0x9A695
1336        xFloor *= 0xE19B1;
1337        yFloor *= 0xC6D1D;
1338        zFloor *= 0xAF36D;
1339        wFloor *= 0x9A695;
1340        return ((1 - w) *
1341                ((1 - z) *
1342                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, wFloor, seed) + x * hashPart1024(xFloor + 0xE19B1, yFloor, zFloor, wFloor, seed))
1343                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xC6D1D, zFloor, wFloor, seed) + x * hashPart1024(xFloor + 0xE19B1, yFloor + 0xC6D1D, zFloor, wFloor, seed)))
1344                        + z *
1345                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xAF36D, wFloor, seed) + x * hashPart1024(xFloor + 0xE19B1, yFloor, zFloor + 0xAF36D, wFloor, seed))
1346                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xC6D1D, zFloor + 0xAF36D, wFloor, seed) + x * hashPart1024(xFloor + 0xE19B1, yFloor + 0xC6D1D, zFloor + 0xAF36D, wFloor, seed))))
1347                + (w *
1348                ((1 - z) *
1349                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, wFloor + 0x9A695, seed) + x * hashPart1024(xFloor + 0xE19B1, yFloor, zFloor, wFloor + 0x9A695, seed))
1350                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xC6D1D, zFloor, wFloor + 0x9A695, seed) + x * hashPart1024(xFloor + 0xE19B1, yFloor + 0xC6D1D, zFloor, wFloor + 0x9A695, seed)))
1351                        + z *
1352                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xAF36D, wFloor + 0x9A695, seed) + x * hashPart1024(xFloor + 0xE19B1, yFloor, zFloor + 0xAF36D, wFloor + 0x9A695, seed))
1353                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xC6D1D, zFloor + 0xAF36D, wFloor + 0x9A695, seed) + x * hashPart1024(xFloor + 0xE19B1, yFloor + 0xC6D1D, zFloor + 0xAF36D, wFloor + 0x9A695, seed)))
1354                ))) * 0x1p-10f + 0.5f;
1355    }
1356
1357    public float getValueFractal(float x, float y, float z, float w, float u, float v) {
1358        x *= frequency;
1359        y *= frequency;
1360        z *= frequency;
1361        w *= frequency;
1362        u *= frequency;
1363        v *= frequency;
1364
1365        switch (fractalType) {
1366            case BILLOW:
1367                return singleValueFractalBillow(x, y, z, w, u, v);
1368            case RIDGED_MULTI:
1369                return singleValueFractalRidgedMulti(x, y, z, w, u, v);
1370            default:
1371                return singleValueFractalFBM(x, y, z, w, u, v);
1372        }
1373    }
1374    private float singleValueFractalFBM(float x, float y, float z, float w, float u, float v) {
1375        int seed = this.seed;
1376        float sum = singleValue(seed, x, y, z, w, u, v);
1377        float amp = 1;
1378
1379        for (int i = 1; i < octaves; i++) {
1380            x *= lacunarity;
1381            y *= lacunarity;
1382            z *= lacunarity;
1383            w *= lacunarity;
1384            u *= lacunarity;
1385            v *= lacunarity;
1386
1387            amp *= gain;
1388            sum += singleValue(++seed, x, y, z, w, u, v) * amp;
1389        }
1390
1391        return sum * fractalBounding;
1392    }
1393
1394    private float singleValueFractalBillow(float x, float y, float z, float w, float u, float v) {
1395        int seed = this.seed;
1396        float sum = Math.abs(singleValue(seed, x, y, z, w, u, v)) * 2 - 1;
1397        float amp = 1;
1398
1399        for (int i = 1; i < octaves; i++) {
1400            x *= lacunarity;
1401            y *= lacunarity;
1402            z *= lacunarity;
1403            w *= lacunarity;
1404            u *= lacunarity;
1405            v *= lacunarity;
1406
1407            amp *= gain;
1408            sum += (Math.abs(singleValue(++seed, x, y, z, w, u, v)) * 2 - 1) * amp;
1409        }
1410
1411        return sum * fractalBounding;
1412    }
1413
1414    private float singleValueFractalRidgedMulti(float x, float y, float z, float w, float u, float v) {
1415        int seed = this.seed;
1416        float sum = 0, amp = 1, ampBias = 1f, spike;
1417        for (int i = 0; i < octaves; i++) {
1418            spike = 1f - Math.abs(singleValue(seed + i, x, y, z, w, u, v));
1419            spike *= spike * amp;
1420            amp = Math.max(0f, Math.min(1f, spike * 2f));
1421            sum += (spike * ampBias);
1422            ampBias *= 2f;
1423            x *= lacunarity;
1424            y *= lacunarity;
1425            z *= lacunarity;
1426            w *= lacunarity;
1427            u *= lacunarity;
1428            v *= lacunarity;
1429        }
1430        return sum / ((ampBias - 1f) * 0.5f) - 1f;
1431    }
1432
1433    public float getValue(float x, float y, float z, float w, float u, float v) {
1434        return singleValue(seed, x * frequency, y * frequency, z * frequency, w * frequency, u * frequency, v * frequency);
1435    }
1436
1437    private float singleValue(int seed, float x, float y, float z, float w, float u, float v) {
1438        int xFloor = x >= 0 ? (int) x : (int) x - 1;
1439        x -= xFloor;
1440        int yFloor = y >= 0 ? (int) y : (int) y - 1;
1441        y -= yFloor;
1442        int zFloor = z >= 0 ? (int) z : (int) z - 1;
1443        z -= zFloor;
1444        int wFloor = w >= 0 ? (int) w : (int) w - 1;
1445        w -= wFloor;
1446        int uFloor = u >= 0 ? (int) u : (int) u - 1;
1447        u -= uFloor;
1448        int vFloor = v >= 0 ? (int) v : (int) v - 1;
1449        v -= vFloor;
1450        switch (interpolation) {
1451            case HERMITE:
1452                x = hermiteInterpolator(x);
1453                y = hermiteInterpolator(y);
1454                z = hermiteInterpolator(z);
1455                w = hermiteInterpolator(w);
1456                u = hermiteInterpolator(u);
1457                v = hermiteInterpolator(v);
1458                break;
1459            case QUINTIC:
1460                x = quinticInterpolator(x);
1461                y = quinticInterpolator(y);
1462                z = quinticInterpolator(z);
1463                w = quinticInterpolator(w);
1464                u = quinticInterpolator(u);
1465                v = quinticInterpolator(v);
1466                break;
1467        }
1468        //0xE95E1, 0xD4BC7, 0xC1EDB, 0xB0C8B, 0xA1279, 0x92E85
1469        xFloor *= 0xE95E1;
1470        yFloor *= 0xD4BC7;
1471        zFloor *= 0xC1EDB;
1472        wFloor *= 0xB0C8B;
1473        uFloor *= 0xA127B;
1474        vFloor *= 0x92E85;
1475        return ((1 - v) *
1476                ((1 - u) *
1477                        ((1 - w) *
1478                                ((1 - z) *
1479                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, wFloor, uFloor, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor, wFloor, uFloor, vFloor, seed))
1480                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor, wFloor, uFloor, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor, wFloor, uFloor, vFloor, seed)))
1481                                        + z *
1482                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xC1EDB, wFloor, uFloor, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor + 0xC1EDB, wFloor, uFloor, vFloor, seed))
1483                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor, uFloor, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor, uFloor, vFloor, seed))))
1484                                + (w *
1485                                ((1 - z) *
1486                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, wFloor + 0xB0C8B, uFloor, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor, wFloor + 0xB0C8B, uFloor, vFloor, seed))
1487                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor, wFloor + 0xB0C8B, uFloor, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor, wFloor + 0xB0C8B, uFloor, vFloor, seed)))
1488                                        + z *
1489                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor, vFloor, seed))
1490                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor, vFloor, seed)))
1491                                )))
1492                        + (u *
1493                        ((1 - w) *
1494                                ((1 - z) *
1495                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, wFloor, uFloor + 0xA127B, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor, wFloor, uFloor + 0xA127B, vFloor, seed))
1496                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor, wFloor, uFloor + 0xA127B, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor, wFloor, uFloor + 0xA127B, vFloor, seed)))
1497                                        + z *
1498                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xC1EDB, wFloor, uFloor + 0xA127B, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor + 0xC1EDB, wFloor, uFloor + 0xA127B, vFloor, seed))
1499                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor, uFloor + 0xA127B, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor, uFloor + 0xA127B, vFloor, seed))))
1500                                + (w *
1501                                ((1 - z) *
1502                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor, seed))
1503                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor, seed)))
1504                                        + z *
1505                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor, seed))
1506                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor, seed)))
1507                                )))))
1508                + (v *
1509                ((1 - u) *
1510                        ((1 - w) *
1511                                ((1 - z) *
1512                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, wFloor, uFloor, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor, wFloor, uFloor, vFloor + 0x92E85, seed))
1513                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor, wFloor, uFloor, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor, wFloor, uFloor, vFloor + 0x92E85, seed)))
1514                                        + z *
1515                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xC1EDB, wFloor, uFloor, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor + 0xC1EDB, wFloor, uFloor, vFloor + 0x92E85, seed))
1516                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor, uFloor, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor, uFloor, vFloor + 0x92E85, seed))))
1517                                + (w *
1518                                ((1 - z) *
1519                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, wFloor + 0xB0C8B, uFloor, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor, wFloor + 0xB0C8B, uFloor, vFloor + 0x92E85, seed))
1520                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor, wFloor + 0xB0C8B, uFloor, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor, wFloor + 0xB0C8B, uFloor, vFloor + 0x92E85, seed)))
1521                                        + z *
1522                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor, vFloor + 0x92E85, seed))
1523                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor, vFloor + 0x92E85, seed)))
1524                                )))
1525                        + (u *
1526                        ((1 - w) *
1527                                ((1 - z) *
1528                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, wFloor, uFloor + 0xA127B, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor, wFloor, uFloor + 0xA127B, vFloor + 0x92E85, seed))
1529                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor, wFloor, uFloor + 0xA127B, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor, wFloor, uFloor + 0xA127B, vFloor + 0x92E85, seed)))
1530                                        + z *
1531                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xC1EDB, wFloor, uFloor + 0xA127B, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor + 0xC1EDB, wFloor, uFloor + 0xA127B, vFloor + 0x92E85, seed))
1532                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor, uFloor + 0xA127B, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor, uFloor + 0xA127B, vFloor + 0x92E85, seed))))
1533                                + (w *
1534                                ((1 - z) *
1535                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor + 0x92E85, seed))
1536                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor + 0x92E85, seed)))
1537                                        + z *
1538                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor + 0x92E85, seed))
1539                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor + 0x92E85, seed)))
1540                                ))))))
1541        ) * 0x1p-9f;
1542    }
1543
1544    private static float valueNoise(int seed, float x, float y, float z, float w, float u, float v) {
1545        int xFloor = x >= 0 ? (int) x : (int) x - 1;
1546        x -= xFloor;
1547        x *= x * (3 - 2 * x);
1548        int yFloor = y >= 0 ? (int) y : (int) y - 1;
1549        y -= yFloor;
1550        y *= y * (3 - 2 * y);
1551        int zFloor = z >= 0 ? (int) z : (int) z - 1;
1552        z -= zFloor;
1553        z *= z * (3 - 2 * z);
1554        int wFloor = w >= 0 ? (int) w : (int) w - 1;
1555        w -= wFloor;
1556        w *= w * (3 - 2 * w);
1557        int uFloor = u >= 0 ? (int) u : (int) u - 1;
1558        u -= uFloor;
1559        u *= u * (3 - 2 * u);
1560        int vFloor = v >= 0 ? (int) v : (int) v - 1;
1561        v -= vFloor;
1562        v *= v * (3 - 2 * v);
1563        //0xE95E1, 0xD4BC7, 0xC1EDB, 0xB0C8B, 0xA1279, 0x92E85
1564        xFloor *= 0xE95E1;
1565        yFloor *= 0xD4BC7;
1566        zFloor *= 0xC1EDB;
1567        wFloor *= 0xB0C8B;
1568        uFloor *= 0xA127B;
1569        vFloor *= 0x92E85;
1570        return ((1 - v) *
1571                ((1 - u) *
1572                        ((1 - w) *
1573                                ((1 - z) *
1574                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, wFloor, uFloor, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor, wFloor, uFloor, vFloor, seed))
1575                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor, wFloor, uFloor, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor, wFloor, uFloor, vFloor, seed)))
1576                                        + z *
1577                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xC1EDB, wFloor, uFloor, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor + 0xC1EDB, wFloor, uFloor, vFloor, seed))
1578                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor, uFloor, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor, uFloor, vFloor, seed))))
1579                                + (w *
1580                                ((1 - z) *
1581                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, wFloor + 0xB0C8B, uFloor, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor, wFloor + 0xB0C8B, uFloor, vFloor, seed))
1582                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor, wFloor + 0xB0C8B, uFloor, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor, wFloor + 0xB0C8B, uFloor, vFloor, seed)))
1583                                        + z *
1584                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor, vFloor, seed))
1585                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor, vFloor, seed)))
1586                                )))
1587                        + (u *
1588                        ((1 - w) *
1589                                ((1 - z) *
1590                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, wFloor, uFloor + 0xA127B, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor, wFloor, uFloor + 0xA127B, vFloor, seed))
1591                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor, wFloor, uFloor + 0xA127B, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor, wFloor, uFloor + 0xA127B, vFloor, seed)))
1592                                        + z *
1593                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xC1EDB, wFloor, uFloor + 0xA127B, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor + 0xC1EDB, wFloor, uFloor + 0xA127B, vFloor, seed))
1594                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor, uFloor + 0xA127B, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor, uFloor + 0xA127B, vFloor, seed))))
1595                                + (w *
1596                                ((1 - z) *
1597                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor, seed))
1598                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor, seed)))
1599                                        + z *
1600                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor, seed))
1601                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor, seed)))
1602                                )))))
1603                + (v *
1604                ((1 - u) *
1605                        ((1 - w) *
1606                                ((1 - z) *
1607                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, wFloor, uFloor, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor, wFloor, uFloor, vFloor + 0x92E85, seed))
1608                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor, wFloor, uFloor, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor, wFloor, uFloor, vFloor + 0x92E85, seed)))
1609                                        + z *
1610                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xC1EDB, wFloor, uFloor, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor + 0xC1EDB, wFloor, uFloor, vFloor + 0x92E85, seed))
1611                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor, uFloor, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor, uFloor, vFloor + 0x92E85, seed))))
1612                                + (w *
1613                                ((1 - z) *
1614                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, wFloor + 0xB0C8B, uFloor, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor, wFloor + 0xB0C8B, uFloor, vFloor + 0x92E85, seed))
1615                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor, wFloor + 0xB0C8B, uFloor, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor, wFloor + 0xB0C8B, uFloor, vFloor + 0x92E85, seed)))
1616                                        + z *
1617                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor, vFloor + 0x92E85, seed))
1618                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor, vFloor + 0x92E85, seed)))
1619                                )))
1620                        + (u *
1621                        ((1 - w) *
1622                                ((1 - z) *
1623                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, wFloor, uFloor + 0xA127B, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor, wFloor, uFloor + 0xA127B, vFloor + 0x92E85, seed))
1624                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor, wFloor, uFloor + 0xA127B, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor, wFloor, uFloor + 0xA127B, vFloor + 0x92E85, seed)))
1625                                        + z *
1626                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xC1EDB, wFloor, uFloor + 0xA127B, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor + 0xC1EDB, wFloor, uFloor + 0xA127B, vFloor + 0x92E85, seed))
1627                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor, uFloor + 0xA127B, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor, uFloor + 0xA127B, vFloor + 0x92E85, seed))))
1628                                + (w *
1629                                ((1 - z) *
1630                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor + 0x92E85, seed))
1631                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor + 0x92E85, seed)))
1632                                        + z *
1633                                        ((1 - y) * ((1 - x) * hashPart1024(xFloor, yFloor, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor + 0x92E85, seed))
1634                                                + y * ((1 - x) * hashPart1024(xFloor, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor + 0x92E85, seed) + x * hashPart1024(xFloor + 0xE95E1, yFloor + 0xD4BC7, zFloor + 0xC1EDB, wFloor + 0xB0C8B, uFloor + 0xA127B, vFloor + 0x92E85, seed)))
1635                                ))))))
1636        ) * 0x1p-10f + 0.5f;
1637    }
1638
1639    public float getFoamFractal(float x, float y) {
1640        x *= frequency;
1641        y *= frequency;
1642
1643        switch (fractalType) {
1644            case FBM:
1645                return singleFoamFractalFBM(x, y);
1646            case BILLOW:
1647                return singleFoamFractalBillow(x, y);
1648            case RIDGED_MULTI:
1649                return singleFoamFractalRidgedMulti(x, y);
1650            default:
1651                return 0;
1652        }
1653    }
1654
1655    private float singleFoamFractalFBM(float x, float y) {
1656        int seed = this.seed;
1657        float sum = singleFoam(seed, x, y);
1658        float amp = 1, t;
1659
1660        for (int i = 1; i < octaves; i++) {
1661            t = x;
1662            x = y * lacunarity;
1663            y = t * lacunarity;
1664
1665            amp *= gain;
1666            sum += singleFoam(seed + i, x, y) * amp;
1667        }
1668
1669        return sum * fractalBounding;
1670    }
1671
1672    private float singleFoamFractalBillow(float x, float y) {
1673        int seed = this.seed;
1674        float sum = Math.abs(singleFoam(seed, x, y)) * 2 - 1;
1675        float amp = 1, t;
1676
1677        for (int i = 1; i < octaves; i++) {
1678            t = x;
1679            x = y * lacunarity;
1680            y = t * lacunarity;
1681
1682            amp *= gain;
1683            sum += (Math.abs(singleFoam(++seed, x, y)) * 2 - 1) * amp;
1684        }
1685
1686        return sum * fractalBounding;
1687    }
1688
1689    private float singleFoamFractalRidgedMulti(float x, float y) {
1690        int seed = this.seed;
1691        float sum = 0, amp = 1, ampBias = 1f, spike, t;
1692        for (int i = 0; i < octaves; i++) {
1693            spike = 1f - Math.abs(singleFoam(seed + i, x, y));
1694            spike *= spike * amp;
1695            amp = Math.max(0f, Math.min(1f, spike * 2f));
1696            sum += (spike * ampBias);
1697            ampBias *= 2f;
1698            t = x;
1699            x = y * lacunarity;
1700            y = t * lacunarity;
1701        }
1702        return sum / ((ampBias - 1f) * 0.5f) - 1f;
1703    }
1704
1705    public float getFoam(float x, float y) {
1706        return singleFoam(seed, x * frequency, y * frequency);
1707    }
1708
1709
1710    // Foam Noise
1711    public float singleFoam(int seed, float x, float y) {
1712        final float p0 = x;
1713        final float p1 = x * -0.5f + y * 0.8660254037844386f;
1714        final float p2 = x * -0.5f + y * -0.8660254037844387f;
1715
1716        float xin = p2;
1717        float yin = p0;
1718        final float a = valueNoise(seed, xin, yin);
1719        seed += 0x9E3779BD;
1720        seed ^= seed >>> 14;
1721        xin = p1;
1722        yin = p2;
1723        final float b = valueNoise(seed, xin + a, yin);
1724        seed += 0x9E3779BD;
1725        seed ^= seed >>> 14;
1726        xin = p0;
1727        yin = p1;
1728        final float c = valueNoise(seed, xin + b, yin);
1729        final float result = (a + b + c) * F3;
1730        return (result <= 0.5f)
1731                ? (result * result * 4) - 1
1732                : 1 - ((result - 1) * (result - 1) * 4);
1733    }
1734    public float getFoamFractal(float x, float y, float z) {
1735        x *= frequency;
1736        y *= frequency;
1737        z *= frequency;
1738
1739        switch (fractalType) {
1740            case FBM:
1741                return singleFoamFractalFBM(x, y, z);
1742            case BILLOW:
1743                return singleFoamFractalBillow(x, y, z);
1744            case RIDGED_MULTI:
1745                return singleFoamFractalRidgedMulti(x, y, z);
1746            default:
1747                return 0;
1748        }
1749    }
1750
1751    private float singleFoamFractalFBM(float x, float y, float z) {
1752        int seed = this.seed;
1753        float sum = singleFoam(seed, x, y, z);
1754        float amp = 1;
1755
1756        for (int i = 1; i < octaves; i++) {
1757            x *= lacunarity;
1758            y *= lacunarity;
1759            z *= lacunarity;
1760
1761            amp *= gain;
1762            sum += singleFoam(++seed, x, y, z) * amp;
1763        }
1764
1765        return sum * fractalBounding;
1766    }
1767
1768    private float singleFoamFractalBillow(float x, float y, float z) {
1769        int seed = this.seed;
1770        float sum = Math.abs(singleFoam(seed, x, y, z)) * 2 - 1;
1771        float amp = 1;
1772
1773        for (int i = 1; i < octaves; i++) {
1774            x *= lacunarity;
1775            y *= lacunarity;
1776            z *= lacunarity;
1777
1778            amp *= gain;
1779            sum += (Math.abs(singleFoam(++seed, x, y, z)) * 2 - 1) * amp;
1780        }
1781
1782        return sum * fractalBounding;
1783    }
1784
1785    private float singleFoamFractalRidgedMulti(float x, float y, float z) {
1786        int seed = this.seed;
1787        float sum = 0, amp = 1, ampBias = 1f, spike;
1788        for (int i = 0; i < octaves; i++) {
1789            spike = 1f - Math.abs(singleFoam(seed + i, x, y, z));
1790            spike *= spike * amp;
1791            amp = Math.max(0f, Math.min(1f, spike * 2f));
1792            sum += (spike * ampBias);
1793            ampBias *= 2f;
1794            x *= lacunarity;
1795            y *= lacunarity;
1796            z *= lacunarity;
1797        }
1798        return sum / ((ampBias - 1f) * 0.5f) - 1f;
1799    }
1800
1801    public float getFoam(float x, float y, float z) {
1802        return singleFoam(seed, x * frequency, y * frequency, z * frequency);
1803    }
1804
1805    public float singleFoam(int seed, float x, float y, float z){
1806        final float p0 = x;
1807        final float p1 = x * -0.3333333333333333f + y * 0.9428090415820634f;
1808        final float p2 = x * -0.3333333333333333f + y * -0.4714045207910317f + z * 0.816496580927726f;
1809        final float p3 = x * -0.3333333333333333f + y * -0.4714045207910317f + z * -0.816496580927726f;
1810
1811        float xin = p3;
1812        float yin = p2;
1813        float zin = p0;
1814        final float a = valueNoise(seed, xin, yin, zin);
1815        seed += 0x9E3779BD;
1816        seed ^= seed >>> 14;
1817        xin = p0;
1818        yin = p1;
1819        zin = p3;
1820        final float b = valueNoise(seed, xin + a, yin, zin);
1821        seed += 0x9E3779BD;
1822        seed ^= seed >>> 14;
1823        xin = p1;
1824        yin = p2;
1825        zin = p3;
1826        final float c = valueNoise(seed, xin + b, yin, zin);
1827        seed += 0x9E3779BD;
1828        seed ^= seed >>> 14;
1829        xin = p0;
1830        yin = p1;
1831        zin = p2;
1832        final float d = valueNoise(seed, xin + c, yin, zin);
1833
1834        float result = (a + b + c + d) * 0.25f;
1835        if(result <= 0.5){
1836            result *= 2;
1837            return result * result * result - 1;
1838        }
1839        else {
1840            result = (result - 1) * 2;
1841            return result * result * result + 1;
1842        }
1843    }
1844
1845
1846    private float singleFoamFractalFBM(float x, float y, float z, float w) {
1847        int seed = this.seed;
1848        float sum = singleFoam(seed, x, y, z, w);
1849        float amp = 1;
1850
1851        for (int i = 1; i < octaves; i++) {
1852            x *= lacunarity;
1853            y *= lacunarity;
1854            z *= lacunarity;
1855            w *= lacunarity;
1856
1857            amp *= gain;
1858            sum += singleFoam(++seed, x, y, z, w) * amp;
1859        }
1860
1861        return sum * fractalBounding;
1862    }
1863
1864    private float singleFoamFractalBillow(float x, float y, float z, float w) {
1865        int seed = this.seed;
1866        float sum = Math.abs(singleFoam(seed, x, y, z, w)) * 2 - 1;
1867        float amp = 1;
1868
1869        for (int i = 1; i < octaves; i++) {
1870            x *= lacunarity;
1871            y *= lacunarity;
1872            z *= lacunarity;
1873            w *= lacunarity;
1874
1875            amp *= gain;
1876            sum += (Math.abs(singleFoam(++seed, x, y, z, w)) * 2 - 1) * amp;
1877        }
1878
1879        return sum * fractalBounding;
1880    }
1881
1882    private float singleFoamFractalRidgedMulti(float x, float y, float z, float w) {
1883        int seed = this.seed;
1884        float sum = 0, amp = 1, ampBias = 1f, spike;
1885        for (int i = 0; i < octaves; i++) {
1886            spike = 1f - Math.abs(singleFoam(seed + i, x, y,  z, w));
1887            spike *= spike * amp;
1888            amp = Math.max(0f, Math.min(1f, spike * 2f));
1889            sum += (spike * ampBias);
1890            ampBias *= 2f;
1891            x *= lacunarity;
1892            y *= lacunarity;
1893            z *= lacunarity;
1894            w *= lacunarity;
1895        }
1896        return sum / ((ampBias - 1f) * 0.5f) - 1f;
1897    }
1898
1899    public float getFoam(float x, float y, float z, float w) {
1900        return singleFoam(seed, x * frequency, y * frequency, z * frequency, w * frequency);
1901    }
1902
1903    public float singleFoam(int seed, float x, float y, float z, float w) {
1904        final float p0 = x;
1905        final float p1 = x * -0.25f + y *  0.9682458365518543f;
1906        final float p2 = x * -0.25f + y * -0.3227486121839514f + z *  0.91287092917527690f;
1907        final float p3 = x * -0.25f + y * -0.3227486121839514f + z * -0.45643546458763834f + w *  0.7905694150420949f;
1908        final float p4 = x * -0.25f + y * -0.3227486121839514f + z * -0.45643546458763834f + w * -0.7905694150420947f;
1909
1910        float xin = p1;
1911        float yin = p2;
1912        float zin = p3;
1913        float win = p4;
1914        final float a = valueNoise(seed, xin, yin, zin, win);
1915        seed += 0x9E3779BD;
1916        seed ^= seed >>> 14;
1917        xin = p0;
1918        yin = p2;
1919        zin = p3;
1920        win = p4;
1921        final float b = valueNoise(seed, xin + a, yin, zin, win);
1922        seed += 0x9E3779BD;
1923        seed ^= seed >>> 14;
1924        xin = p0;
1925        yin = p1;
1926        zin = p3;
1927        win = p4;
1928        final float c = valueNoise(seed, xin + b, yin, zin, win);
1929        seed += 0x9E3779BD;
1930        seed ^= seed >>> 14;
1931        xin = p0;
1932        yin = p1;
1933        zin = p2;
1934        win = p4;
1935        final float d = valueNoise(seed, xin + c, yin, zin, win);
1936        seed += 0x9E3779BD;
1937        seed ^= seed >>> 14;
1938        xin = p0;
1939        yin = p1;
1940        zin = p2;
1941        win = p3;
1942        final float e = valueNoise(seed, xin + d, yin, zin, win);
1943
1944        float result = (a + b + c + d + e) * 0.2f;
1945        if(result <= 0.5f){
1946            result *= 2;
1947            result *= result;
1948            return result * result - 1;
1949        }
1950        else{
1951            result = (result - 1) * 2;
1952            result *= result;
1953            return 1 - result * result;
1954        }
1955    }
1956    public float getFoamFractal(float x, float y, float z, float w, float u, float v) {
1957        x *= frequency;
1958        y *= frequency;
1959        z *= frequency;
1960        w *= frequency;
1961        u *= frequency;
1962        v *= frequency;
1963
1964        switch (fractalType) {
1965            case FBM:
1966                return singleFoamFractalFBM(x, y, z, w, u, v);
1967            case BILLOW:
1968                return singleFoamFractalBillow(x, y, z, w, u, v);
1969            case RIDGED_MULTI:
1970                return singleFoamFractalRidgedMulti(x, y, z, w, u, v);
1971            default:
1972                return 0;
1973        }
1974    }
1975
1976    private float singleFoamFractalFBM(float x, float y, float z, float w, float u, float v) {
1977        int seed = this.seed;
1978        float sum = singleFoam(seed, x, y, z, w, u, v);
1979        float amp = 1;
1980
1981        for (int i = 1; i < octaves; i++) {
1982            x *= lacunarity;
1983            y *= lacunarity;
1984            z *= lacunarity;
1985            w *= lacunarity;
1986            u *= lacunarity;
1987            v *= lacunarity;
1988
1989            amp *= gain;
1990            sum += singleFoam(++seed, x, y, z, w, u, v) * amp;
1991        }
1992
1993        return sum * fractalBounding;
1994    }
1995
1996    private float singleFoamFractalBillow(float x, float y, float z, float w, float u, float v) {
1997        int seed = this.seed;
1998        float sum = Math.abs(singleFoam(seed, x, y, z, w, u, v)) * 2 - 1;
1999        float amp = 1;
2000
2001        for (int i = 1; i < octaves; i++) {
2002            x *= lacunarity;
2003            y *= lacunarity;
2004            z *= lacunarity;
2005            w *= lacunarity;
2006            u *= lacunarity;
2007            v *= lacunarity;
2008
2009            amp *= gain;
2010            sum += (Math.abs(singleFoam(++seed, x, y, z, w, u, v)) * 2 - 1) * amp;
2011        }
2012
2013        return sum * fractalBounding;
2014    }
2015
2016    private float singleFoamFractalRidgedMulti(float x, float y, float z, float w, float u, float v) {
2017        int seed = this.seed;
2018        float sum = 0, amp = 1, ampBias = 1f, spike;
2019        for (int i = 0; i < octaves; i++) {
2020            spike = 1f - Math.abs(singleFoam(seed + i, x, y, z, w, u, v));
2021            spike *= spike * amp;
2022            amp = Math.max(0f, Math.min(1f, spike * 2f));
2023            sum += (spike * ampBias);
2024            ampBias *= 2f;
2025            x *= lacunarity;
2026            y *= lacunarity;
2027            z *= lacunarity;
2028            w *= lacunarity;
2029            u *= lacunarity;
2030            v *= lacunarity;
2031        }
2032        return sum / ((ampBias - 1f) * 0.5f) - 1f;
2033    }
2034
2035    public float getFoam(float x, float y, float z, float w, float u, float v) {
2036        return singleFoam(seed, x * frequency, y * frequency, z * frequency, w * frequency, u * frequency, v * frequency);
2037    }
2038
2039    public float singleFoam(int seed, float x, float y, float z, float w, float u, float v) {
2040        final float p0 = x;
2041        final float p1 = x * -0.16666666666666666f + y *  0.98601329718326940f;
2042        final float p2 = x * -0.16666666666666666f + y * -0.19720265943665383f + z *  0.96609178307929590f;
2043        final float p3 = x * -0.16666666666666666f + y * -0.19720265943665383f + z * -0.24152294576982394f + w *  0.93541434669348530f;
2044        final float p4 = x * -0.16666666666666666f + y * -0.19720265943665383f + z * -0.24152294576982394f + w * -0.31180478223116176f + u *  0.8819171036881969f;
2045        final float p5 = x * -0.16666666666666666f + y * -0.19720265943665383f + z * -0.24152294576982394f + w * -0.31180478223116176f + u * -0.4409585518440984f + v *  0.7637626158259734f;
2046        final float p6 = x * -0.16666666666666666f + y * -0.19720265943665383f + z * -0.24152294576982394f + w * -0.31180478223116176f + u * -0.4409585518440984f + v * -0.7637626158259732f;
2047        float xin = p0;
2048        float yin = p5;
2049        float zin = p3;
2050        float win = p6;
2051        float uin = p1;
2052        float vin = p4;
2053        final float a = valueNoise(seed, xin, yin, zin, win, uin, vin);
2054        seed += 0x9E3779BD;
2055        seed ^= seed >>> 14;
2056        xin = p2;
2057        yin = p6;
2058        zin = p0;
2059        win = p4;
2060        uin = p5;
2061        vin = p3;
2062        final float b = valueNoise(seed, xin + a, yin, zin, win, uin, vin);
2063        seed += 0x9E3779BD;
2064        seed ^= seed >>> 14;
2065        xin = p1;
2066        yin = p2;
2067        zin = p3;
2068        win = p4;
2069        uin = p6;
2070        vin = p5;
2071        final float c = valueNoise(seed, xin + b, yin, zin, win, uin, vin);
2072        seed += 0x9E3779BD;
2073        seed ^= seed >>> 14;
2074        xin = p6;
2075        yin = p0;
2076        zin = p2;
2077        win = p5;
2078        uin = p4;
2079        vin = p1;
2080        final float d = valueNoise(seed, xin + c, yin, zin, win, uin, vin);
2081        seed += 0x9E3779BD;
2082        seed ^= seed >>> 14;
2083        xin = p2;
2084        yin = p1;
2085        zin = p5;
2086        win = p0;
2087        uin = p3;
2088        vin = p6;
2089        final float e = valueNoise(seed, xin + d, yin, zin, win, uin, vin);
2090        seed += 0x9E3779BD;
2091        seed ^= seed >>> 14;
2092        xin = p0;
2093        yin = p4;
2094        zin = p6;
2095        win = p3;
2096        uin = p1;
2097        vin = p2;
2098        final float f = valueNoise(seed, xin + e, yin, zin, win, uin, vin);
2099        seed += 0x9E3779BD;
2100        seed ^= seed >>> 14;
2101        xin = p5;
2102        yin = p1;
2103        zin = p2;
2104        win = p3;
2105        uin = p4;
2106        vin = p0;
2107        final float g = valueNoise(seed, xin + f, yin, zin, win, uin, vin);
2108        float result = (a + b + c + d + e + f + g) * 0.14285714285714285f;
2109        if (result <= 0.5f){
2110            result *= 2;
2111            result *= result * result;
2112            return result * result - 1;
2113        }
2114        else{
2115            result = (result - 1) * 2;
2116            result *= result * result;
2117            return 1 - result * result;
2118        }
2119    }
2120
2121    // Gradient Noise
2122    public float getPerlinFractal(float x, float y, float z) {
2123        x *= frequency;
2124        y *= frequency;
2125        z *= frequency;
2126
2127        switch (fractalType) {
2128            case FBM:
2129                return singlePerlinFractalFBM(x, y, z);
2130            case BILLOW:
2131                return singlePerlinFractalBillow(x, y, z);
2132            case RIDGED_MULTI:
2133                return singlePerlinFractalRidgedMulti(x, y, z);
2134            default:
2135                return 0;
2136        }
2137    }
2138
2139    private float singlePerlinFractalFBM(float x, float y, float z) {
2140        int seed = this.seed;
2141        float sum = singlePerlin(seed, x, y, z);
2142        float amp = 1;
2143
2144        for (int i = 1; i < octaves; i++) {
2145            x *= lacunarity;
2146            y *= lacunarity;
2147            z *= lacunarity;
2148
2149            amp *= gain;
2150            sum += singlePerlin(++seed, x, y, z) * amp;
2151        }
2152
2153        return sum * fractalBounding;
2154    }
2155
2156    private float singlePerlinFractalBillow(float x, float y, float z) {
2157        int seed = this.seed;
2158        float sum = Math.abs(singlePerlin(seed, x, y, z)) * 2 - 1;
2159        float amp = 1;
2160
2161        for (int i = 1; i < octaves; i++) {
2162            x *= lacunarity;
2163            y *= lacunarity;
2164            z *= lacunarity;
2165
2166            amp *= gain;
2167            sum += (Math.abs(singlePerlin(++seed, x, y, z)) * 2 - 1) * amp;
2168        }
2169
2170        return sum * fractalBounding;
2171    }
2172
2173    private float singlePerlinFractalRidgedMulti(float x, float y, float z) {
2174        int seed = this.seed;
2175        float sum = 0, amp = 1, ampBias = 1f, spike;
2176        for (int i = 0; i < octaves; i++) {
2177            spike = 1f - Math.abs(singlePerlin(seed + i, x, y, z));
2178            spike *= spike * amp;
2179            amp = Math.max(0f, Math.min(1f, spike * 2f));
2180            sum += (spike * ampBias);
2181            ampBias *= 2f;
2182            x *= lacunarity;
2183            y *= lacunarity;
2184            z *= lacunarity;
2185        }
2186        return sum / ((ampBias - 1f) * 0.5f) - 1f;
2187    }
2188
2189    public float getPerlin(float x, float y, float z) {
2190        return singlePerlin(seed, x * frequency, y * frequency, z * frequency);
2191    }
2192
2193    private float singlePerlin(int seed, float x, float y, float z) {
2194        int x0 = fastFloor(x);
2195        int y0 = fastFloor(y);
2196        int z0 = fastFloor(z);
2197        int x1 = x0 + 1;
2198        int y1 = y0 + 1;
2199        int z1 = z0 + 1;
2200
2201        float xs, ys, zs;
2202        switch (interpolation) {
2203            default:
2204            case LINEAR:
2205                xs = x - x0;
2206                ys = y - y0;
2207                zs = z - z0;
2208                break;
2209            case HERMITE:
2210                xs = hermiteInterpolator(x - x0);
2211                ys = hermiteInterpolator(y - y0);
2212                zs = hermiteInterpolator(z - z0);
2213                break;
2214            case QUINTIC:
2215                xs = quinticInterpolator(x - x0);
2216                ys = quinticInterpolator(y - y0);
2217                zs = quinticInterpolator(z - z0);
2218                break;
2219        }
2220
2221        final float xd0 = x - x0;
2222        final float yd0 = y - y0;
2223        final float zd0 = z - z0;
2224        final float xd1 = xd0 - 1;
2225        final float yd1 = yd0 - 1;
2226        final float zd1 = zd0 - 1;
2227
2228        final float xf00 = lerp(gradCoord3D(seed, x0, y0, z0, xd0, yd0, zd0), gradCoord3D(seed, x1, y0, z0, xd1, yd0, zd0), xs);
2229        final float xf10 = lerp(gradCoord3D(seed, x0, y1, z0, xd0, yd1, zd0), gradCoord3D(seed, x1, y1, z0, xd1, yd1, zd0), xs);
2230        final float xf01 = lerp(gradCoord3D(seed, x0, y0, z1, xd0, yd0, zd1), gradCoord3D(seed, x1, y0, z1, xd1, yd0, zd1), xs);
2231        final float xf11 = lerp(gradCoord3D(seed, x0, y1, z1, xd0, yd1, zd1), gradCoord3D(seed, x1, y1, z1, xd1, yd1, zd1), xs);
2232
2233        final float yf0 = lerp(xf00, xf10, ys);
2234        final float yf1 = lerp(xf01, xf11, ys);
2235
2236        return lerp(yf0, yf1, zs);
2237    }
2238    public float getPerlin(float x, float y, float z, float w) {
2239        return singlePerlin(seed, x * frequency, y * frequency, z * frequency, w * frequency);
2240    }
2241
2242    private float singlePerlin(int seed, float x, float y, float z, float w) {
2243        int x0 = fastFloor(x);
2244        int y0 = fastFloor(y);
2245        int z0 = fastFloor(z);
2246        int w0 = fastFloor(w);
2247        int x1 = x0 + 1;
2248        int y1 = y0 + 1;
2249        int z1 = z0 + 1;
2250        int w1 = w0 + 1;
2251
2252        float xs, ys, zs, ws;
2253        switch (interpolation) {
2254            default:
2255            case LINEAR:
2256                xs = x - x0;
2257                ys = y - y0;
2258                zs = z - z0;
2259                ws = w - w0;
2260                break;
2261            case HERMITE:
2262                xs = hermiteInterpolator(x - x0);
2263                ys = hermiteInterpolator(y - y0);
2264                zs = hermiteInterpolator(z - z0);
2265                ws = hermiteInterpolator(w - w0);
2266                break;
2267            case QUINTIC:
2268                xs = quinticInterpolator(x - x0);
2269                ys = quinticInterpolator(y - y0);
2270                zs = quinticInterpolator(z - z0);
2271                ws = quinticInterpolator(w - w0);
2272                break;
2273        }
2274
2275        final float xd0 = x - x0;
2276        final float yd0 = y - y0;
2277        final float zd0 = z - z0;
2278        final float wd0 = w - w0;
2279        final float xd1 = xd0 - 1;
2280        final float yd1 = yd0 - 1;
2281        final float zd1 = zd0 - 1;
2282        final float wd1 = wd0 - 1;
2283
2284        final float xf000 = lerp(gradCoord4D(seed, x0, y0, z0, w0, xd0, yd0, zd0, wd0), gradCoord4D(seed, x1, y0, z0, w0, xd1, yd0, zd0, wd0), xs);
2285        final float xf100 = lerp(gradCoord4D(seed, x0, y1, z0, w0, xd0, yd1, zd0, wd0), gradCoord4D(seed, x1, y1, z0, w0, xd1, yd1, zd0, wd0), xs);
2286        final float xf010 = lerp(gradCoord4D(seed, x0, y0, z1, w0, xd0, yd0, zd1, wd0), gradCoord4D(seed, x1, y0, z1, w0, xd1, yd0, zd1, wd0), xs);
2287        final float xf110 = lerp(gradCoord4D(seed, x0, y1, z1, w0, xd0, yd1, zd1, wd0), gradCoord4D(seed, x1, y1, z1, w0, xd1, yd1, zd1, wd0), xs);
2288        final float xf001 = lerp(gradCoord4D(seed, x0, y0, z0, w1, xd0, yd0, zd0, wd1), gradCoord4D(seed, x1, y0, z0, w1, xd1, yd0, zd0, wd1), xs);
2289        final float xf101 = lerp(gradCoord4D(seed, x0, y1, z0, w1, xd0, yd1, zd0, wd1), gradCoord4D(seed, x1, y1, z0, w1, xd1, yd1, zd0, wd1), xs);
2290        final float xf011 = lerp(gradCoord4D(seed, x0, y0, z1, w1, xd0, yd0, zd1, wd1), gradCoord4D(seed, x1, y0, z1, w1, xd1, yd0, zd1, wd1), xs);
2291        final float xf111 = lerp(gradCoord4D(seed, x0, y1, z1, w1, xd0, yd1, zd1, wd1), gradCoord4D(seed, x1, y1, z1, w1, xd1, yd1, zd1, wd1), xs);
2292
2293        final float yf00 = lerp(xf000, xf100, ys);
2294        final float yf10 = lerp(xf010, xf110, ys);
2295        final float yf01 = lerp(xf001, xf101, ys);
2296        final float yf11 = lerp(xf011, xf111, ys);
2297
2298        final float zf0 = lerp(yf00, yf10, zs);
2299        final float zf1 = lerp(yf01, yf11, zs);
2300        return lerp(zf0, zf1, ws) * 0.55f;
2301    }
2302    private float singlePerlinFractalFBM(float x, float y, float z, float w) {
2303        int seed = this.seed;
2304        float sum = singlePerlin(seed, x, y, z, w);
2305        float amp = 1;
2306
2307        for (int i = 1; i < octaves; i++) {
2308            x *= lacunarity;
2309            y *= lacunarity;
2310            z *= lacunarity;
2311            w *= lacunarity;
2312
2313            amp *= gain;
2314            sum += singlePerlin(++seed, x, y, z, w) * amp;
2315        }
2316
2317        return sum * fractalBounding;
2318    }
2319
2320    private float singlePerlinFractalBillow(float x, float y, float z, float w) {
2321        int seed = this.seed;
2322        float sum = Math.abs(singlePerlin(seed, x, y, z, w)) * 2 - 1;
2323        float amp = 1;
2324
2325        for (int i = 1; i < octaves; i++) {
2326            x *= lacunarity;
2327            y *= lacunarity;
2328            z *= lacunarity;
2329            w *= lacunarity;
2330
2331            amp *= gain;
2332            sum += (Math.abs(singlePerlin(++seed, x, y, z, w)) * 2 - 1) * amp;
2333        }
2334
2335        return sum * fractalBounding;
2336    }
2337
2338    private float singlePerlinFractalRidgedMulti(float x, float y, float z, float w) {
2339        int seed = this.seed;
2340        float sum = 0, amp = 1, ampBias = 1f, spike;
2341        for (int i = 0; i < octaves; i++) {
2342            spike = 1f - Math.abs(singlePerlin(seed + i, x, y,  z, w));
2343            spike *= spike * amp;
2344            amp = Math.max(0f, Math.min(1f, spike * 2f));
2345            sum += (spike * ampBias);
2346            ampBias *= 2f;
2347            x *= lacunarity;
2348            y *= lacunarity;
2349            z *= lacunarity;
2350            w *= lacunarity;
2351        }
2352        return sum / ((ampBias - 1f) * 0.5f) - 1f;
2353    }
2354
2355    public float getPerlinFractal(float x, float y) {
2356        x *= frequency;
2357        y *= frequency;
2358
2359        switch (fractalType) {
2360            case FBM:
2361                return singlePerlinFractalFBM(x, y);
2362            case BILLOW:
2363                return singlePerlinFractalBillow(x, y);
2364            case RIDGED_MULTI:
2365                return singlePerlinFractalRidgedMulti(x, y);
2366            default:
2367                return 0;
2368        }
2369    }
2370
2371    private float singlePerlinFractalFBM(float x, float y) {
2372        int seed = this.seed;
2373        float sum = singlePerlin(seed, x, y);
2374        float amp = 1;
2375
2376        for (int i = 1; i < octaves; i++) {
2377            x *= lacunarity;
2378            y *= lacunarity;
2379
2380            amp *= gain;
2381            sum += singlePerlin(++seed, x, y) * amp;
2382        }
2383
2384        return sum * fractalBounding;
2385    }
2386
2387    private float singlePerlinFractalBillow(float x, float y) {
2388        int seed = this.seed;
2389        float sum = Math.abs(singlePerlin(seed, x, y)) * 2 - 1;
2390        float amp = 1;
2391
2392        for (int i = 1; i < octaves; i++) {
2393            x *= lacunarity;
2394            y *= lacunarity;
2395
2396            amp *= gain;
2397            sum += (Math.abs(singlePerlin(++seed, x, y)) * 2 - 1) * amp;
2398        }
2399
2400        return sum * fractalBounding;
2401    }
2402
2403    private float singlePerlinFractalRidgedMulti(float x, float y) {
2404        int seed = this.seed;
2405        float sum = 0, amp = 1, ampBias = 1f, spike;
2406        for (int i = 0; i < octaves; i++) {
2407            spike = 1f - Math.abs(singlePerlin(seed + i, x, y));
2408            spike *= spike * amp;
2409            amp = Math.max(0f, Math.min(1f, spike * 2f));
2410            sum += (spike * ampBias);
2411            ampBias *= 2f;
2412            x *= lacunarity;
2413            y *= lacunarity;
2414        }
2415        return sum / ((ampBias - 1f) * 0.5f) - 1f;
2416    }
2417
2418    public float getPerlin(float x, float y) {
2419        return singlePerlin(seed, x * frequency, y * frequency);
2420    }
2421
2422    private float singlePerlin(int seed, float x, float y) {
2423        int x0 = fastFloor(x);
2424        int y0 = fastFloor(y);
2425        int x1 = x0 + 1;
2426        int y1 = y0 + 1;
2427
2428        float xs, ys;
2429        switch (interpolation) {
2430            default:
2431            case LINEAR:
2432                xs = x - x0;
2433                ys = y - y0;
2434                break;
2435            case HERMITE:
2436                xs = hermiteInterpolator(x - x0);
2437                ys = hermiteInterpolator(y - y0);
2438                break;
2439            case QUINTIC:
2440                xs = quinticInterpolator(x - x0);
2441                ys = quinticInterpolator(y - y0);
2442                break;
2443        }
2444
2445        float xd0 = x - x0;
2446        float yd0 = y - y0;
2447        float xd1 = xd0 - 1;
2448        float yd1 = yd0 - 1;
2449
2450        float xf0 = lerp(gradCoord2D(seed, x0, y0, xd0, yd0), gradCoord2D(seed, x1, y0, xd1, yd0), xs);
2451        float xf1 = lerp(gradCoord2D(seed, x0, y1, xd0, yd1), gradCoord2D(seed, x1, y1, xd1, yd1), xs);
2452
2453        return lerp(xf0, xf1, ys);
2454    }
2455    public float getPerlin(float x, float y, float z, float w, float u, float v) {
2456        return singlePerlin(seed, x * frequency, y * frequency, z * frequency, w * frequency, u * frequency, v * frequency);
2457    }
2458
2459    private float singlePerlin(int seed, float x, float y, float z, float w, float u, float v) {
2460        int x0 = fastFloor(x);
2461        int y0 = fastFloor(y);
2462        int z0 = fastFloor(z);
2463        int w0 = fastFloor(w);
2464        int u0 = fastFloor(u);
2465        int v0 = fastFloor(v);
2466        int x1 = x0 + 1;
2467        int y1 = y0 + 1;
2468        int z1 = z0 + 1;
2469        int w1 = w0 + 1;
2470        int u1 = u0 + 1;
2471        int v1 = v0 + 1;
2472
2473        float xs, ys, zs, ws, us, vs;
2474        switch (interpolation) {
2475            default:
2476            case LINEAR:
2477                xs = x - x0;
2478                ys = y - y0;
2479                zs = z - z0;
2480                ws = w - w0;
2481                us = u - u0;
2482                vs = v - v0;
2483                break;
2484            case HERMITE:
2485                xs = hermiteInterpolator(x - x0);
2486                ys = hermiteInterpolator(y - y0);
2487                zs = hermiteInterpolator(z - z0);
2488                ws = hermiteInterpolator(w - w0);
2489                us = hermiteInterpolator(u - u0);
2490                vs = hermiteInterpolator(v - v0);
2491                break;
2492            case QUINTIC:
2493                xs = quinticInterpolator(x - x0);
2494                ys = quinticInterpolator(y - y0);
2495                zs = quinticInterpolator(z - z0);
2496                ws = quinticInterpolator(w - w0);
2497                us = quinticInterpolator(u - u0);
2498                vs = quinticInterpolator(v - v0);
2499                break;
2500        }
2501
2502        final float xd0 = x - x0;
2503        final float yd0 = y - y0;
2504        final float zd0 = z - z0;
2505        final float wd0 = w - w0;
2506        final float ud0 = u - u0;
2507        final float vd0 = v - v0;
2508        final float xd1 = xd0 - 1;
2509        final float yd1 = yd0 - 1;
2510        final float zd1 = zd0 - 1;
2511        final float wd1 = wd0 - 1;
2512        final float ud1 = ud0 - 1;
2513        final float vd1 = vd0 - 1;
2514
2515        final float xf00000 = lerp(gradCoord6D(seed, x0, y0, z0, w0, u0, v0, xd0, yd0, zd0, wd0, ud0, vd0), gradCoord6D(seed, x1, y0, z0, w0, u0, v0, xd1, yd0, zd0, wd0, ud0, vd0), xs);
2516        final float xf10000 = lerp(gradCoord6D(seed, x0, y1, z0, w0, u0, v0, xd0, yd1, zd0, wd0, ud0, vd0), gradCoord6D(seed, x1, y1, z0, w0, u0, v0, xd1, yd1, zd0, wd0, ud0, vd0), xs);
2517        final float xf01000 = lerp(gradCoord6D(seed, x0, y0, z1, w0, u0, v0, xd0, yd0, zd1, wd0, ud0, vd0), gradCoord6D(seed, x1, y0, z1, w0, u0, v0, xd1, yd0, zd1, wd0, ud0, vd0), xs);
2518        final float xf11000 = lerp(gradCoord6D(seed, x0, y1, z1, w0, u0, v0, xd0, yd1, zd1, wd0, ud0, vd0), gradCoord6D(seed, x1, y1, z1, w0, u0, v0, xd1, yd1, zd1, wd0, ud0, vd0), xs);
2519        final float xf00100 = lerp(gradCoord6D(seed, x0, y0, z0, w1, u0, v0, xd0, yd0, zd0, wd1, ud0, vd0), gradCoord6D(seed, x1, y0, z0, w1, u0, v0, xd1, yd0, zd0, wd1, ud0, vd0), xs);
2520        final float xf10100 = lerp(gradCoord6D(seed, x0, y1, z0, w1, u0, v0, xd0, yd1, zd0, wd1, ud0, vd0), gradCoord6D(seed, x1, y1, z0, w1, u0, v0, xd1, yd1, zd0, wd1, ud0, vd0), xs);
2521        final float xf01100 = lerp(gradCoord6D(seed, x0, y0, z1, w1, u0, v0, xd0, yd0, zd1, wd1, ud0, vd0), gradCoord6D(seed, x1, y0, z1, w1, u0, v0, xd1, yd0, zd1, wd1, ud0, vd0), xs);
2522        final float xf11100 = lerp(gradCoord6D(seed, x0, y1, z1, w1, u0, v0, xd0, yd1, zd1, wd1, ud0, vd0), gradCoord6D(seed, x1, y1, z1, w1, u0, v0, xd1, yd1, zd1, wd1, ud0, vd0), xs);
2523
2524        final float xf00010 = lerp(gradCoord6D(seed, x0, y0, z0, w0, u1, v0, xd0, yd0, zd0, wd0, ud1, vd0), gradCoord6D(seed, x1, y0, z0, w0, u1, v0, xd1, yd0, zd0, wd0, ud1, vd0), xs);
2525        final float xf10010 = lerp(gradCoord6D(seed, x0, y1, z0, w0, u1, v0, xd0, yd1, zd0, wd0, ud1, vd0), gradCoord6D(seed, x1, y1, z0, w0, u1, v0, xd1, yd1, zd0, wd0, ud1, vd0), xs);
2526        final float xf01010 = lerp(gradCoord6D(seed, x0, y0, z1, w0, u1, v0, xd0, yd0, zd1, wd0, ud1, vd0), gradCoord6D(seed, x1, y0, z1, w0, u1, v0, xd1, yd0, zd1, wd0, ud1, vd0), xs);
2527        final float xf11010 = lerp(gradCoord6D(seed, x0, y1, z1, w0, u1, v0, xd0, yd1, zd1, wd0, ud1, vd0), gradCoord6D(seed, x1, y1, z1, w0, u1, v0, xd1, yd1, zd1, wd0, ud1, vd0), xs);
2528        final float xf00110 = lerp(gradCoord6D(seed, x0, y0, z0, w1, u1, v0, xd0, yd0, zd0, wd1, ud1, vd0), gradCoord6D(seed, x1, y0, z0, w1, u1, v0, xd1, yd0, zd0, wd1, ud1, vd0), xs);
2529        final float xf10110 = lerp(gradCoord6D(seed, x0, y1, z0, w1, u1, v0, xd0, yd1, zd0, wd1, ud1, vd0), gradCoord6D(seed, x1, y1, z0, w1, u1, v0, xd1, yd1, zd0, wd1, ud1, vd0), xs);
2530        final float xf01110 = lerp(gradCoord6D(seed, x0, y0, z1, w1, u1, v0, xd0, yd0, zd1, wd1, ud1, vd0), gradCoord6D(seed, x1, y0, z1, w1, u1, v0, xd1, yd0, zd1, wd1, ud1, vd0), xs);
2531        final float xf11110 = lerp(gradCoord6D(seed, x0, y1, z1, w1, u1, v0, xd0, yd1, zd1, wd1, ud1, vd0), gradCoord6D(seed, x1, y1, z1, w1, u1, v0, xd1, yd1, zd1, wd1, ud1, vd0), xs);
2532
2533        final float xf00001 = lerp(gradCoord6D(seed, x0, y0, z0, w0, u0, v1, xd0, yd0, zd0, wd0, ud0, vd1), gradCoord6D(seed, x1, y0, z0, w0, u0, v1, xd1, yd0, zd0, wd0, ud0, vd1), xs);
2534        final float xf10001 = lerp(gradCoord6D(seed, x0, y1, z0, w0, u0, v1, xd0, yd1, zd0, wd0, ud0, vd1), gradCoord6D(seed, x1, y1, z0, w0, u0, v1, xd1, yd1, zd0, wd0, ud0, vd1), xs);
2535        final float xf01001 = lerp(gradCoord6D(seed, x0, y0, z1, w0, u0, v1, xd0, yd0, zd1, wd0, ud0, vd1), gradCoord6D(seed, x1, y0, z1, w0, u0, v1, xd1, yd0, zd1, wd0, ud0, vd1), xs);
2536        final float xf11001 = lerp(gradCoord6D(seed, x0, y1, z1, w0, u0, v1, xd0, yd1, zd1, wd0, ud0, vd1), gradCoord6D(seed, x1, y1, z1, w0, u0, v1, xd1, yd1, zd1, wd0, ud0, vd1), xs);
2537        final float xf00101 = lerp(gradCoord6D(seed, x0, y0, z0, w1, u0, v1, xd0, yd0, zd0, wd1, ud0, vd1), gradCoord6D(seed, x1, y0, z0, w1, u0, v1, xd1, yd0, zd0, wd1, ud0, vd1), xs);
2538        final float xf10101 = lerp(gradCoord6D(seed, x0, y1, z0, w1, u0, v1, xd0, yd1, zd0, wd1, ud0, vd1), gradCoord6D(seed, x1, y1, z0, w1, u0, v1, xd1, yd1, zd0, wd1, ud0, vd1), xs);
2539        final float xf01101 = lerp(gradCoord6D(seed, x0, y0, z1, w1, u0, v1, xd0, yd0, zd1, wd1, ud0, vd1), gradCoord6D(seed, x1, y0, z1, w1, u0, v1, xd1, yd0, zd1, wd1, ud0, vd1), xs);
2540        final float xf11101 = lerp(gradCoord6D(seed, x0, y1, z1, w1, u0, v1, xd0, yd1, zd1, wd1, ud0, vd1), gradCoord6D(seed, x1, y1, z1, w1, u0, v1, xd1, yd1, zd1, wd1, ud0, vd1), xs);
2541
2542        final float xf00011 = lerp(gradCoord6D(seed, x0, y0, z0, w0, u1, v1, xd0, yd0, zd0, wd0, ud1, vd1), gradCoord6D(seed, x1, y0, z0, w0, u1, v1, xd1, yd0, zd0, wd0, ud1, vd1), xs);
2543        final float xf10011 = lerp(gradCoord6D(seed, x0, y1, z0, w0, u1, v1, xd0, yd1, zd0, wd0, ud1, vd1), gradCoord6D(seed, x1, y1, z0, w0, u1, v1, xd1, yd1, zd0, wd0, ud1, vd1), xs);
2544        final float xf01011 = lerp(gradCoord6D(seed, x0, y0, z1, w0, u1, v1, xd0, yd0, zd1, wd0, ud1, vd1), gradCoord6D(seed, x1, y0, z1, w0, u1, v1, xd1, yd0, zd1, wd0, ud1, vd1), xs);
2545        final float xf11011 = lerp(gradCoord6D(seed, x0, y1, z1, w0, u1, v1, xd0, yd1, zd1, wd0, ud1, vd1), gradCoord6D(seed, x1, y1, z1, w0, u1, v1, xd1, yd1, zd1, wd0, ud1, vd1), xs);
2546        final float xf00111 = lerp(gradCoord6D(seed, x0, y0, z0, w1, u1, v1, xd0, yd0, zd0, wd1, ud1, vd1), gradCoord6D(seed, x1, y0, z0, w1, u1, v1, xd1, yd0, zd0, wd1, ud1, vd1), xs);
2547        final float xf10111 = lerp(gradCoord6D(seed, x0, y1, z0, w1, u1, v1, xd0, yd1, zd0, wd1, ud1, vd1), gradCoord6D(seed, x1, y1, z0, w1, u1, v1, xd1, yd1, zd0, wd1, ud1, vd1), xs);
2548        final float xf01111 = lerp(gradCoord6D(seed, x0, y0, z1, w1, u1, v1, xd0, yd0, zd1, wd1, ud1, vd1), gradCoord6D(seed, x1, y0, z1, w1, u1, v1, xd1, yd0, zd1, wd1, ud1, vd1), xs);
2549        final float xf11111 = lerp(gradCoord6D(seed, x0, y1, z1, w1, u1, v1, xd0, yd1, zd1, wd1, ud1, vd1), gradCoord6D(seed, x1, y1, z1, w1, u1, v1, xd1, yd1, zd1, wd1, ud1, vd1), xs);
2550
2551        final float yf0000 = lerp(xf00000, xf10000, ys);
2552        final float yf1000 = lerp(xf01000, xf11000, ys);
2553        final float yf0100 = lerp(xf00100, xf10100, ys);
2554        final float yf1100 = lerp(xf01100, xf11100, ys);
2555
2556        final float yf0010 = lerp(xf00010, xf10010, ys);
2557        final float yf1010 = lerp(xf01010, xf11010, ys);
2558        final float yf0110 = lerp(xf00110, xf10110, ys);
2559        final float yf1110 = lerp(xf01110, xf11110, ys);
2560
2561        final float yf0001 = lerp(xf00001, xf10001, ys);
2562        final float yf1001 = lerp(xf01001, xf11001, ys);
2563        final float yf0101 = lerp(xf00101, xf10101, ys);
2564        final float yf1101 = lerp(xf01101, xf11101, ys);
2565
2566        final float yf0011 = lerp(xf00011, xf10011, ys);
2567        final float yf1011 = lerp(xf01011, xf11011, ys);
2568        final float yf0111 = lerp(xf00111, xf10111, ys);
2569        final float yf1111 = lerp(xf01111, xf11111, ys);
2570
2571        final float zf000 = lerp(yf0000, yf1000, zs);
2572        final float zf100 = lerp(yf0100, yf1100, zs);
2573
2574        final float zf010 = lerp(yf0010, yf1010, zs);
2575        final float zf110 = lerp(yf0110, yf1110, zs);
2576
2577        final float zf001 = lerp(yf0001, yf1001, zs);
2578        final float zf101 = lerp(yf0101, yf1101, zs);
2579
2580        final float zf011 = lerp(yf0011, yf1011, zs);
2581        final float zf111 = lerp(yf0111, yf1111, zs);
2582
2583        final float wf00 = lerp(zf000, zf100, ws);
2584        final float wf10 = lerp(zf010, zf110, ws);
2585        final float wf01 = lerp(zf001, zf101, ws);
2586        final float wf11 = lerp(zf011, zf111, ws);
2587
2588        final float uf0 = lerp(wf00, wf10, us);
2589        final float uf1 = lerp(wf01, wf11, us);
2590
2591        return lerp(uf0, uf1, vs) * 1.75f;
2592    }
2593    private float singlePerlinFractalFBM(float x, float y, float z, float w, float u, float v) {
2594        int seed = this.seed;
2595        float sum = singlePerlin(seed, x, y, z, w, u, v);
2596        float amp = 1;
2597
2598        for (int i = 1; i < octaves; i++) {
2599            x *= lacunarity;
2600            y *= lacunarity;
2601            z *= lacunarity;
2602            w *= lacunarity;
2603            u *= lacunarity;
2604            v *= lacunarity;
2605
2606            amp *= gain;
2607            sum += singlePerlin(++seed, x, y, z, w, u, v) * amp;
2608        }
2609
2610        return sum * fractalBounding;
2611    }
2612
2613    private float singlePerlinFractalBillow(float x, float y, float z, float w, float u, float v) {
2614        int seed = this.seed;
2615        float sum = Math.abs(singlePerlin(seed, x, y, z, w, u, v)) * 2 - 1;
2616        float amp = 1;
2617
2618        for (int i = 1; i < octaves; i++) {
2619            x *= lacunarity;
2620            y *= lacunarity;
2621            z *= lacunarity;
2622            w *= lacunarity;
2623            u *= lacunarity;
2624            v *= lacunarity;
2625
2626            amp *= gain;
2627            sum += (Math.abs(singlePerlin(++seed, x, y, z, w, u, v)) * 2 - 1) * amp;
2628        }
2629
2630        return sum * fractalBounding;
2631    }
2632
2633    private float singlePerlinFractalRidgedMulti(float x, float y, float z, float w, float u, float v) {
2634        int seed = this.seed;
2635        float sum = 0, amp = 1, ampBias = 1f, spike;
2636        for (int i = 0; i < octaves; i++) {
2637            spike = 1f - Math.abs(singlePerlin(seed + i, x, y, z, w, u, v));
2638            spike *= spike * amp;
2639            amp = Math.max(0f, Math.min(1f, spike * 2f));
2640            sum += (spike * ampBias);
2641            ampBias *= 2f;
2642            x *= lacunarity;
2643            y *= lacunarity;
2644            z *= lacunarity;
2645            w *= lacunarity;
2646            u *= lacunarity;
2647            v *= lacunarity;
2648        }
2649        return sum / ((ampBias - 1f) * 0.5f) - 1f;
2650    }
2651
2652    // Simplex Noise
2653    public float getSimplexFractal(float x, float y, float z) {
2654        x *= frequency;
2655        y *= frequency;
2656        z *= frequency;
2657
2658        switch (fractalType) {
2659            case FBM:
2660                return singleSimplexFractalFBM(x, y, z);
2661            case BILLOW:
2662                return singleSimplexFractalBillow(x, y, z);
2663            case RIDGED_MULTI:
2664                return singleSimplexFractalRidgedMulti(x, y, z);
2665            default:
2666                return 0;
2667        }
2668    }
2669
2670    /**
2671     * Generates ridged-multi simplex noise with the given amount of octaves and default frequency (0.03125), lacunarity
2672     * (2) and gain (0.5) in 3D.
2673     * @param x
2674     * @param y
2675     * @param z
2676     * @param seed
2677     * @param octaves
2678     * @return noise as a float between -1f and 1f
2679     */
2680    public float layered3D(float x, float y, float z, int seed, int octaves)
2681    {
2682        x *= 0.03125f;
2683        y *= 0.03125f;
2684        z *= 0.03125f;
2685
2686        float sum = 1 - Math.abs(singleSimplex(seed, x, y, z));
2687        float amp = 1;
2688
2689        for (int i = 1; i < octaves; i++) {
2690            x *= 2f;
2691            y *= 2f;
2692            z *= 2f;
2693
2694            amp *= 0.5f;
2695            sum -= (1 - Math.abs(singleSimplex(seed + i, x, y, z))) * amp;
2696        }
2697        amp = gain;
2698        float ampFractal = 1;
2699        for (int i = 1; i < octaves; i++) {
2700            ampFractal += amp;
2701            amp *= gain;
2702        }
2703        return sum / ampFractal;
2704    }
2705    /**
2706     * Generates ridged-multi simplex noise with the given amount of octaves and default frequency (0.03125), lacunarity
2707     * (2) and gain (0.5) in 3D.
2708     * @param x
2709     * @param y
2710     * @param z
2711     * @param seed
2712     * @param octaves
2713     * @return noise as a float between -1f and 1f
2714     */
2715    public float layered3D(float x, float y, float z, int seed, int octaves, float frequency)
2716    {
2717        x *= frequency;
2718        y *= frequency;
2719        z *= frequency;
2720
2721        float sum = singleSimplex(seed, x, y, z);
2722        float amp = 1;
2723
2724        for (int i = 1; i < octaves; i++) {
2725            x *= 2f;
2726            y *= 2f;
2727            z *= 2f;
2728
2729            amp *= 0.5f;
2730            sum += singleSimplex(seed + i, x, y, z) * amp;
2731        }
2732        amp = gain;
2733        float ampFractal = 1;
2734        for (int i = 1; i < octaves; i++) {
2735            ampFractal += amp;
2736            amp *= gain;
2737        }
2738        return sum / ampFractal;
2739    }
2740    /**
2741     * Generates layered simplex noise with the given amount of octaves and specified lacunarity (the amount of
2742     * frequency change between octaves) and gain (0.5) in 3D.
2743     * @param x
2744     * @param y
2745     * @param z
2746     * @param seed
2747     * @param octaves
2748     * @param frequency
2749     * @param lacunarity
2750     * @return noise as a float between -1f and 1f
2751     */
2752    public float layered3D(float x, float y, float z, int seed, int octaves, float frequency, float lacunarity)
2753    {
2754        x *= frequency;
2755        y *= frequency;
2756        z *= frequency;
2757
2758        float sum = singleSimplex(seed, x, y, z);
2759        float amp = 1;
2760
2761        for (int i = 1; i < octaves; i++) {
2762            x *= lacunarity;
2763            y *= lacunarity;
2764            z *= lacunarity;
2765
2766            amp *= 0.5f;
2767            sum += singleSimplex(seed + i, x, y, z) * amp;
2768        }
2769        amp = gain;
2770        float ampFractal = 1;
2771        for (int i = 1; i < octaves; i++) {
2772            ampFractal += amp;
2773            amp *= gain;
2774        }
2775        return sum / ampFractal;
2776    }
2777
2778    /**
2779     * Generates layered simplex noise with the given amount of octaves and specified lacunarity (the amount of
2780     * frequency change between octaves) and gain (loosely, how much to emphasize lower-frequency octaves) in 3D.
2781     * @param x
2782     * @param y
2783     * @param z
2784     * @param seed
2785     * @param octaves
2786     * @param frequency
2787     * @param lacunarity
2788     * @param gain
2789     * @return noise as a float between -1f and 1f
2790     */
2791    public float layered3D(float x, float y, float z, int seed, int octaves, float frequency, float lacunarity, float gain)
2792    {
2793        x *= frequency;
2794        y *= frequency;
2795        z *= frequency;
2796
2797        float sum = singleSimplex(seed, x, y, z);
2798        float amp = 1;
2799
2800        for (int i = 1; i < octaves; i++) {
2801            x *= lacunarity;
2802            y *= lacunarity;
2803            z *= lacunarity;
2804
2805            amp *= gain;
2806            sum += singleSimplex(seed + i, x, y, z) * amp;
2807        }
2808        amp = gain;
2809        float ampFractal = 1;
2810        for (int i = 1; i < octaves; i++) {
2811            ampFractal += amp;
2812            amp *= gain;
2813        }
2814        return sum / ampFractal;
2815    }
2816
2817    private float singleSimplexFractalFBM(float x, float y, float z) {
2818        int seed = this.seed;
2819        float sum = singleSimplex(seed, x, y, z);
2820        float amp = 1;
2821
2822        for (int i = 1; i < octaves; i++) {
2823            x *= lacunarity;
2824            y *= lacunarity;
2825            z *= lacunarity;
2826
2827            amp *= gain;
2828            sum += singleSimplex(seed + i, x, y, z) * amp;
2829        }
2830
2831        return sum * fractalBounding;
2832    }
2833
2834    private float singleSimplexFractalBillow(float x, float y, float z) {
2835        int seed = this.seed;
2836        float sum = Math.abs(singleSimplex(seed, x, y, z)) * 2 - 1;
2837        float amp = 1;
2838
2839        for (int i = 1; i < octaves; i++) {
2840            x *= lacunarity;
2841            y *= lacunarity;
2842            z *= lacunarity;
2843
2844            amp *= gain;
2845            sum += (Math.abs(singleSimplex(seed + i, x, y, z)) * 2 - 1) * amp;
2846        }
2847
2848        return sum * fractalBounding;
2849    }
2850
2851    /**
2852     * Generates ridged-multi simplex noise with the given amount of octaves and default frequency (0.03125), lacunarity
2853     * (2) and gain (0.5).
2854     * @param x
2855     * @param y
2856     * @param z
2857     * @param seed
2858     * @param octaves
2859     * @return noise as a float between -1f and 1f
2860     */
2861    public float ridged3D(float x, float y, float z, int seed, int octaves)
2862    {
2863        return ridged3D(x, y, z, seed, octaves, 0.03125f, 2f);
2864    }
2865    /**
2866     * Generates ridged-multi simplex noise with the given amount of octaves, specified frequency, and the default
2867     * lacunarity (2) and gain (0.5).
2868     * @param x
2869     * @param y
2870     * @param z
2871     * @param seed
2872     * @param octaves
2873     * @return noise as a float between -1f and 1f
2874     */
2875    public float ridged3D(float x, float y, float z, int seed, int octaves, float frequency)
2876    {
2877        return ridged3D(x, y, z, seed, octaves, frequency, 2f);
2878    }
2879    /**
2880     * Generates ridged-multi simplex noise with the given amount of octaves and specified lacunarity (the amount of
2881     * frequency change between octaves); gain is not used.
2882     * @param x
2883     * @param y
2884     * @param z
2885     * @param seed any int
2886     * @param octaves how many "layers of detail" to generate; at least 1, but note this slows down with many octaves
2887     * @param frequency often about {@code 1f / 32f}, but generally adjusted for the use case
2888     * @param lacunarity when {@code octaves} is 2 or more, this affects the change between layers
2889     * @return noise as a float between -1f and 1f
2890     */
2891    public float ridged3D(float x, float y, float z, int seed, int octaves, float frequency, float lacunarity)
2892    {
2893        x *= frequency;
2894        y *= frequency;
2895        z *= frequency;
2896
2897        float sum = 0, amp = 1, ampBias = 1f, spike;
2898        for (int i = 0; i < octaves; i++) {
2899            spike = 1f - Math.abs(singleSimplex(seed + i, x, y, z));
2900            spike *= spike * amp;
2901            amp = Math.max(0f, Math.min(1f, spike * 2f));
2902            sum += (spike * ampBias);
2903            ampBias *= 2f;
2904            x *= lacunarity;
2905            y *= lacunarity;
2906            z *= lacunarity;
2907        }
2908        return sum / ((ampBias - 1f) * 0.5f) - 1f;
2909    }
2910
2911    private float singleSimplexFractalRidgedMulti(float x, float y, float z) {
2912        int seed = this.seed;
2913        float sum = 0, amp = 1, ampBias = 1f, spike;
2914        for (int i = 0; i < octaves; i++) {
2915            spike = 1f - Math.abs(singleSimplex(seed + i, x, y, z));
2916            spike *= spike * amp;
2917            amp = Math.max(0f, Math.min(1f, spike * 2f));
2918            sum += (spike * ampBias);
2919            ampBias *= 2f;
2920            x *= lacunarity;
2921            y *= lacunarity;
2922            z *= lacunarity;
2923        }
2924        return sum / ((ampBias - 1f) * 0.5f) - 1f;
2925    }
2926
2927    public float getSimplex(float x, float y, float z) {
2928        return singleSimplex(seed, x * frequency, y * frequency, z * frequency);
2929    }
2930
2931    private final static float F3 = (1f / 3f);
2932    private final static float G3 = (1f / 6f);
2933    private final static float G33 = -0.5f;
2934
2935    public float singleSimplex(int seed, float x, float y, float z) {
2936        float t = (x + y + z) * F3;
2937        int i = fastFloor(x + t);
2938        int j = fastFloor(y + t);
2939        int k = fastFloor(z + t);
2940
2941        t = (i + j + k) * G3;
2942        float x0 = x - (i - t);
2943        float y0 = y - (j - t);
2944        float z0 = z - (k - t);
2945
2946        int i1, j1, k1;
2947        int i2, j2, k2;
2948
2949        if (x0 >= y0) {
2950            if (y0 >= z0) {
2951                i1 = 1;
2952                j1 = 0;
2953                k1 = 0;
2954                i2 = 1;
2955                j2 = 1;
2956                k2 = 0;
2957            } else if (x0 >= z0) {
2958                i1 = 1;
2959                j1 = 0;
2960                k1 = 0;
2961                i2 = 1;
2962                j2 = 0;
2963                k2 = 1;
2964            } else // x0 < z0
2965            {
2966                i1 = 0;
2967                j1 = 0;
2968                k1 = 1;
2969                i2 = 1;
2970                j2 = 0;
2971                k2 = 1;
2972            }
2973        } else // x0 < y0
2974        {
2975            if (y0 < z0) {
2976                i1 = 0;
2977                j1 = 0;
2978                k1 = 1;
2979                i2 = 0;
2980                j2 = 1;
2981                k2 = 1;
2982            } else if (x0 < z0) {
2983                i1 = 0;
2984                j1 = 1;
2985                k1 = 0;
2986                i2 = 0;
2987                j2 = 1;
2988                k2 = 1;
2989            } else // x0 >= z0
2990            {
2991                i1 = 0;
2992                j1 = 1;
2993                k1 = 0;
2994                i2 = 1;
2995                j2 = 1;
2996                k2 = 0;
2997            }
2998        }
2999
3000        float x1 = x0 - i1 + G3;
3001        float y1 = y0 - j1 + G3;
3002        float z1 = z0 - k1 + G3;
3003        float x2 = x0 - i2 + F3;
3004        float y2 = y0 - j2 + F3;
3005        float z2 = z0 - k2 + F3;
3006        float x3 = x0 + G33;
3007        float y3 = y0 + G33;
3008        float z3 = z0 + G33;
3009
3010        float n = 0;
3011
3012        t = 0.6f - x0 * x0 - y0 * y0 - z0 * z0;
3013        if (t > 0) {
3014            t *= t;
3015            n += t * t * gradCoord3D(seed, i, j, k, x0, y0, z0);
3016        }
3017
3018        t = 0.6f - x1 * x1 - y1 * y1 - z1 * z1;
3019        if (t > 0) {
3020            t *= t;
3021            n += t * t * gradCoord3D(seed, i + i1, j + j1, k + k1, x1, y1, z1);
3022        }
3023
3024        t = 0.6f - x2 * x2 - y2 * y2 - z2 * z2;
3025        if (t > 0) {
3026            t *= t;
3027            n += t * t * gradCoord3D(seed, i + i2, j + j2, k + k2, x2, y2, z2);
3028        }
3029
3030        t = 0.6f - x3 * x3 - y3 * y3 - z3 * z3;
3031        if (t > 0)  {
3032            t *= t;
3033            n += t * t * gradCoord3D(seed, i + 1, j + 1, k + 1, x3, y3, z3);
3034        }
3035
3036        return 31.5f * n;
3037    }
3038
3039    public float getSimplexFractal(float x, float y) {
3040        x *= frequency;
3041        y *= frequency;
3042
3043        switch (fractalType) {
3044            case FBM:
3045                return singleSimplexFractalFBM(x, y);
3046            case BILLOW:
3047                return singleSimplexFractalBillow(x, y);
3048            case RIDGED_MULTI:
3049                return singleSimplexFractalRidgedMulti(x, y);
3050            default:
3051                return 0;
3052        }
3053    }
3054
3055    /**
3056     * Generates ridged-multi simplex noise with the given amount of octaves and default frequency (0.03125), lacunarity
3057     * (2) and gain (0.5) in 2D.
3058     * @param x
3059     * @param y
3060     * @param seed
3061     * @param octaves
3062     * @return noise as a float between -1f and 1f
3063     */
3064    public float layered2D(float x, float y, int seed, int octaves)
3065    {
3066        x *= 0.03125f;
3067        y *= 0.03125f;
3068
3069        float sum = 1 - Math.abs(singleSimplex(seed, x, y));
3070        float amp = 1;
3071
3072        for (int i = 1; i < octaves; i++) {
3073            x *= 2f;
3074            y *= 2f;
3075
3076            amp *= 0.5f;
3077            sum -= (1 - Math.abs(singleSimplex(seed + i, x, y))) * amp;
3078        }
3079        amp = gain;
3080        float ampFractal = 1;
3081        for (int i = 1; i < octaves; i++) {
3082            ampFractal += amp;
3083            amp *= gain;
3084        }
3085        return sum / ampFractal;
3086    }
3087    /**
3088     * Generates ridged-multi simplex noise with the given amount of octaves and default frequency (0.03125), lacunarity
3089     * (2) and gain (0.5) in 2D.
3090     * @param x
3091     * @param y
3092     * @param seed
3093     * @param octaves
3094     * @return noise as a float between -1f and 1f
3095     */
3096    public float layered2D(float x, float y, int seed, int octaves, float frequency)
3097    {
3098        x *= frequency;
3099        y *= frequency;
3100
3101        float sum = singleSimplex(seed, x, y);
3102        float amp = 1;
3103
3104        for (int i = 1; i < octaves; i++) {
3105            x *= 2f;
3106            y *= 2f;
3107
3108            amp *= 0.5f;
3109            sum += singleSimplex(seed + i, x, y) * amp;
3110        }
3111        amp = gain;
3112        float ampFractal = 1;
3113        for (int i = 1; i < octaves; i++) {
3114            ampFractal += amp;
3115            amp *= gain;
3116        }
3117        return sum / ampFractal;
3118    }
3119    /**
3120     * Generates layered simplex noise with the given amount of octaves and specified lacunarity (the amount of
3121     * frequency change between octaves) and gain (0.5) in D.
3122     * @param x
3123     * @param y
3124     * @param seed
3125     * @param octaves
3126     * @return noise as a float between -1f and 1f
3127     */
3128    public float layered2D(float x, float y, int seed, int octaves, float frequency, float lacunarity)
3129    {
3130        x *= frequency;
3131        y *= frequency;
3132
3133        float sum = singleSimplex(seed, x, y);
3134        float amp = 1;
3135
3136        for (int i = 1; i < octaves; i++) {
3137            x *= lacunarity;
3138            y *= lacunarity;
3139
3140            amp *= 0.5f;
3141            sum += singleSimplex(seed + i, x, y) * amp;
3142        }
3143        amp = gain;
3144        float ampFractal = 1;
3145        for (int i = 1; i < octaves; i++) {
3146            ampFractal += amp;
3147            amp *= gain;
3148        }
3149        return sum / ampFractal;
3150    }
3151
3152    /**
3153     * Generates layered simplex noise with the given amount of octaves and specified lacunarity (the amount of
3154     * frequency change between octaves) and gain (loosely, how much to emphasize lower-frequency octaves) in 2D.
3155     * @param x
3156     * @param y
3157     * @param seed
3158     * @param octaves
3159     * @return noise as a float between -1f and 1f
3160     */
3161    public float layered2D(float x, float y, int seed, int octaves, float frequency, float lacunarity, float gain)
3162    {
3163        x *= frequency;
3164        y *= frequency;
3165
3166        float sum = singleSimplex(seed, x, y);
3167        float amp = 1;
3168
3169        for (int i = 1; i < octaves; i++) {
3170            x *= lacunarity;
3171            y *= lacunarity;
3172
3173            amp *= gain;
3174            sum += singleSimplex(seed + i, x, y) * amp;
3175        }
3176        amp = gain;
3177        float ampFractal = 1;
3178        for (int i = 1; i < octaves; i++) {
3179            ampFractal += amp;
3180            amp *= gain;
3181        }
3182        return sum / ampFractal;
3183    }
3184
3185    private float singleSimplexFractalFBM(float x, float y) {
3186        int seed = this.seed;
3187        float sum = singleSimplex(seed, x, y);
3188        float amp = 1;
3189
3190        for (int i = 1; i < octaves; i++) {
3191            x *= lacunarity;
3192            y *= lacunarity;
3193
3194            amp *= gain;
3195            sum += singleSimplex(seed + i, x, y) * amp;
3196        }
3197
3198        return sum * fractalBounding;
3199    }
3200
3201    private float singleSimplexFractalBillow(float x, float y) {
3202        int seed = this.seed;
3203        float sum = Math.abs(singleSimplex(seed, x, y)) * 2 - 1;
3204        float amp = 1;
3205
3206        for (int i = 1; i < octaves; i++) {
3207            x *= lacunarity;
3208            y *= lacunarity;
3209
3210            amp *= gain;
3211            sum += (Math.abs(singleSimplex(++seed, x, y)) * 2 - 1) * amp;
3212        }
3213
3214        return sum * fractalBounding;
3215    }
3216
3217    /**
3218     * Generates ridged-multi simplex noise with the given amount of octaves and default frequency (0.03125), lacunarity
3219     * (2) and gain (0.5).
3220     * @param x
3221     * @param y
3222     * @param seed
3223     * @param octaves
3224     * @return noise as a float between -1f and 1f
3225     */
3226    public float ridged2D(float x, float y, int seed, int octaves)
3227    {
3228        return ridged2D(x, y, seed, octaves, 0.03125f, 2f);
3229    }
3230    /**
3231     * Generates ridged-multi simplex noise with the given amount of octaves and default frequency (0.03125), lacunarity
3232     * (2) and gain (0.5).
3233     * @param x
3234     * @param y
3235     * @param seed
3236     * @param octaves
3237     * @return noise as a float between -1f and 1f
3238     */
3239    public float ridged2D(float x, float y, int seed, int octaves, float frequency)
3240    {
3241        return ridged2D(x, y, seed, octaves, frequency, 2f);
3242    }
3243    /**
3244     * Generates ridged-multi simplex noise with the given amount of octaves and specified lacunarity (the amount of
3245     * frequency change between octaves); gain is not used.
3246     * @param x
3247     * @param y
3248     * @param seed any int
3249     * @param octaves how many "layers of detail" to generate; at least 1, but note this slows down with many octaves
3250     * @param frequency often about {@code 1f / 32f}, but generally adjusted for the use case
3251     * @param lacunarity when {@code octaves} is 2 or more, this affects the change between layers
3252     * @return noise as a float between -1f and 1f
3253     */
3254    public float ridged2D(float x, float y, int seed, int octaves, float frequency, float lacunarity)
3255    {
3256        x *= frequency;
3257        y *= frequency;
3258
3259        float sum = 0, amp = 1, ampBias = 1f, spike;
3260        for (int i = 0; i < octaves; i++) {
3261            spike = 1f - Math.abs(singleSimplex(seed + i, x, y));
3262            spike *= spike * amp;
3263            amp = Math.max(0f, Math.min(1f, spike * 2f));
3264            sum += (spike * ampBias);
3265            ampBias *= 2f;
3266            x *= lacunarity;
3267            y *= lacunarity;
3268        }
3269        return sum / ((ampBias - 1f) * 0.5f) - 1f;
3270    }
3271
3272    private float singleSimplexFractalRidgedMulti(float x, float y) {
3273        int seed = this.seed;
3274        float sum = 0, amp = 1, ampBias = 1f, spike;
3275        for (int i = 0; i < octaves; i++) {
3276            spike = 1f - Math.abs(singleSimplex(seed + i, x, y));
3277            spike *= spike * amp;
3278            amp = Math.max(0f, Math.min(1f, spike * 2f));
3279            sum += (spike * ampBias);
3280            ampBias *= 2f;
3281            x *= lacunarity;
3282            y *= lacunarity;
3283        }
3284        return sum / ((ampBias - 1f) * 0.5f) - 1f;
3285    }
3286
3287    public float getSimplex(float x, float y) {
3288        return singleSimplex(seed, x * frequency, y * frequency);
3289    }
3290
3291    public float singleSimplex(int seed, float x, float y) {
3292        float t = (x + y) * F2f;
3293        int i = fastFloor(x + t);
3294        int j = fastFloor(y + t);
3295
3296        t = (i + j) * G2f;
3297        float X0 = i - t;
3298        float Y0 = j - t;
3299
3300        float x0 = x - X0;
3301        float y0 = y - Y0;
3302
3303        int i1, j1;
3304        if (x0 > y0) {
3305            i1 = 1;
3306            j1 = 0;
3307        } else {
3308            i1 = 0;
3309            j1 = 1;
3310        }
3311
3312        float x1 = x0 - i1 + G2f;
3313        float y1 = y0 - j1 + G2f;
3314        float x2 = x0 - 1 + H2f;
3315        float y2 = y0 - 1 + H2f;
3316
3317        float n = 0f;
3318
3319        t = 0.75f - x0 * x0 - y0 * y0;
3320        if (t >= 0) {
3321            t *= t;
3322            n += t * t * gradCoord2D(seed, i, j, x0, y0);
3323        }
3324
3325        t = 0.75f - x1 * x1 - y1 * y1;
3326        if (t > 0) {
3327            t *= t;
3328            n += t * t * gradCoord2D(seed, i + i1, j + j1, x1, y1);
3329        }
3330
3331        t = 0.75f - x2 * x2 - y2 * y2;
3332        if (t > 0)  {
3333            t *= t;
3334            n += t * t * gradCoord2D(seed, i + 1, j + 1, x2, y2);
3335        }
3336
3337        return 9.11f * n;
3338    }
3339
3340    public float getSimplex(float x, float y, float z, float w) {
3341        return singleSimplex(seed, x * frequency, y * frequency, z * frequency, w * frequency);
3342    }
3343
3344    public float singleSimplex(int seed, float x, float y, float z, float w) {
3345        float n = 0f;
3346        float t = (x + y + z + w) * F4;
3347        int i = fastFloor(x + t);
3348        int j = fastFloor(y + t);
3349        int k = fastFloor(z + t);
3350        int l = fastFloor(w + t);
3351        t = (i + j + k + l) * G4;
3352        final float X0 = i - t;
3353        final float Y0 = j - t;
3354        final float Z0 = k - t;
3355        final float W0 = l - t;
3356        final float x0 = x - X0;
3357        final float y0 = y - Y0;
3358        final float z0 = z - Z0;
3359        final float w0 = w - W0;
3360
3361        final int[] SIMPLEX_4D = FastNoise.SIMPLEX_4D;
3362        final int c = (x0 > y0 ? 128 : 0) | (x0 > z0 ? 64 : 0) | (y0 > z0 ? 32 : 0) | (x0 > w0 ? 16 : 0) | (y0 > w0 ? 8 : 0) | (z0 > w0 ? 4 : 0);
3363        final int ip = SIMPLEX_4D[c];
3364        final int jp = SIMPLEX_4D[c + 1];
3365        final int kp = SIMPLEX_4D[c + 2];
3366        final int lp = SIMPLEX_4D[c + 3];
3367
3368        final int i1 = ip >> 2;
3369        final int i2 = ip >> 1 & 1;
3370        final int i3 = ip & 1;
3371        final int j1 = jp >> 2;
3372        final int j2 = jp >> 1 & 1;
3373        final int j3 = jp & 1;
3374        final int k1 = kp >> 2;
3375        final int k2 = kp >> 1 & 1;
3376        final int k3 = kp & 1;
3377        final int l1 = lp >> 2;
3378        final int l2 = lp >> 1 & 1;
3379        final int l3 = lp & 1;
3380
3381        final float x1 = x0 - i1 + G4;
3382        final float y1 = y0 - j1 + G4;
3383        final float z1 = z0 - k1 + G4;
3384        final float w1 = w0 - l1 + G4;
3385        final float x2 = x0 - i2 + 2 * G4;
3386        final float y2 = y0 - j2 + 2 * G4;
3387        final float z2 = z0 - k2 + 2 * G4;
3388        final float w2 = w0 - l2 + 2 * G4;
3389        final float x3 = x0 - i3 + 3 * G4;
3390        final float y3 = y0 - j3 + 3 * G4;
3391        final float z3 = z0 - k3 + 3 * G4;
3392        final float w3 = w0 - l3 + 3 * G4;
3393        final float x4 = x0 - 1 + 4 * G4;
3394        final float y4 = y0 - 1 + 4 * G4;
3395        final float z4 = z0 - 1 + 4 * G4;
3396        final float w4 = w0 - 1 + 4 * G4;
3397
3398        t = 0.75f - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;
3399        if (t > 0) {
3400            t *= t;
3401            n = t * t * gradCoord4D(seed, i, j, k, l, x0, y0, z0, w0);
3402        }
3403        t = 0.75f - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1;
3404        if (t > 0) {
3405            t *= t;
3406            n += t * t * gradCoord4D(seed, i + i1, j + j1, k + k1, l + l1, x1, y1, z1, w1);
3407        }
3408        t = 0.75f - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2;
3409        if (t > 0) {
3410            t *= t;
3411            n += t * t * gradCoord4D(seed, i + i2, j + j2, k + k2, l + l2, x2, y2, z2, w2);
3412        }
3413        t = 0.75f - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3;
3414        if (t > 0) {
3415            t *= t;
3416            n += t * t * gradCoord4D(seed, i + i3, j + j3, k + k3, l + l3, x3, y3, z3, w3);
3417        }
3418        t = 0.75f - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4;
3419        if (t > 0) {
3420            t *= t;
3421            n += t * t * gradCoord4D(seed, i + 1, j + 1, k + 1, l + 1, x4, y4, z4, w4);
3422        }
3423
3424        return 4.9f * n;
3425    }
3426
3427    // Simplex Noise
3428    public float getSimplexFractal(float x, float y, float z, float w) {
3429        x *= frequency;
3430        y *= frequency;
3431        z *= frequency;
3432        w *= frequency;
3433
3434        switch (fractalType) {
3435            case FBM:
3436                return singleSimplexFractalFBM(x, y, z, w);
3437            case BILLOW:
3438                return singleSimplexFractalBillow(x, y, z, w);
3439            case RIDGED_MULTI:
3440                return singleSimplexFractalRidgedMulti(x, y, z, w);
3441            default:
3442                return 0;
3443        }
3444    }
3445
3446    private float singleSimplexFractalFBM(float x, float y, float z, float w) {
3447        int seed = this.seed;
3448        float sum = singleSimplex(seed, x, y, z, w);
3449        float amp = 1;
3450
3451        for (int i = 1; i < octaves; i++) {
3452            x *= lacunarity;
3453            y *= lacunarity;
3454            z *= lacunarity;
3455            w *= lacunarity;
3456
3457            amp *= gain;
3458            sum += singleSimplex(seed + i, x, y, z, w) * amp;
3459        }
3460
3461        return sum * fractalBounding;
3462    }
3463    private float singleSimplexFractalRidgedMulti(float x, float y, float z, float w) {
3464        int seed = this.seed;
3465        float sum = 0, amp = 1, ampBias = 1f, spike;
3466        for (int i = 0; i < octaves; i++) {
3467            spike = 1f - Math.abs(singleSimplex(seed + i, x, y, z, w));
3468            spike *= spike * amp;
3469            amp = Math.max(0f, Math.min(1f, spike * 2f));
3470            sum += (spike * ampBias);
3471            ampBias *= 2f;
3472            x *= lacunarity;
3473            y *= lacunarity;
3474            z *= lacunarity;
3475            w *= lacunarity;
3476        }
3477        return sum / ((ampBias - 1f) * 0.5f) - 1f;
3478    }
3479
3480    private float singleSimplexFractalBillow(float x, float y, float z, float w) {
3481        int seed = this.seed;
3482        float sum = Math.abs(singleSimplex(seed, x, y, z, w)) * 2 - 1;
3483        float amp = 1;
3484
3485        for (int i = 1; i < octaves; i++) {
3486            x *= lacunarity;
3487            y *= lacunarity;
3488            z *= lacunarity;
3489            w *= lacunarity;
3490
3491            amp *= gain;
3492            sum += (Math.abs(singleSimplex(seed + i, x, y, z, w)) * 2 - 1) * amp;
3493        }
3494
3495        return sum * fractalBounding;
3496    }
3497
3498    // 6D Simplex
3499
3500    private final float[] m = {0, 0, 0, 0, 0, 0}, cellDist = {0, 0, 0, 0, 0, 0};
3501    private final int[] distOrder = {0, 0, 0, 0, 0, 0}, intLoc = {0, 0, 0, 0, 0, 0};
3502
3503    private static final float
3504            F6 = (float) ((Math.sqrt(7.0) - 1.0) / 6.0),
3505            G6 = F6 / (1f + 6f * F6),
3506            LIMIT6 = 0.8375f;
3507
3508
3509    public float singleSimplex(int seed, float x, float y, float z, float w, float u, float v) {
3510        final float s = (x + y + z + w + u + v) * F6;
3511
3512        final int skewX = fastFloor(x + s), skewY = fastFloor(y + s), skewZ = fastFloor(z + s),
3513                skewW = fastFloor(w + s), skewU = fastFloor(u + s), skewV = fastFloor(v + s);
3514        intLoc[0] = skewX;
3515        intLoc[1] = skewY;
3516        intLoc[2] = skewZ;
3517        intLoc[3] = skewW;
3518        intLoc[4] = skewU;
3519        intLoc[5] = skewV;
3520
3521        final float unskew = (skewX + skewY + skewZ + skewW + skewU + skewV) * G6;
3522        cellDist[0] = x - skewX + unskew;
3523        cellDist[1] = y - skewY + unskew;
3524        cellDist[2] = z - skewZ + unskew;
3525        cellDist[3] = w - skewW + unskew;
3526        cellDist[4] = u - skewU + unskew;
3527        cellDist[5] = v - skewV + unskew;
3528
3529        int o0 = (cellDist[0]<cellDist[1]?1:0)+(cellDist[0]<cellDist[2]?1:0)+(cellDist[0]<cellDist[3]?1:0)+(cellDist[0]<cellDist[4]?1:0)+(cellDist[0]<cellDist[5]?1:0);
3530        int o1 = (cellDist[1]<=cellDist[0]?1:0)+(cellDist[1]<cellDist[2]?1:0)+(cellDist[1]<cellDist[3]?1:0)+(cellDist[1]<cellDist[4]?1:0)+(cellDist[1]<cellDist[5]?1:0);
3531        int o2 = (cellDist[2]<=cellDist[0]?1:0)+(cellDist[2]<=cellDist[1]?1:0)+(cellDist[2]<cellDist[3]?1:0)+(cellDist[2]<cellDist[4]?1:0)+(cellDist[2]<cellDist[5]?1:0);
3532        int o3 = (cellDist[3]<=cellDist[0]?1:0)+(cellDist[3]<=cellDist[1]?1:0)+(cellDist[3]<=cellDist[2]?1:0)+(cellDist[3]<cellDist[4]?1:0)+(cellDist[3]<cellDist[5]?1:0);
3533        int o4 = (cellDist[4]<=cellDist[0]?1:0)+(cellDist[4]<=cellDist[1]?1:0)+(cellDist[4]<=cellDist[2]?1:0)+(cellDist[4]<=cellDist[3]?1:0)+(cellDist[4]<cellDist[5]?1:0);
3534        int o5 = 15-(o0+o1+o2+o3+o4);
3535
3536        distOrder[o0]=0;
3537        distOrder[o1]=1;
3538        distOrder[o2]=2;
3539        distOrder[o3]=3;
3540        distOrder[o4]=4;
3541        distOrder[o5]=5;
3542
3543        float n = 0;
3544        float skewOffset = 0;
3545
3546        for (int c = -1; c < 6; c++) {
3547            if (c != -1) intLoc[distOrder[c]]++;
3548
3549            m[0] = cellDist[0] - (intLoc[0] - skewX) + skewOffset;
3550            m[1] = cellDist[1] - (intLoc[1] - skewY) + skewOffset;
3551            m[2] = cellDist[2] - (intLoc[2] - skewZ) + skewOffset;
3552            m[3] = cellDist[3] - (intLoc[3] - skewW) + skewOffset;
3553            m[4] = cellDist[4] - (intLoc[4] - skewU) + skewOffset;
3554            m[5] = cellDist[5] - (intLoc[5] - skewV) + skewOffset;
3555
3556            float tc = LIMIT6;
3557
3558            for (int d = 0; d < 6; d++) {
3559                tc -= m[d] * m[d];
3560            }
3561
3562            if (tc > 0) {
3563                final int h = hash256(intLoc[0], intLoc[1], intLoc[2], intLoc[3],
3564                        intLoc[4], intLoc[5], seed) * 6;
3565                final float gr = grad6f[h] * m[0] + grad6f[h + 1] * m[1]
3566                        + grad6f[h + 2] * m[2] + grad6f[h + 3] * m[3]
3567                        + grad6f[h + 4] * m[4] + grad6f[h + 5] * m[5];
3568                tc *= tc;
3569                n += gr * tc * tc;
3570            }
3571            skewOffset += G6;
3572        }
3573        return 8.1f * n;
3574
3575    }
3576
3577    public float getSimplex(float x, float y, float z, float w, float u, float v) {
3578        return singleSimplex(seed, x * frequency, y * frequency, z * frequency, w * frequency, u * frequency, v * frequency);
3579    }
3580    // Simplex Noise
3581    public float getSimplexFractal(float x, float y, float z, float w, float u, float v) {
3582        x *= frequency;
3583        y *= frequency;
3584        z *= frequency;
3585        w *= frequency;
3586        u *= frequency;
3587        v *= frequency;
3588
3589        switch (fractalType) {
3590            case FBM:
3591                return singleSimplexFractalFBM(x, y, z, w, u, v);
3592            case BILLOW:
3593                return singleSimplexFractalBillow(x, y, z, w, u, v);
3594            case RIDGED_MULTI:
3595                return singleSimplexFractalRidgedMulti(x, y, z, w, u, v);
3596            default:
3597                return 0;
3598        }
3599    }
3600
3601    private float singleSimplexFractalFBM(float x, float y, float z, float w, float u, float v) {
3602        int seed = this.seed;
3603        float sum = singleSimplex(seed, x, y, z, w, u, v);
3604        float amp = 1;
3605
3606        for (int i = 1; i < octaves; i++) {
3607            x *= lacunarity;
3608            y *= lacunarity;
3609            z *= lacunarity;
3610            w *= lacunarity;
3611            u *= lacunarity;
3612            v *= lacunarity;
3613
3614            amp *= gain;
3615            sum += singleSimplex(seed + i, x, y, z, w, u, v) * amp;
3616        }
3617
3618        return sum * fractalBounding;
3619    }
3620    private float singleSimplexFractalRidgedMulti(float x, float y, float z, float w, float u, float v) {
3621        int seed = this.seed;
3622        float sum = 0, amp = 1, ampBias = 1f, spike;
3623        for (int i = 0; i < octaves; i++) {
3624            spike = 1f - Math.abs(singleSimplex(seed + i, x, y, z, w, u, v));
3625            spike *= spike * amp;
3626            amp = Math.max(0f, Math.min(1f, spike * 2f));
3627            sum += (spike * ampBias);
3628            ampBias *= 2f;
3629            x *= lacunarity;
3630            y *= lacunarity;
3631            z *= lacunarity;
3632            w *= lacunarity;
3633            u *= lacunarity;
3634            v *= lacunarity;
3635        }
3636        return sum / ((ampBias - 1f) * 0.5f) - 1f;
3637    }
3638
3639    private float singleSimplexFractalBillow(float x, float y, float z, float w, float u, float v) {
3640        int seed = this.seed;
3641        float sum = Math.abs(singleSimplex(seed, x, y, z, w, u, v)) * 2 - 1;
3642        float amp = 1;
3643
3644        for (int i = 1; i < octaves; i++) {
3645            x *= lacunarity;
3646            y *= lacunarity;
3647            z *= lacunarity;
3648            w *= lacunarity;
3649            u *= lacunarity;
3650            v *= lacunarity;
3651
3652            amp *= gain;
3653            sum += (Math.abs(singleSimplex(seed + i, x, y, z, w, u, v)) * 2 - 1) * amp;
3654        }
3655
3656        return sum * fractalBounding;
3657    }
3658
3659    // Cubic Noise
3660    public float getCubicFractal(float x, float y, float z) {
3661        x *= frequency;
3662        y *= frequency;
3663        z *= frequency;
3664
3665        switch (fractalType) {
3666            case FBM:
3667                return singleCubicFractalFBM(x, y, z);
3668            case BILLOW:
3669                return singleCubicFractalBillow(x, y, z);
3670            case RIDGED_MULTI:
3671                return singleCubicFractalRidgedMulti(x, y, z);
3672            default:
3673                return 0;
3674        }
3675    }
3676
3677    private float singleCubicFractalFBM(float x, float y, float z) {
3678        int seed = this.seed;
3679        float sum = singleCubic(seed, x, y, z);
3680        float amp = 1;
3681        int i = 0;
3682
3683        while (++i < octaves) {
3684            x *= lacunarity;
3685            y *= lacunarity;
3686            z *= lacunarity;
3687
3688            amp *= gain;
3689            sum += singleCubic(++seed, x, y, z) * amp;
3690        }
3691
3692        return sum * fractalBounding;
3693    }
3694
3695    private float singleCubicFractalBillow(float x, float y, float z) {
3696        int seed = this.seed;
3697        float sum = Math.abs(singleCubic(seed, x, y, z)) * 2 - 1;
3698        float amp = 1;
3699        int i = 0;
3700
3701        while (++i < octaves) {
3702            x *= lacunarity;
3703            y *= lacunarity;
3704            z *= lacunarity;
3705
3706            amp *= gain;
3707            sum += (Math.abs(singleCubic(++seed, x, y, z)) * 2 - 1) * amp;
3708        }
3709
3710        return sum * fractalBounding;
3711    }
3712
3713    private float singleCubicFractalRidgedMulti(float x, float y, float z) {
3714        int seed = this.seed;
3715        float sum = 0, amp = 1, ampBias = 1f, spike;
3716        for (int i = 0; i < octaves; i++) {
3717            spike = 1f - Math.abs(singleCubic(seed + i, x, y, z));
3718            spike *= spike * amp;
3719            amp = Math.max(0f, Math.min(1f, spike * 2f));
3720            sum += (spike * ampBias);
3721            ampBias *= 2f;
3722            x *= lacunarity;
3723            y *= lacunarity;
3724            z *= lacunarity;
3725        }
3726        return sum / ((ampBias - 1f) * 0.5f) - 1f;
3727    }
3728
3729    public float getCubic(float x, float y, float z) {
3730        return singleCubic(seed, x * frequency, y * frequency, z * frequency);
3731    }
3732
3733    private final static float CUBIC_3D_BOUNDING = 1 / (float) (1.5 * 1.5 * 1.5);
3734
3735    private float singleCubic(int seed, float x, float y, float z) {
3736        int x1 = fastFloor(x);
3737        int y1 = fastFloor(y);
3738        int z1 = fastFloor(z);
3739
3740        int x0 = x1 - 1;
3741        int y0 = y1 - 1;
3742        int z0 = z1 - 1;
3743        int x2 = x1 + 1;
3744        int y2 = y1 + 1;
3745        int z2 = z1 + 1;
3746        int x3 = x1 + 2;
3747        int y3 = y1 + 2;
3748        int z3 = z1 + 2;
3749
3750        float xs = x - (float) x1;
3751        float ys = y - (float) y1;
3752        float zs = z - (float) z1;
3753
3754        return cubicLerp(
3755                cubicLerp(
3756                        cubicLerp(valCoord3D(seed, x0, y0, z0), valCoord3D(seed, x1, y0, z0), valCoord3D(seed, x2, y0, z0), valCoord3D(seed, x3, y0, z0), xs),
3757                        cubicLerp(valCoord3D(seed, x0, y1, z0), valCoord3D(seed, x1, y1, z0), valCoord3D(seed, x2, y1, z0), valCoord3D(seed, x3, y1, z0), xs),
3758                        cubicLerp(valCoord3D(seed, x0, y2, z0), valCoord3D(seed, x1, y2, z0), valCoord3D(seed, x2, y2, z0), valCoord3D(seed, x3, y2, z0), xs),
3759                        cubicLerp(valCoord3D(seed, x0, y3, z0), valCoord3D(seed, x1, y3, z0), valCoord3D(seed, x2, y3, z0), valCoord3D(seed, x3, y3, z0), xs),
3760                        ys),
3761                cubicLerp(
3762                        cubicLerp(valCoord3D(seed, x0, y0, z1), valCoord3D(seed, x1, y0, z1), valCoord3D(seed, x2, y0, z1), valCoord3D(seed, x3, y0, z1), xs),
3763                        cubicLerp(valCoord3D(seed, x0, y1, z1), valCoord3D(seed, x1, y1, z1), valCoord3D(seed, x2, y1, z1), valCoord3D(seed, x3, y1, z1), xs),
3764                        cubicLerp(valCoord3D(seed, x0, y2, z1), valCoord3D(seed, x1, y2, z1), valCoord3D(seed, x2, y2, z1), valCoord3D(seed, x3, y2, z1), xs),
3765                        cubicLerp(valCoord3D(seed, x0, y3, z1), valCoord3D(seed, x1, y3, z1), valCoord3D(seed, x2, y3, z1), valCoord3D(seed, x3, y3, z1), xs),
3766                        ys),
3767                cubicLerp(
3768                        cubicLerp(valCoord3D(seed, x0, y0, z2), valCoord3D(seed, x1, y0, z2), valCoord3D(seed, x2, y0, z2), valCoord3D(seed, x3, y0, z2), xs),
3769                        cubicLerp(valCoord3D(seed, x0, y1, z2), valCoord3D(seed, x1, y1, z2), valCoord3D(seed, x2, y1, z2), valCoord3D(seed, x3, y1, z2), xs),
3770                        cubicLerp(valCoord3D(seed, x0, y2, z2), valCoord3D(seed, x1, y2, z2), valCoord3D(seed, x2, y2, z2), valCoord3D(seed, x3, y2, z2), xs),
3771                        cubicLerp(valCoord3D(seed, x0, y3, z2), valCoord3D(seed, x1, y3, z2), valCoord3D(seed, x2, y3, z2), valCoord3D(seed, x3, y3, z2), xs),
3772                        ys),
3773                cubicLerp(
3774                        cubicLerp(valCoord3D(seed, x0, y0, z3), valCoord3D(seed, x1, y0, z3), valCoord3D(seed, x2, y0, z3), valCoord3D(seed, x3, y0, z3), xs),
3775                        cubicLerp(valCoord3D(seed, x0, y1, z3), valCoord3D(seed, x1, y1, z3), valCoord3D(seed, x2, y1, z3), valCoord3D(seed, x3, y1, z3), xs),
3776                        cubicLerp(valCoord3D(seed, x0, y2, z3), valCoord3D(seed, x1, y2, z3), valCoord3D(seed, x2, y2, z3), valCoord3D(seed, x3, y2, z3), xs),
3777                        cubicLerp(valCoord3D(seed, x0, y3, z3), valCoord3D(seed, x1, y3, z3), valCoord3D(seed, x2, y3, z3), valCoord3D(seed, x3, y3, z3), xs),
3778                        ys),
3779                zs) * CUBIC_3D_BOUNDING;
3780    }
3781
3782
3783    public float getCubicFractal(float x, float y) {
3784        x *= frequency;
3785        y *= frequency;
3786
3787        switch (fractalType) {
3788            case FBM:
3789                return singleCubicFractalFBM(x, y);
3790            case BILLOW:
3791                return singleCubicFractalBillow(x, y);
3792            case RIDGED_MULTI:
3793                return singleCubicFractalRidgedMulti(x, y);
3794            default:
3795                return 0;
3796        }
3797    }
3798
3799    private float singleCubicFractalFBM(float x, float y) {
3800        int seed = this.seed;
3801        float sum = singleCubic(seed, x, y);
3802        float amp = 1;
3803        int i = 0;
3804
3805        while (++i < octaves) {
3806            x *= lacunarity;
3807            y *= lacunarity;
3808
3809            amp *= gain;
3810            sum += singleCubic(++seed, x, y) * amp;
3811        }
3812
3813        return sum * fractalBounding;
3814    }
3815
3816    private float singleCubicFractalBillow(float x, float y) {
3817        int seed = this.seed;
3818        float sum = Math.abs(singleCubic(seed, x, y)) * 2 - 1;
3819        float amp = 1;
3820        int i = 0;
3821
3822        while (++i < octaves) {
3823            x *= lacunarity;
3824            y *= lacunarity;
3825
3826            amp *= gain;
3827            sum += (Math.abs(singleCubic(++seed, x, y)) * 2 - 1) * amp;
3828        }
3829
3830        return sum * fractalBounding;
3831    }
3832
3833    private float singleCubicFractalRidgedMulti(float x, float y) {
3834        int seed = this.seed;
3835        float sum = 0, amp = 1, ampBias = 1f, spike;
3836        for (int i = 0; i < octaves; i++) {
3837            spike = 1f - Math.abs(singleCubic(seed + i, x, y));
3838            spike *= spike * amp;
3839            amp = Math.max(0f, Math.min(1f, spike * 2f));
3840            sum += (spike * ampBias);
3841            ampBias *= 2f;
3842            x *= lacunarity;
3843            y *= lacunarity;
3844        }
3845        return sum / ((ampBias - 1f) * 0.5f) - 1f;
3846    }
3847
3848    public float getCubic(float x, float y) {
3849        x *= frequency;
3850        y *= frequency;
3851
3852        return singleCubic(0, x, y);
3853    }
3854
3855    private final static float CUBIC_2D_BOUNDING = 1 / 2.25f;
3856
3857    private float singleCubic(int seed, float x, float y) {
3858        int x1 = fastFloor(x);
3859        int y1 = fastFloor(y);
3860
3861        int x0 = x1 - 1;
3862        int y0 = y1 - 1;
3863        int x2 = x1 + 1;
3864        int y2 = y1 + 1;
3865        int x3 = x1 + 2;
3866        int y3 = y1 + 2;
3867
3868        float xs = x - (float) x1;
3869        float ys = y - (float) y1;
3870
3871        return cubicLerp(
3872                cubicLerp(valCoord2D(seed, x0, y0), valCoord2D(seed, x1, y0), valCoord2D(seed, x2, y0), valCoord2D(seed, x3, y0),
3873                        xs),
3874                cubicLerp(valCoord2D(seed, x0, y1), valCoord2D(seed, x1, y1), valCoord2D(seed, x2, y1), valCoord2D(seed, x3, y1),
3875                        xs),
3876                cubicLerp(valCoord2D(seed, x0, y2), valCoord2D(seed, x1, y2), valCoord2D(seed, x2, y2), valCoord2D(seed, x3, y2),
3877                        xs),
3878                cubicLerp(valCoord2D(seed, x0, y3), valCoord2D(seed, x1, y3), valCoord2D(seed, x2, y3), valCoord2D(seed, x3, y3),
3879                        xs),
3880                ys) * CUBIC_2D_BOUNDING;
3881    }
3882
3883    // Cellular Noise
3884    public float getCellular(float x, float y, float z) {
3885        x *= frequency;
3886        y *= frequency;
3887        z *= frequency;
3888
3889        switch (cellularReturnType) {
3890            case CELL_VALUE:
3891            case NOISE_LOOKUP:
3892            case DISTANCE:
3893                return singleCellular(x, y, z);
3894            default:
3895                return singleCellular2Edge(x, y, z);
3896        }
3897    }
3898
3899    private float singleCellular(float x, float y, float z) {
3900        int xr = fastRound(x);
3901        int yr = fastRound(y);
3902        int zr = fastRound(z);
3903
3904        float distance = 999999;
3905        int xc = 0, yc = 0, zc = 0;
3906
3907        switch (cellularDistanceFunction) {
3908            case EUCLIDEAN:
3909                for (int xi = xr - 1; xi <= xr + 1; xi++) {
3910                    for (int yi = yr - 1; yi <= yr + 1; yi++) {
3911                        for (int zi = zr - 1; zi <= zr + 1; zi++) {
3912                            Float3 vec = CELL_3D[hash256(xi, yi, zi, seed)];
3913
3914                            float vecX = xi - x + vec.x;
3915                            float vecY = yi - y + vec.y;
3916                            float vecZ = zi - z + vec.z;
3917
3918                            float newDistance = vecX * vecX + vecY * vecY + vecZ * vecZ;
3919
3920                            if (newDistance < distance) {
3921                                distance = newDistance;
3922                                xc = xi;
3923                                yc = yi;
3924                                zc = zi;
3925                            }
3926                        }
3927                    }
3928                }
3929                break;
3930            case MANHATTAN:
3931                for (int xi = xr - 1; xi <= xr + 1; xi++) {
3932                    for (int yi = yr - 1; yi <= yr + 1; yi++) {
3933                        for (int zi = zr - 1; zi <= zr + 1; zi++) {
3934                            Float3 vec = CELL_3D[hash256(xi, yi, zi, seed)];
3935
3936                            float vecX = xi - x + vec.x;
3937                            float vecY = yi - y + vec.y;
3938                            float vecZ = zi - z + vec.z;
3939
3940                            float newDistance = Math.abs(vecX) + Math.abs(vecY) + Math.abs(vecZ);
3941
3942                            if (newDistance < distance) {
3943                                distance = newDistance;
3944                                xc = xi;
3945                                yc = yi;
3946                                zc = zi;
3947                            }
3948                        }
3949                    }
3950                }
3951                break;
3952            case NATURAL:
3953                for (int xi = xr - 1; xi <= xr + 1; xi++) {
3954                    for (int yi = yr - 1; yi <= yr + 1; yi++) {
3955                        for (int zi = zr - 1; zi <= zr + 1; zi++) {
3956                            Float3 vec = CELL_3D[hash256(xi, yi, zi, seed)];
3957
3958                            float vecX = xi - x + vec.x;
3959                            float vecY = yi - y + vec.y;
3960                            float vecZ = zi - z + vec.z;
3961
3962                            float newDistance = (Math.abs(vecX) + Math.abs(vecY) + Math.abs(vecZ)) + (vecX * vecX + vecY * vecY + vecZ * vecZ);
3963
3964                            if (newDistance < distance) {
3965                                distance = newDistance;
3966                                xc = xi;
3967                                yc = yi;
3968                                zc = zi;
3969                            }
3970                        }
3971                    }
3972                }
3973                break;
3974        }
3975
3976        switch (cellularReturnType) {
3977            case CELL_VALUE:
3978                return valCoord3D(0, xc, yc, zc);
3979
3980            case NOISE_LOOKUP:
3981                Float3 vec = CELL_3D[hash256(xc, yc, zc, seed)];
3982                return cellularNoiseLookup.getConfiguredNoise(xc + vec.x, yc + vec.y, zc + vec.z);
3983
3984            case DISTANCE:
3985                return distance - 1;
3986            default:
3987                return 0;
3988        }
3989    }
3990
3991    private float singleCellular2Edge(float x, float y, float z) {
3992        int xr = fastRound(x);
3993        int yr = fastRound(y);
3994        int zr = fastRound(z);
3995
3996        float distance = 999999;
3997        float distance2 = 999999;
3998
3999        switch (cellularDistanceFunction) {
4000            case EUCLIDEAN:
4001                for (int xi = xr - 1; xi <= xr + 1; xi++) {
4002                    for (int yi = yr - 1; yi <= yr + 1; yi++) {
4003                        for (int zi = zr - 1; zi <= zr + 1; zi++) {
4004                            Float3 vec = CELL_3D[hash256(xi, yi, zi, seed)];
4005
4006                            float vecX = xi - x + vec.x;
4007                            float vecY = yi - y + vec.y;
4008                            float vecZ = zi - z + vec.z;
4009
4010                            float newDistance = vecX * vecX + vecY * vecY + vecZ * vecZ;
4011
4012                            distance2 = Math.max(Math.min(distance2, newDistance), distance);
4013                            distance = Math.min(distance, newDistance);
4014                        }
4015                    }
4016                }
4017                break;
4018            case MANHATTAN:
4019                for (int xi = xr - 1; xi <= xr + 1; xi++) {
4020                    for (int yi = yr - 1; yi <= yr + 1; yi++) {
4021                        for (int zi = zr - 1; zi <= zr + 1; zi++) {
4022                            Float3 vec = CELL_3D[hash256(xi, yi, zi, seed)];
4023
4024                            float vecX = xi - x + vec.x;
4025                            float vecY = yi - y + vec.y;
4026                            float vecZ = zi - z + vec.z;
4027
4028                            float newDistance = Math.abs(vecX) + Math.abs(vecY) + Math.abs(vecZ);
4029
4030                            distance2 = Math.max(Math.min(distance2, newDistance), distance);
4031                            distance = Math.min(distance, newDistance);
4032                        }
4033                    }
4034                }
4035                break;
4036            case NATURAL:
4037                for (int xi = xr - 1; xi <= xr + 1; xi++) {
4038                    for (int yi = yr - 1; yi <= yr + 1; yi++) {
4039                        for (int zi = zr - 1; zi <= zr + 1; zi++) {
4040                            Float3 vec = CELL_3D[hash256(xi, yi, zi, seed)];
4041
4042                            float vecX = xi - x + vec.x;
4043                            float vecY = yi - y + vec.y;
4044                            float vecZ = zi - z + vec.z;
4045
4046                            float newDistance = (Math.abs(vecX) + Math.abs(vecY) + Math.abs(vecZ)) + (vecX * vecX + vecY * vecY + vecZ * vecZ);
4047
4048                            distance2 = Math.max(Math.min(distance2, newDistance), distance);
4049                            distance = Math.min(distance, newDistance);
4050                        }
4051                    }
4052                }
4053                break;
4054            default:
4055                break;
4056        }
4057
4058        switch (cellularReturnType) {
4059            case DISTANCE_2:
4060                return distance2 - 1;
4061            case DISTANCE_2_ADD:
4062                return distance2 + distance - 1;
4063            case DISTANCE_2_SUB:
4064                return distance2 - distance - 1;
4065            case DISTANCE_2_MUL:
4066                return distance2 * distance - 1;
4067            case DISTANCE_2_DIV:
4068                return distance / distance2 - 1;
4069            default:
4070                return 0;
4071        }
4072    }
4073
4074    public float getCellular(float x, float y) {
4075        x *= frequency;
4076        y *= frequency;
4077
4078        switch (cellularReturnType) {
4079            case CELL_VALUE:
4080            case NOISE_LOOKUP:
4081            case DISTANCE:
4082                return singleCellular(x, y);
4083            default:
4084                return singleCellular2Edge(x, y);
4085        }
4086    }
4087
4088    private float singleCellular(float x, float y) {
4089        int xr = fastRound(x);
4090        int yr = fastRound(y);
4091
4092        float distance = 999999;
4093        int xc = 0, yc = 0;
4094
4095        switch (cellularDistanceFunction) {
4096            default:
4097            case EUCLIDEAN:
4098                for (int xi = xr - 1; xi <= xr + 1; xi++) {
4099                    for (int yi = yr - 1; yi <= yr + 1; yi++) {
4100                        Float2 vec = CELL_2D[hash256(xi, yi, seed)];
4101
4102                        float vecX = xi - x + vec.x;
4103                        float vecY = yi - y + vec.y;
4104
4105                        float newDistance = vecX * vecX + vecY * vecY;
4106
4107                        if (newDistance < distance) {
4108                            distance = newDistance;
4109                            xc = xi;
4110                            yc = yi;
4111                        }
4112                    }
4113                }
4114                break;
4115            case MANHATTAN:
4116                for (int xi = xr - 1; xi <= xr + 1; xi++) {
4117                    for (int yi = yr - 1; yi <= yr + 1; yi++) {
4118                        Float2 vec = CELL_2D[hash256(xi, yi, seed)];
4119
4120                        float vecX = xi - x + vec.x;
4121                        float vecY = yi - y + vec.y;
4122
4123                        float newDistance = (Math.abs(vecX) + Math.abs(vecY));
4124
4125                        if (newDistance < distance) {
4126                            distance = newDistance;
4127                            xc = xi;
4128                            yc = yi;
4129                        }
4130                    }
4131                }
4132                break;
4133            case NATURAL:
4134                for (int xi = xr - 1; xi <= xr + 1; xi++) {
4135                    for (int yi = yr - 1; yi <= yr + 1; yi++) {
4136                        Float2 vec = CELL_2D[hash256(xi, yi, seed)];
4137
4138                        float vecX = xi - x + vec.x;
4139                        float vecY = yi - y + vec.y;
4140
4141                        float newDistance = (Math.abs(vecX) + Math.abs(vecY)) + (vecX * vecX + vecY * vecY);
4142
4143                        if (newDistance < distance) {
4144                            distance = newDistance;
4145                            xc = xi;
4146                            yc = yi;
4147                        }
4148                    }
4149                }
4150                break;
4151        }
4152
4153        switch (cellularReturnType) {
4154            case CELL_VALUE:
4155                return valCoord2D(0, xc, yc);
4156
4157            case NOISE_LOOKUP:
4158                Float2 vec = CELL_2D[hash256(xc, yc, seed)];
4159                return cellularNoiseLookup.getConfiguredNoise(xc + vec.x, yc + vec.y);
4160
4161            case DISTANCE:
4162                return distance - 1;
4163            default:
4164                return 0;
4165        }
4166    }
4167
4168    private float singleCellular2Edge(float x, float y) {
4169        int xr = fastRound(x);
4170        int yr = fastRound(y);
4171
4172        float distance = 999999;
4173        float distance2 = 999999;
4174
4175        switch (cellularDistanceFunction) {
4176            default:
4177            case EUCLIDEAN:
4178                for (int xi = xr - 1; xi <= xr + 1; xi++) {
4179                    for (int yi = yr - 1; yi <= yr + 1; yi++) {
4180                        Float2 vec = CELL_2D[hash256(xi, yi, seed)];
4181
4182                        float vecX = xi - x + vec.x;
4183                        float vecY = yi - y + vec.y;
4184
4185                        float newDistance = vecX * vecX + vecY * vecY;
4186
4187                        distance2 = Math.max(Math.min(distance2, newDistance), distance);
4188                        distance = Math.min(distance, newDistance);
4189                    }
4190                }
4191                break;
4192            case MANHATTAN:
4193                for (int xi = xr - 1; xi <= xr + 1; xi++) {
4194                    for (int yi = yr - 1; yi <= yr + 1; yi++) {
4195                        Float2 vec = CELL_2D[hash256(xi, yi, seed)];
4196
4197                        float vecX = xi - x + vec.x;
4198                        float vecY = yi - y + vec.y;
4199
4200                        float newDistance = Math.abs(vecX) + Math.abs(vecY);
4201
4202                        distance2 = Math.max(Math.min(distance2, newDistance), distance);
4203                        distance = Math.min(distance, newDistance);
4204                    }
4205                }
4206                break;
4207            case NATURAL:
4208                for (int xi = xr - 1; xi <= xr + 1; xi++) {
4209                    for (int yi = yr - 1; yi <= yr + 1; yi++) {
4210                        Float2 vec = CELL_2D[hash256(xi, yi, seed)];
4211
4212                        float vecX = xi - x + vec.x;
4213                        float vecY = yi - y + vec.y;
4214
4215                        float newDistance = (Math.abs(vecX) + Math.abs(vecY)) + (vecX * vecX + vecY * vecY);
4216
4217                        distance2 = Math.max(Math.min(distance2, newDistance), distance);
4218                        distance = Math.min(distance, newDistance);
4219                    }
4220                }
4221                break;
4222        }
4223
4224        switch (cellularReturnType) {
4225            case DISTANCE_2:
4226                return distance2 - 1;
4227            case DISTANCE_2_ADD:
4228                return distance2 + distance - 1;
4229            case DISTANCE_2_SUB:
4230                return distance2 - distance - 1;
4231            case DISTANCE_2_MUL:
4232                return distance2 * distance - 1;
4233            case DISTANCE_2_DIV:
4234                return distance / distance2 - 1;
4235            default:
4236                return 0;
4237        }
4238    }
4239
4240    public void gradientPerturb3(float[] v3) {
4241        singleGradientPerturb3(seed, gradientPerturbAmp, frequency, v3);
4242    }
4243
4244    public void gradientPerturbFractal3(float[] v3) {
4245        int seed = this.seed;
4246        float amp = gradientPerturbAmp * fractalBounding;
4247        float freq = frequency;
4248
4249        singleGradientPerturb3(seed, amp, frequency, v3);
4250
4251        for (int i = 1; i < octaves; i++) {
4252            freq *= lacunarity;
4253            amp *= gain;
4254            singleGradientPerturb3(++seed, amp, freq, v3);
4255        }
4256    }
4257
4258    private void singleGradientPerturb3(int seed, float perturbAmp, float frequency, float[] v3) {
4259        float xf = v3[0] * frequency;
4260        float yf = v3[1] * frequency;
4261        float zf = v3[2] * frequency;
4262
4263        int x0 = fastFloor(xf);
4264        int y0 = fastFloor(yf);
4265        int z0 = fastFloor(zf);
4266        int x1 = x0 + 1;
4267        int y1 = y0 + 1;
4268        int z1 = z0 + 1;
4269
4270        float xs, ys, zs;
4271        switch (interpolation) {
4272            default:
4273            case LINEAR:
4274                xs = xf - x0;
4275                ys = yf - y0;
4276                zs = zf - z0;
4277                break;
4278            case HERMITE:
4279                xs = hermiteInterpolator(xf - x0);
4280                ys = hermiteInterpolator(yf - y0);
4281                zs = hermiteInterpolator(zf - z0);
4282                break;
4283            case QUINTIC:
4284                xs = quinticInterpolator(xf - x0);
4285                ys = quinticInterpolator(yf - y0);
4286                zs = quinticInterpolator(zf - z0);
4287                break;
4288        }
4289
4290        Float3 vec0 = CELL_3D[hash256(x0, y0, z0, seed)];
4291        Float3 vec1 = CELL_3D[hash256(x1, y0, z0, seed)];
4292
4293        float lx0x = lerp(vec0.x, vec1.x, xs);
4294        float ly0x = lerp(vec0.y, vec1.y, xs);
4295        float lz0x = lerp(vec0.z, vec1.z, xs);
4296
4297        vec0 = CELL_3D[hash256(x0, y1, z0, seed)];
4298        vec1 = CELL_3D[hash256(x1, y1, z0, seed)];
4299
4300        float lx1x = lerp(vec0.x, vec1.x, xs);
4301        float ly1x = lerp(vec0.y, vec1.y, xs);
4302        float lz1x = lerp(vec0.z, vec1.z, xs);
4303
4304        float lx0y = lerp(lx0x, lx1x, ys);
4305        float ly0y = lerp(ly0x, ly1x, ys);
4306        float lz0y = lerp(lz0x, lz1x, ys);
4307
4308        vec0 = CELL_3D[hash256(x0, y0, z1, seed)];
4309        vec1 = CELL_3D[hash256(x1, y0, z1, seed)];
4310
4311        lx0x = lerp(vec0.x, vec1.x, xs);
4312        ly0x = lerp(vec0.y, vec1.y, xs);
4313        lz0x = lerp(vec0.z, vec1.z, xs);
4314
4315        vec0 = CELL_3D[hash256(x0, y1, z1, seed)];
4316        vec1 = CELL_3D[hash256(x1, y1, z1, seed)];
4317
4318        lx1x = lerp(vec0.x, vec1.x, xs);
4319        ly1x = lerp(vec0.y, vec1.y, xs);
4320        lz1x = lerp(vec0.z, vec1.z, xs);
4321
4322        v3[0] += lerp(lx0y, lerp(lx0x, lx1x, ys), zs) * perturbAmp;
4323        v3[1] += lerp(ly0y, lerp(ly0x, ly1x, ys), zs) * perturbAmp;
4324        v3[2] += lerp(lz0y, lerp(lz0x, lz1x, ys), zs) * perturbAmp;
4325    }
4326
4327    public void gradientPerturb2(float[] v2) {
4328        singleGradientPerturb2(seed, gradientPerturbAmp, frequency, v2);
4329    }
4330
4331    public void gradientPerturbFractal2(float[] v2) {
4332        int seed = this.seed;
4333        float amp = gradientPerturbAmp * fractalBounding;
4334        float freq = frequency;
4335
4336        singleGradientPerturb2(seed, amp, frequency, v2);
4337
4338        for (int i = 1; i < octaves; i++) {
4339            freq *= lacunarity;
4340            amp *= gain;
4341            singleGradientPerturb2(++seed, amp, freq, v2);
4342        }
4343    }
4344
4345    private void singleGradientPerturb2(int seed, float perturbAmp, float frequency, float[] v2) {
4346        float xf = v2[0] * frequency;
4347        float yf = v2[1] * frequency;
4348
4349        int x0 = fastFloor(xf);
4350        int y0 = fastFloor(yf);
4351        int x1 = x0 + 1;
4352        int y1 = y0 + 1;
4353
4354        float xs, ys;
4355        switch (interpolation) {
4356            default:
4357            case LINEAR:
4358                xs = xf - x0;
4359                ys = yf - y0;
4360                break;
4361            case HERMITE:
4362                xs = hermiteInterpolator(xf - x0);
4363                ys = hermiteInterpolator(yf - y0);
4364                break;
4365            case QUINTIC:
4366                xs = quinticInterpolator(xf - x0);
4367                ys = quinticInterpolator(yf - y0);
4368                break;
4369        }
4370
4371        Float2 vec0 = CELL_2D[hash256(x0, y0, seed)];
4372        Float2 vec1 = CELL_2D[hash256(x1, y0, seed)];
4373
4374        float lx0x = lerp(vec0.x, vec1.x, xs);
4375        float ly0x = lerp(vec0.y, vec1.y, xs);
4376
4377        vec0 = CELL_2D[hash256(x0, y1, seed)];
4378        vec1 = CELL_2D[hash256(x1, y1, seed)];
4379
4380        float lx1x = lerp(vec0.x, vec1.x, xs);
4381        float ly1x = lerp(vec0.y, vec1.y, xs);
4382
4383        v2[0] += lerp(lx0x, lx1x, ys) * perturbAmp;
4384        v2[1] += lerp(ly0x, ly1x, ys) * perturbAmp;
4385    }
4386
4387
4388    public static final float F2f = 0.3660254f;
4389    public static final float G2f = 0.21132487f;
4390    public static final float H2f = 0.42264974f;
4391    public static final float F3f = 0.33333334f;
4392    public static final float G3f = 0.16666667f;
4393
4394    private static final float F4 = (float) ((2.23606797 - 1.0) / 4.0);
4395    private static final float G4 = (float) ((5.0 - 2.23606797) / 20.0);
4396
4397    // takes slightly less storage than an array of float[2]
4398    private static class Float2 {
4399        public final float x, y;
4400
4401        Float2(float x, float y) {
4402            this.x = x;
4403            this.y = y;
4404        }
4405    }
4406
4407    // takes slightly less storage than an array of float[3]
4408    private static class Float3 {
4409        public final float x, y, z;
4410
4411        Float3(float x, float y, float z) {
4412            this.x = x;
4413            this.y = y;
4414            this.z = z;
4415        }
4416    }
4417
4418    protected static final float[][] phiGrad2f = {
4419            {0.6499429579167653f, 0.759982994187637f},
4420            {-0.1551483029088119f, 0.9878911904175052f},
4421            {-0.8516180517334043f, 0.5241628506120981f},
4422            {-0.9518580082090311f, -0.30653928330368374f},
4423            {-0.38568876701087174f, -0.9226289476282616f},
4424            {0.4505066120763985f, -0.8927730912586049f},
4425            {0.9712959670388622f, -0.23787421973396244f},
4426            {0.8120673355833279f, 0.5835637432865366f},
4427            {0.08429892519436613f, 0.9964405106232257f},
4428            {-0.702488350003267f, 0.7116952424385647f},
4429            {-0.9974536374007479f, -0.07131788861160528f},
4430            {-0.5940875849508908f, -0.804400361391775f},
4431            {0.2252075529515288f, -0.9743108118529653f},
4432            {0.8868317111719171f, -0.4620925405802277f},
4433            {0.9275724981153959f, 0.373643226540993f},
4434            {0.3189067150428103f, 0.9477861083074618f},
4435            {-0.5130301507665112f, 0.8583705868705491f},
4436            {-0.9857873824221494f, 0.1679977281313266f},
4437            {-0.7683809836504446f, -0.6399927061806058f},
4438            {-0.013020236219374872f, -0.9999152331316848f},
4439            {0.7514561619680513f, -0.6597830223946701f},
4440            {0.9898275175279653f, 0.14227257481477412f},
4441            {0.5352066871710182f, 0.8447211386057674f},
4442            {-0.29411988281443646f, 0.9557685360657266f},
4443            {-0.9175289804081126f, 0.39766892022290273f},
4444            {-0.8985631161871687f, -0.43884430750324743f},
4445            {-0.2505005588110731f, -0.968116454790094f},
4446            {0.5729409678802212f, -0.8195966369650838f},
4447            {0.9952584535626074f, -0.09726567026534665f},
4448            {0.7207814785200723f, 0.6931623620930514f},
4449            {-0.05832476124070039f, 0.998297662136006f},
4450            {-0.7965970142012075f, 0.6045107087270838f},
4451            {-0.977160478114496f, -0.21250270589112422f},
4452            {-0.4736001288089817f, -0.8807399831914728f},
4453            {0.36153434093875386f, -0.9323587937709286f},
4454            {0.9435535266854258f, -0.3312200813348966f},
4455            {0.8649775992346886f, 0.5018104750024599f},
4456            {0.1808186720712497f, 0.9835164502083277f},
4457            {-0.6299339540895539f, 0.7766487066139361f},
4458            {-0.9996609468975833f, 0.02603826506945166f},
4459            {-0.6695112313914258f, -0.7428019325774111f},
4460            {0.12937272671950842f, -0.9915960354807594f},
4461            {0.8376810167470904f, -0.5461597881403947f},
4462            {0.959517028911149f, 0.28165061908243916f},
4463            {0.4095816551369482f, 0.9122734610714476f},
4464            {-0.42710760401484793f, 0.9042008043530463f},
4465            {-0.9647728141412515f, 0.2630844295924223f},
4466            {-0.8269869890664444f, -0.562221059650754f},
4467            {-0.11021592552380209f, -0.9939076666174438f},
4468            {0.6837188597775012f, -0.72974551782423f},
4469            {0.998972441738333f, 0.04532174585508431f},
4470            {0.6148313475439905f, 0.7886586169422362f},
4471            {-0.1997618324529528f, 0.9798444827088829f},
4472            {-0.8744989400706802f, 0.48502742583822706f},
4473            {-0.9369870231562731f, -0.3493641630687752f},
4474            {-0.3434772946489506f, -0.9391609809082988f},
4475            {0.4905057254335028f, -0.8714379687143274f},
4476            {0.9810787787756657f, -0.1936089611460388f},
4477            {0.7847847614201463f, 0.6197684069414349f},
4478            {0.03905187955516296f, 0.9992371844077906f},
4479            {-0.7340217731995672f, 0.6791259356474049f},
4480            {-0.9931964444524306f, -0.1164509455824639f},
4481            {-0.5570202966000876f, -0.830498879695542f},
4482            {0.2691336060685578f, -0.9631028512493016f},
4483            {0.9068632806061f, -0.4214249521425399f},
4484            {0.9096851999779008f, 0.4152984913783901f},
4485            {0.27562369868737335f, 0.9612656119522284f},
4486            {-0.5514058359842319f, 0.8342371389734039f},
4487            {-0.9923883787916933f, 0.12314749546456379f},
4488            {-0.7385858406439617f, -0.6741594440488484f},
4489            {0.032311046904542805f, -0.9994778618098213f},
4490            {0.7805865154410089f, -0.6250477517051506f},
4491            {0.9823623706068018f, 0.18698709264487903f},
4492            {0.49637249435561115f, 0.8681096398768929f},
4493            {-0.3371347561867868f, 0.9414564016304079f},
4494            {-0.9346092156607797f, 0.35567627697379833f},
4495            {-0.877750600058892f, -0.47911781859606817f},
4496            {-0.20636642697019966f, -0.9784747813917093f},
4497            {0.6094977881394418f, -0.7927877687333024f},
4498            {0.998644017504346f, -0.052058873429796634f},
4499            {0.6886255051458764f, 0.7251171723677399f},
4500            {-0.10350942208147358f, 0.9946284731196666f},
4501            {-0.8231759450656516f, 0.567786371327519f},
4502            {-0.9665253951623188f, -0.2565709658288005f},
4503            {-0.43319680340129196f, -0.9012993562201753f},
4504            {0.4034189716368784f, -0.9150153732716426f},
4505            {0.9575954428121146f, -0.28811624026678895f},
4506            {0.8413458575409575f, 0.5404971304259356f},
4507            {0.13605818775026976f, 0.9907008476558967f},
4508            {-0.664485735550556f, 0.7473009482463117f},
4509            {-0.999813836664718f, -0.01929487014147803f},
4510            {-0.6351581891853917f, -0.7723820781910558f},
4511            {0.17418065221630152f, -0.984713714941304f},
4512            {0.8615731658120597f, -0.5076334109892543f},
4513            {0.945766171482902f, 0.32484819358982736f},
4514            {0.3678149601703667f, 0.9298990026206456f},
4515            {-0.4676486851245607f, 0.883914423064399f},
4516            {-0.9757048995218635f, 0.2190889067228882f},
4517            {-0.8006563717736747f, -0.5991238388999518f},
4518            {-0.06505704156910719f, -0.9978815467490495f},
4519            {0.716089639712196f, -0.6980083293893113f},
4520            {0.9958918787052943f, 0.09055035024139549f},
4521            {0.5784561871098056f, 0.8157134543418942f},
4522            {-0.24396482815448167f, 0.9697840804135497f},
4523            {-0.8955826311865743f, 0.4448952131872543f},
4524            {-0.9201904205900768f, -0.39147105876968413f},
4525            {-0.3005599364234082f, -0.9537629289384008f},
4526            {0.5294967923694863f, -0.84831193960148f},
4527            {0.9888453593035162f, -0.1489458135829932f},
4528            {0.7558893631265085f, 0.6546993743025888f},
4529            {-0.006275422246980369f, 0.9999803093439501f},
4530            {-0.764046696121276f, 0.6451609459244744f},
4531            {-0.9868981170802014f, -0.16134468229090512f},
4532            {-0.5188082666339063f, -0.8548906260290385f},
4533            {0.31250655826478446f, -0.9499156020623616f},
4534            {0.9250311403279032f, -0.3798912863223621f},
4535            {0.889928392754896f, 0.45610026942404636f},
4536            {0.2317742435145519f, 0.9727696027545563f},
4537            {-0.5886483179573486f, 0.8083892365475831f},
4538            {-0.996949901406418f, 0.0780441803450664f},
4539            {-0.707272817672466f, -0.7069407057042696f},
4540            {0.07757592706207364f, -0.9969864470194466f},
4541            {0.8081126726681943f, -0.5890279350532263f},
4542            {0.9728783545459001f, 0.23131733021125322f},
4543            {0.4565181982253288f, 0.8897140746830408f},
4544            {-0.3794567783511009f, 0.9252094645881026f},
4545            {-0.9497687200714887f, 0.31295267753091066f},
4546            {-0.8551342041690687f, -0.5184066867432686f},
4547            {-0.16180818807538452f, -0.9868222283024238f},
4548            {0.6448020194233159f, -0.7643496292585048f},
4549            {0.9999772516247822f, -0.006745089543285545f},
4550            {0.6550543261176665f, 0.7555817823601425f},
4551            {-0.14848135899860646f, 0.9889152066936411f},
4552            {-0.848063153443784f, 0.5298951667745091f},
4553            {-0.9539039899003245f, -0.300111942535184f},
4554            {-0.3919032080850608f, -0.9200064540494471f},
4555            {0.44447452934057863f, -0.8957914895596358f},
4556            {0.9696693887216105f, -0.24442028675267172f},
4557            {0.8159850520735595f, 0.5780730012658526f},
4558            {0.0910180879994953f, 0.9958492394217692f},
4559            {-0.6976719213969089f, 0.7164173993520435f},
4560            {-0.9979119924958648f, -0.06458835214597858f},
4561            {-0.5994998228898376f, -0.8003748886334786f},
4562            {0.2186306161766729f, -0.9758076929755208f},
4563            {0.8836946816279001f, -0.46806378802740584f},
4564            {0.9300716543684309f, 0.36737816720699407f},
4565            {0.32529236260160294f, 0.9456134933645286f},
4566            {-0.5072286936943775f, 0.8618114946396893f},
4567            {-0.9846317976415725f, 0.17464313062106204f},
4568            {-0.7726803123417516f, -0.6347953488483143f},
4569            {-0.019764457813331488f, -0.9998046640256011f},
4570            {0.7469887719961158f, -0.6648366525032559f},
4571            {0.9907646418168752f, 0.13559286310672486f},
4572            {0.5408922318074902f, 0.8410919055432124f},
4573            {-0.2876664477065717f, 0.9577306588304888f},
4574            {-0.9148257956391065f, 0.40384868903250853f},
4575            {-0.9015027194859215f, -0.4327734358292892f},
4576            {-0.2570248925062563f, -0.9664047830139022f},
4577            {0.5673996816983953f, -0.8234425306046317f},
4578            {0.9945797473944409f, -0.10397656501736473f},
4579            {0.7254405241129018f, 0.6882848581617921f},
4580            {-0.05158982732517303f, 0.9986683582233687f},
4581            {-0.7925014140531963f, 0.609870075281354f},
4582            {-0.9785715990807187f, -0.20590683687679034f},
4583            {-0.47953002522651733f, -0.8775254725113429f},
4584            {0.35523727306945746f, -0.9347761656258549f},
4585            {0.9412979532686209f, -0.33757689964259285f},
4586            {0.868342678987353f, 0.4959647082697184f},
4587            {0.18744846526420056f, 0.9822744386728669f},
4588            {-0.6246810590458048f, 0.7808800000444446f},
4589            {-0.9994625758058275f, 0.03278047534097766f},
4590            {-0.674506266646887f, -0.738269121834361f},
4591            {0.12268137965007223f, -0.9924461089082646f},
4592            {0.8339780641890598f, -0.5517975973592748f},
4593            {0.9613949601033843f, 0.2751721837101493f},
4594            {0.41572570400265835f, 0.9094900433932711f},
4595            {-0.42099897262033487f, 0.907061114287578f},
4596            {-0.9629763390922247f, 0.2695859238694348f},
4597            {-0.8307604078465821f, -0.5566301687427484f},
4598            {-0.11691741449967302f, -0.9931416405461567f},
4599            {0.6787811074228051f, -0.7343406622310046f},
4600            {0.999255415972447f, 0.03858255628819732f},
4601            {0.6201369341201711f, 0.7844935837468874f},
4602            {-0.19314814942146824f, 0.9811696042861612f},
4603            {-0.8712074932224428f, 0.4909149659086258f},
4604            {-0.9393222007870077f, -0.34303615422962713f},
4605            {-0.3498042060103595f, -0.9368228314134226f},
4606            {0.4846166400948296f, -0.8747266499559725f},
4607            {0.9797505510481769f, -0.20022202106859724f},
4608            {0.7889473022428521f, 0.6144608647291752f},
4609            {0.045790935472179155f, 0.9989510449609544f},
4610            {-0.7294243101497431f, 0.684061529222753f},
4611            {-0.9939593229024027f, -0.10974909756074072f},
4612            {-0.562609414602539f, -0.8267228354174018f},
4613            {0.26263126874523307f, -0.9648962724963078f},
4614            {0.9040001019019392f, -0.4275322394408211f},
4615            {0.9124657316291773f, 0.4091531358824348f},
4616            {0.28210125132356934f, 0.9593846381935018f},
4617            {-0.5457662881946498f, 0.8379374431723614f},
4618            {-0.9915351626845509f, 0.12983844253579577f},
4619            {-0.7431163048326799f, -0.6691622803863227f},
4620            {0.02556874420628532f, -0.9996730662170076f},
4621            {0.7763527553119807f, -0.6302986588273021f},
4622            {0.9836012681423212f, 0.1803567168386515f},
4623            {0.5022166799422209f, 0.8647418148718223f},
4624            {-0.330776879188771f, 0.9437089891455613f},
4625            {-0.9321888864830543f, 0.3619722087639923f},
4626            {-0.8809623252471085f, -0.47318641305008735f},
4627            {-0.21296163248563432f, -0.9770605626515961f},
4628            {0.604136498566135f, -0.7968808512571063f},
4629            {0.9982701582127194f, -0.05879363249495786f},
4630            {0.6935008202914851f, 0.7204558364362367f},
4631            {-0.09679820929680796f, 0.9953040272584711f},
4632            {-0.8193274492343137f, 0.5733258505694586f},
4633            {-0.9682340024187017f, -0.25004582891994304f},
4634            {-0.4392662937408502f, -0.8983569018954422f},
4635            {0.39723793388455464f, -0.9177156552457467f},
4636            {0.9556302892322005f, -0.2945687530984589f},
4637            {0.8449724198323217f, 0.5348098818484104f},
4638            {0.14273745857559722f, 0.9897605861618151f},
4639            {-0.6594300077680133f, 0.7517659641504648f},
4640            {-0.9999212381512442f, -0.01255059735959867f},
4641            {-0.6403535266476091f, -0.768080308893523f},
4642            {0.16753470770767478f, -0.9858661784001437f},
4643            {0.8581295336101056f, -0.5134332513054668f},
4644            {0.9479357869928937f, 0.31846152630759517f},
4645            {0.37407884501651706f, 0.9273969040875156f},
4646            {-0.461675964944643f, 0.8870486477034012f},
4647            {-0.9742049295269273f, 0.22566513972130173f},
4648            {-0.8046793020829978f, -0.5937097108850584f},
4649            {-0.07178636201352963f, -0.9974200309943962f},
4650            {0.7113652211526822f, -0.7028225395748172f},
4651            {0.9964799940037152f, 0.08383091047075403f},
4652            {0.5839450884626246f, 0.8117931594072332f},
4653            {-0.23741799789097484f, 0.9714075840127259f},
4654            {-0.8925614000865144f, 0.45092587758477687f},
4655            {-0.9228099950981292f, -0.38525538665538556f},
4656            {-0.30698631553196837f, -0.95171392869712f},
4657            {0.5237628071845146f, -0.8518641451605984f},
4658            {0.9878182118285335f, -0.15561227580071732f},
4659            {0.7602881737752754f, 0.6495859395164404f},
4660            {4.6967723669845613E-4f, 0.9999998897016406f},
4661            {-0.7596776469502666f, 0.6502998329417794f},
4662            {-0.9879639510809196f, -0.15468429579171308f},
4663            {-0.5245627784110601f, -0.8513717704420726f},
4664            {0.3060921834538644f, -0.9520018777441807f},
4665            {0.9224476966294768f, -0.3861220622846781f},
4666            {0.8929845854878761f, 0.45008724718774934f},
4667            {0.23833038910266038f, 0.9711841358002995f},
4668            {-0.5831822693781987f, 0.8123413326200348f},
4669            {-0.9964008074312266f, 0.0847669213219385f},
4670            {-0.712025106726807f, -0.7021540054650968f},
4671            {0.07084939947717452f, -0.9974870237721009f},
4672            {0.8041212432524677f, -0.5944653279629567f},
4673            {0.9744164792492415f, 0.22474991650168097f},
4674            {0.462509014279733f, 0.8866145790082576f},
4675    };
4676    private static final Float3[] GRAD_3D =
4677            {
4678                    new Float3(-0.448549002408981f,  1.174316525459290f,  0.000000000000001f  ),
4679                    new Float3(0.000000000000001f,  1.069324374198914f,  0.660878777503967f   ),
4680                    new Float3(0.448549002408981f,  1.174316525459290f,  0.000000000000001f   ),
4681                    new Float3(0.000000000000001f,  1.069324374198914f, -0.660878777503967f   ),
4682                    new Float3(-0.725767493247986f,  0.725767493247986f, -0.725767493247986f  ),
4683                    new Float3(-1.069324374198914f,  0.660878777503967f,  0.000000000000001f  ),
4684                    new Float3(-0.725767493247986f,  0.725767493247986f,  0.725767493247986f  ),
4685                    new Float3(0.725767493247986f,  0.725767493247986f,  0.725767493247986f   ),
4686                    new Float3(1.069324374198914f,  0.660878777503967f,  0.000000000000000f   ),
4687                    new Float3(0.725767493247986f,  0.725767493247986f, -0.725767493247986f   ),
4688                    new Float3(-0.660878777503967f,  0.000000000000003f, -1.069324374198914f  ),
4689                    new Float3(-1.174316525459290f,  0.000000000000003f, -0.448549002408981f  ),
4690                    new Float3(0.000000000000000f,  0.448549002408981f, -1.174316525459290f   ),
4691                    new Float3(-0.660878777503967f,  0.000000000000001f,  1.069324374198914f  ),
4692                    new Float3(0.000000000000001f,  0.448549002408981f,  1.174316525459290f   ),
4693                    new Float3(-1.174316525459290f,  0.000000000000001f,  0.448549002408981f  ),
4694                    new Float3(0.660878777503967f,  0.000000000000001f,  1.069324374198914f   ),
4695                    new Float3(1.174316525459290f,  0.000000000000001f,  0.448549002408981f   ),
4696                    new Float3(0.660878777503967f,  0.000000000000001f, -1.069324374198914f   ),
4697                    new Float3(1.174316525459290f,  0.000000000000001f, -0.448549002408981f   ),
4698                    new Float3(-0.725767493247986f, -0.725767493247986f, -0.725767493247986f  ),
4699                    new Float3(-1.069324374198914f, -0.660878777503967f, -0.000000000000001f  ),
4700                    new Float3(-0.000000000000001f, -0.448549002408981f, -1.174316525459290f  ),
4701                    new Float3(-0.000000000000001f, -0.448549002408981f,  1.174316525459290f  ),
4702                    new Float3(-0.725767493247986f, -0.725767493247986f,  0.725767493247986f  ),
4703                    new Float3(0.725767493247986f, -0.725767493247986f,  0.725767493247986f   ),
4704                    new Float3(1.069324374198914f, -0.660878777503967f,  0.000000000000001f   ),
4705                    new Float3(0.725767493247986f, -0.725767493247986f, -0.725767493247986f   ),
4706                    new Float3(-0.000000000000004f, -1.069324374198914f, -0.660878777503967f  ),
4707                    new Float3(-0.448549002408981f, -1.174316525459290f, -0.000000000000003f  ),
4708                    new Float3(-0.000000000000003f, -1.069324374198914f,  0.660878777503967f  ),
4709                    new Float3(0.448549002408981f, -1.174316525459290f,  0.000000000000003f   ),
4710            };
4711
4712
4713    protected static final float[] grad4f =
4714            {
4715                    -0.5875167f, 1.4183908f, 1.4183908f, 1.4183908f,
4716                    -0.5875167f, 1.4183908f, 1.4183908f, -1.4183908f,
4717                    -0.5875167f, 1.4183908f, -1.4183908f, 1.4183908f,
4718                    -0.5875167f, 1.4183908f, -1.4183908f, -1.4183908f,
4719                    -0.5875167f, -1.4183908f, 1.4183908f, 1.4183908f,
4720                    -0.5875167f, -1.4183908f, 1.4183908f, -1.4183908f,
4721                    -0.5875167f, -1.4183908f, -1.4183908f, 1.4183908f,
4722                    -0.5875167f, -1.4183908f, -1.4183908f, -1.4183908f,
4723                    1.4183908f, -0.5875167f, 1.4183908f, 1.4183908f,
4724                    1.4183908f, -0.5875167f, 1.4183908f, -1.4183908f,
4725                    1.4183908f, -0.5875167f, -1.4183908f, 1.4183908f,
4726                    1.4183908f, -0.5875167f, -1.4183908f, -1.4183908f,
4727                    -1.4183908f, -0.5875167f, 1.4183908f, 1.4183908f,
4728                    -1.4183908f, -0.5875167f, 1.4183908f, -1.4183908f,
4729                    -1.4183908f, -0.5875167f, -1.4183908f, 1.4183908f,
4730                    -1.4183908f, -0.5875167f, -1.4183908f, -1.4183908f,
4731                    1.4183908f, 1.4183908f, -0.5875167f, 1.4183908f,
4732                    1.4183908f, 1.4183908f, -0.5875167f, -1.4183908f,
4733                    1.4183908f, -1.4183908f, -0.5875167f, 1.4183908f,
4734                    1.4183908f, -1.4183908f, -0.5875167f, -1.4183908f,
4735                    -1.4183908f, 1.4183908f, -0.5875167f, 1.4183908f,
4736                    -1.4183908f, 1.4183908f, -0.5875167f, -1.4183908f,
4737                    -1.4183908f, -1.4183908f, -0.5875167f, 1.4183908f,
4738                    -1.4183908f, -1.4183908f, -0.5875167f, -1.4183908f,
4739                    1.4183908f, 1.4183908f, 1.4183908f, -0.5875167f,
4740                    1.4183908f, 1.4183908f, -1.4183908f, -0.5875167f,
4741                    1.4183908f, -1.4183908f, 1.4183908f, -0.5875167f,
4742                    1.4183908f, -1.4183908f, -1.4183908f, -0.5875167f,
4743                    -1.4183908f, 1.4183908f, 1.4183908f, -0.5875167f,
4744                    -1.4183908f, 1.4183908f, -1.4183908f, -0.5875167f,
4745                    -1.4183908f, -1.4183908f, 1.4183908f, -0.5875167f,
4746                    -1.4183908f, -1.4183908f, -1.4183908f, -0.5875167f,
4747                    0.5875167f, 1.4183908f, 1.4183908f, 1.4183908f,
4748                    0.5875167f, 1.4183908f, 1.4183908f, -1.4183908f,
4749                    0.5875167f, 1.4183908f, -1.4183908f, 1.4183908f,
4750                    0.5875167f, 1.4183908f, -1.4183908f, -1.4183908f,
4751                    0.5875167f, -1.4183908f, 1.4183908f, 1.4183908f,
4752                    0.5875167f, -1.4183908f, 1.4183908f, -1.4183908f,
4753                    0.5875167f, -1.4183908f, -1.4183908f, 1.4183908f,
4754                    0.5875167f, -1.4183908f, -1.4183908f, -1.4183908f,
4755                    1.4183908f, 0.5875167f, 1.4183908f, 1.4183908f,
4756                    1.4183908f, 0.5875167f, 1.4183908f, -1.4183908f,
4757                    1.4183908f, 0.5875167f, -1.4183908f, 1.4183908f,
4758                    1.4183908f, 0.5875167f, -1.4183908f, -1.4183908f,
4759                    -1.4183908f, 0.5875167f, 1.4183908f, 1.4183908f,
4760                    -1.4183908f, 0.5875167f, 1.4183908f, -1.4183908f,
4761                    -1.4183908f, 0.5875167f, -1.4183908f, 1.4183908f,
4762                    -1.4183908f, 0.5875167f, -1.4183908f, -1.4183908f,
4763                    1.4183908f, 1.4183908f, 0.5875167f, 1.4183908f,
4764                    1.4183908f, 1.4183908f, 0.5875167f, -1.4183908f,
4765                    1.4183908f, -1.4183908f, 0.5875167f, 1.4183908f,
4766                    1.4183908f, -1.4183908f, 0.5875167f, -1.4183908f,
4767                    -1.4183908f, 1.4183908f, 0.5875167f, 1.4183908f,
4768                    -1.4183908f, 1.4183908f, 0.5875167f, -1.4183908f,
4769                    -1.4183908f, -1.4183908f, 0.5875167f, 1.4183908f,
4770                    -1.4183908f, -1.4183908f, 0.5875167f, -1.4183908f,
4771                    1.4183908f, 1.4183908f, 1.4183908f, 0.5875167f,
4772                    1.4183908f, 1.4183908f, -1.4183908f, 0.5875167f,
4773                    1.4183908f, -1.4183908f, 1.4183908f, 0.5875167f,
4774                    1.4183908f, -1.4183908f, -1.4183908f, 0.5875167f,
4775                    -1.4183908f, 1.4183908f, 1.4183908f, 0.5875167f,
4776                    -1.4183908f, 1.4183908f, -1.4183908f, 0.5875167f,
4777                    -1.4183908f, -1.4183908f, 1.4183908f, 0.5875167f,
4778                    -1.4183908f, -1.4183908f, -1.4183908f, 0.5875167f,
4779            };
4780    private static final int[] SIMPLEX_4D = {0, 1, 3, 7, 0, 1, 7, 3,
4781            0, 0, 0, 0, 0, 3, 7, 1, 0, 0, 0, 0, 0, 0, 0, 0,
4782            0, 0, 0, 0, 1, 3, 7, 0, 0, 3, 1, 7, 0, 0, 0, 0,
4783            0, 7, 1, 3, 0, 7, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0,
4784            0, 0, 0, 0, 1, 7, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4785            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4786            0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 0, 7, 0, 0, 0, 0,
4787            1, 7, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4788            3, 7, 0, 1, 3, 7, 1, 0, 1, 0, 3, 7, 1, 0, 7, 3,
4789            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 7, 1,
4790            0, 0, 0, 0, 3, 1, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4791            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
4792            0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 7, 0, 0, 0, 0,
4793            0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 1, 3, 7, 0, 3, 1,
4794            0, 0, 0, 0, 7, 1, 3, 0, 3, 1, 0, 7, 0, 0, 0, 0,
4795            0, 0, 0, 0, 0, 0, 0, 0, 7, 1, 0, 3, 0, 0, 0, 0,
4796            7, 3, 0, 1, 7, 3, 1, 0};
4797    
4798    private static final Float2[] CELL_2D =
4799            {
4800                    new Float2(-0.4313539279f, 0.1281943404f), new Float2(-0.1733316799f, 0.415278375f), new Float2(-0.2821957395f, -0.3505218461f), new Float2(-0.2806473808f, 0.3517627718f), new Float2(0.3125508975f, -0.3237467165f), new Float2(0.3383018443f, -0.2967353402f), new Float2(-0.4393982022f, -0.09710417025f), new Float2(-0.4460443703f, -0.05953502905f),
4801                    new Float2(-0.302223039f, 0.3334085102f), new Float2(-0.212681052f, -0.3965687458f), new Float2(-0.2991156529f, 0.3361990872f), new Float2(0.2293323691f, 0.3871778202f), new Float2(0.4475439151f, -0.04695150755f), new Float2(0.1777518f, 0.41340573f), new Float2(0.1688522499f, -0.4171197882f), new Float2(-0.0976597166f, 0.4392750616f),
4802                    new Float2(0.08450188373f, 0.4419948321f), new Float2(-0.4098760448f, -0.1857461384f), new Float2(0.3476585782f, -0.2857157906f), new Float2(-0.3350670039f, -0.30038326f), new Float2(0.2298190031f, -0.3868891648f), new Float2(-0.01069924099f, 0.449872789f), new Float2(-0.4460141246f, -0.05976119672f), new Float2(0.3650293864f, 0.2631606867f),
4803                    new Float2(-0.349479423f, 0.2834856838f), new Float2(-0.4122720642f, 0.1803655873f), new Float2(-0.267327811f, 0.3619887311f), new Float2(0.322124041f, -0.3142230135f), new Float2(0.2880445931f, -0.3457315612f), new Float2(0.3892170926f, -0.2258540565f), new Float2(0.4492085018f, -0.02667811596f), new Float2(-0.4497724772f, 0.01430799601f),
4804                    new Float2(0.1278175387f, -0.4314657307f), new Float2(-0.03572100503f, 0.4485799926f), new Float2(-0.4297407068f, -0.1335025276f), new Float2(-0.3217817723f, 0.3145735065f), new Float2(-0.3057158873f, 0.3302087162f), new Float2(-0.414503978f, 0.1751754899f), new Float2(-0.3738139881f, 0.2505256519f), new Float2(0.2236891408f, -0.3904653228f),
4805                    new Float2(0.002967775577f, -0.4499902136f), new Float2(0.1747128327f, -0.4146991995f), new Float2(-0.4423772489f, -0.08247647938f), new Float2(-0.2763960987f, -0.355112935f), new Float2(-0.4019385906f, -0.2023496216f), new Float2(0.3871414161f, -0.2293938184f), new Float2(-0.430008727f, 0.1326367019f), new Float2(-0.03037574274f, -0.4489736231f),
4806                    new Float2(-0.3486181573f, 0.2845441624f), new Float2(0.04553517144f, -0.4476902368f), new Float2(-0.0375802926f, 0.4484280562f), new Float2(0.3266408905f, 0.3095250049f), new Float2(0.06540017593f, -0.4452222108f), new Float2(0.03409025829f, 0.448706869f), new Float2(-0.4449193635f, 0.06742966669f), new Float2(-0.4255936157f, -0.1461850686f),
4807                    new Float2(0.449917292f, 0.008627302568f), new Float2(0.05242606404f, 0.4469356864f), new Float2(-0.4495305179f, -0.02055026661f), new Float2(-0.1204775703f, 0.4335725488f), new Float2(-0.341986385f, -0.2924813028f), new Float2(0.3865320182f, 0.2304191809f), new Float2(0.04506097811f, -0.447738214f), new Float2(-0.06283465979f, 0.4455915232f),
4808                    new Float2(0.3932600341f, -0.2187385324f), new Float2(0.4472261803f, -0.04988730975f), new Float2(0.3753571011f, -0.2482076684f), new Float2(-0.273662295f, 0.357223947f), new Float2(0.1700461538f, 0.4166344988f), new Float2(0.4102692229f, 0.1848760794f), new Float2(0.323227187f, -0.3130881435f), new Float2(-0.2882310238f, -0.3455761521f),
4809                    new Float2(0.2050972664f, 0.4005435199f), new Float2(0.4414085979f, -0.08751256895f), new Float2(-0.1684700334f, 0.4172743077f), new Float2(-0.003978032396f, 0.4499824166f), new Float2(-0.2055133639f, 0.4003301853f), new Float2(-0.006095674897f, -0.4499587123f), new Float2(-0.1196228124f, -0.4338091548f), new Float2(0.3901528491f, -0.2242337048f),
4810                    new Float2(0.01723531752f, 0.4496698165f), new Float2(-0.3015070339f, 0.3340561458f), new Float2(-0.01514262423f, -0.4497451511f), new Float2(-0.4142574071f, -0.1757577897f), new Float2(-0.1916377265f, -0.4071547394f), new Float2(0.3749248747f, 0.2488600778f), new Float2(-0.2237774255f, 0.3904147331f), new Float2(-0.4166343106f, -0.1700466149f),
4811                    new Float2(0.3619171625f, 0.267424695f), new Float2(0.1891126846f, -0.4083336779f), new Float2(-0.3127425077f, 0.323561623f), new Float2(-0.3281807787f, 0.307891826f), new Float2(-0.2294806661f, 0.3870899429f), new Float2(-0.3445266136f, 0.2894847362f), new Float2(-0.4167095422f, -0.1698621719f), new Float2(-0.257890321f, -0.3687717212f),
4812                    new Float2(-0.3612037825f, 0.2683874578f), new Float2(0.2267996491f, 0.3886668486f), new Float2(0.207157062f, 0.3994821043f), new Float2(0.08355176718f, -0.4421754202f), new Float2(-0.4312233307f, 0.1286329626f), new Float2(0.3257055497f, 0.3105090899f), new Float2(0.177701095f, -0.4134275279f), new Float2(-0.445182522f, 0.06566979625f),
4813                    new Float2(0.3955143435f, 0.2146355146f), new Float2(-0.4264613988f, 0.1436338239f), new Float2(-0.3793799665f, -0.2420141339f), new Float2(0.04617599081f, -0.4476245948f), new Float2(-0.371405428f, -0.2540826796f), new Float2(0.2563570295f, -0.3698392535f), new Float2(0.03476646309f, 0.4486549822f), new Float2(-0.3065454405f, 0.3294387544f),
4814                    new Float2(-0.2256979823f, 0.3893076172f), new Float2(0.4116448463f, -0.1817925206f), new Float2(-0.2907745828f, -0.3434387019f), new Float2(0.2842278468f, -0.348876097f), new Float2(0.3114589359f, -0.3247973695f), new Float2(0.4464155859f, -0.0566844308f), new Float2(-0.3037334033f, -0.3320331606f), new Float2(0.4079607166f, 0.1899159123f),
4815                    new Float2(-0.3486948919f, -0.2844501228f), new Float2(0.3264821436f, 0.3096924441f), new Float2(0.3211142406f, 0.3152548881f), new Float2(0.01183382662f, 0.4498443737f), new Float2(0.4333844092f, 0.1211526057f), new Float2(0.3118668416f, 0.324405723f), new Float2(-0.272753471f, 0.3579183483f), new Float2(-0.422228622f, -0.1556373694f),
4816                    new Float2(-0.1009700099f, -0.4385260051f), new Float2(-0.2741171231f, -0.3568750521f), new Float2(-0.1465125133f, 0.4254810025f), new Float2(0.2302279044f, -0.3866459777f), new Float2(-0.3699435608f, 0.2562064828f), new Float2(0.105700352f, -0.4374099171f), new Float2(-0.2646713633f, 0.3639355292f), new Float2(0.3521828122f, 0.2801200935f),
4817                    new Float2(-0.1864187807f, -0.4095705534f), new Float2(0.1994492955f, -0.4033856449f), new Float2(0.3937065066f, 0.2179339044f), new Float2(-0.3226158377f, 0.3137180602f), new Float2(0.3796235338f, 0.2416318948f), new Float2(0.1482921929f, 0.4248640083f), new Float2(-0.407400394f, 0.1911149365f), new Float2(0.4212853031f, 0.1581729856f),
4818                    new Float2(-0.2621297173f, 0.3657704353f), new Float2(-0.2536986953f, -0.3716678248f), new Float2(-0.2100236383f, 0.3979825013f), new Float2(0.3624152444f, 0.2667493029f), new Float2(-0.3645038479f, -0.2638881295f), new Float2(0.2318486784f, 0.3856762766f), new Float2(-0.3260457004f, 0.3101519002f), new Float2(-0.2130045332f, -0.3963950918f),
4819                    new Float2(0.3814998766f, -0.2386584257f), new Float2(-0.342977305f, 0.2913186713f), new Float2(-0.4355865605f, 0.1129794154f), new Float2(-0.2104679605f, 0.3977477059f), new Float2(0.3348364681f, -0.3006402163f), new Float2(0.3430468811f, 0.2912367377f), new Float2(-0.2291836801f, -0.3872658529f), new Float2(0.2547707298f, -0.3709337882f),
4820                    new Float2(0.4236174945f, -0.151816397f), new Float2(-0.15387742f, 0.4228731957f), new Float2(-0.4407449312f, 0.09079595574f), new Float2(-0.06805276192f, -0.444824484f), new Float2(0.4453517192f, -0.06451237284f), new Float2(0.2562464609f, -0.3699158705f), new Float2(0.3278198355f, -0.3082761026f), new Float2(-0.4122774207f, -0.1803533432f),
4821                    new Float2(0.3354090914f, -0.3000012356f), new Float2(0.446632869f, -0.05494615882f), new Float2(-0.1608953296f, 0.4202531296f), new Float2(-0.09463954939f, 0.4399356268f), new Float2(-0.02637688324f, -0.4492262904f), new Float2(0.447102804f, -0.05098119915f), new Float2(-0.4365670908f, 0.1091291678f), new Float2(-0.3959858651f, 0.2137643437f),
4822                    new Float2(-0.4240048207f, -0.1507312575f), new Float2(-0.3882794568f, 0.2274622243f), new Float2(-0.4283652566f, -0.1378521198f), new Float2(0.3303888091f, 0.305521251f), new Float2(0.3321434919f, -0.3036127481f), new Float2(-0.413021046f, -0.1786438231f), new Float2(0.08403060337f, -0.4420846725f), new Float2(-0.3822882919f, 0.2373934748f),
4823                    new Float2(-0.3712395594f, -0.2543249683f), new Float2(0.4472363971f, -0.04979563372f), new Float2(-0.4466591209f, 0.05473234629f), new Float2(0.0486272539f, -0.4473649407f), new Float2(-0.4203101295f, -0.1607463688f), new Float2(0.2205360833f, 0.39225481f), new Float2(-0.3624900666f, 0.2666476169f), new Float2(-0.4036086833f, -0.1989975647f),
4824                    new Float2(0.2152727807f, 0.3951678503f), new Float2(-0.4359392962f, -0.1116106179f), new Float2(0.4178354266f, 0.1670735057f), new Float2(0.2007630161f, 0.4027334247f), new Float2(-0.07278067175f, -0.4440754146f), new Float2(0.3644748615f, -0.2639281632f), new Float2(-0.4317451775f, 0.126870413f), new Float2(-0.297436456f, 0.3376855855f),
4825                    new Float2(-0.2998672222f, 0.3355289094f), new Float2(-0.2673674124f, 0.3619594822f), new Float2(0.2808423357f, 0.3516071423f), new Float2(0.3498946567f, 0.2829730186f), new Float2(-0.2229685561f, 0.390877248f), new Float2(0.3305823267f, 0.3053118493f), new Float2(-0.2436681211f, -0.3783197679f), new Float2(-0.03402776529f, 0.4487116125f),
4826                    new Float2(-0.319358823f, 0.3170330301f), new Float2(0.4454633477f, -0.06373700535f), new Float2(0.4483504221f, 0.03849544189f), new Float2(-0.4427358436f, -0.08052932871f), new Float2(0.05452298565f, 0.4466847255f), new Float2(-0.2812560807f, 0.3512762688f), new Float2(0.1266696921f, 0.4318041097f), new Float2(-0.3735981243f, 0.2508474468f),
4827                    new Float2(0.2959708351f, -0.3389708908f), new Float2(-0.3714377181f, 0.254035473f), new Float2(-0.404467102f, -0.1972469604f), new Float2(0.1636165687f, -0.419201167f), new Float2(0.3289185495f, -0.3071035458f), new Float2(-0.2494824991f, -0.3745109914f), new Float2(0.03283133272f, 0.4488007393f), new Float2(-0.166306057f, -0.4181414777f),
4828                    new Float2(-0.106833179f, 0.4371346153f), new Float2(0.06440260376f, -0.4453676062f), new Float2(-0.4483230967f, 0.03881238203f), new Float2(-0.421377757f, -0.1579265206f), new Float2(0.05097920662f, -0.4471030312f), new Float2(0.2050584153f, -0.4005634111f), new Float2(0.4178098529f, -0.167137449f), new Float2(-0.3565189504f, -0.2745801121f),
4829                    new Float2(0.4478398129f, 0.04403977727f), new Float2(-0.3399999602f, -0.2947881053f), new Float2(0.3767121994f, 0.2461461331f), new Float2(-0.3138934434f, 0.3224451987f), new Float2(-0.1462001792f, -0.4255884251f), new Float2(0.3970290489f, -0.2118205239f), new Float2(0.4459149305f, -0.06049689889f), new Float2(-0.4104889426f, -0.1843877112f),
4830                    new Float2(0.1475103971f, -0.4251360756f), new Float2(0.09258030352f, 0.4403735771f), new Float2(-0.1589664637f, -0.4209865359f), new Float2(0.2482445008f, 0.3753327428f), new Float2(0.4383624232f, -0.1016778537f), new Float2(0.06242802956f, 0.4456486745f), new Float2(0.2846591015f, -0.3485243118f), new Float2(-0.344202744f, -0.2898697484f),
4831                    new Float2(0.1198188883f, -0.4337550392f), new Float2(-0.243590703f, 0.3783696201f), new Float2(0.2958191174f, -0.3391033025f), new Float2(-0.1164007991f, 0.4346847754f), new Float2(0.1274037151f, -0.4315881062f), new Float2(0.368047306f, 0.2589231171f), new Float2(0.2451436949f, 0.3773652989f), new Float2(-0.4314509715f, 0.12786735f),
4832            };
4833
4834    private static final Float3[] CELL_3D =
4835            {
4836                    new Float3(0.1453787434f, -0.4149781685f, -0.0956981749f), new Float3(-0.01242829687f, -0.1457918398f, -0.4255470325f), new Float3(0.2877979582f, -0.02606483451f, -0.3449535616f), new Float3(-0.07732986802f, 0.2377094325f, 0.3741848704f), new Float3(0.1107205875f, -0.3552302079f, -0.2530858567f), new Float3(0.2755209141f, 0.2640521179f, -0.238463215f), new Float3(0.294168941f, 0.1526064594f, 0.3044271714f), new Float3(0.4000921098f, -0.2034056362f, 0.03244149937f),
4837                    new Float3(-0.1697304074f, 0.3970864695f, -0.1265461359f), new Float3(-0.1483224484f, -0.3859694688f, 0.1775613147f), new Float3(0.2623596946f, -0.2354852944f, 0.2796677792f), new Float3(-0.2709003183f, 0.3505271138f, -0.07901746678f), new Float3(-0.03516550699f, 0.3885234328f, 0.2243054374f), new Float3(-0.1267712655f, 0.1920044036f, 0.3867342179f), new Float3(0.02952021915f, 0.4409685861f, 0.08470692262f), new Float3(-0.2806854217f, -0.266996757f, 0.2289725438f),
4838                    new Float3(-0.171159547f, 0.2141185563f, 0.3568720405f), new Float3(0.2113227183f, 0.3902405947f, -0.07453178509f), new Float3(-0.1024352839f, 0.2128044156f, -0.3830421561f), new Float3(-0.3304249877f, -0.1566986703f, 0.2622305365f), new Float3(0.2091111325f, 0.3133278055f, -0.2461670583f), new Float3(0.344678154f, -0.1944240454f, -0.2142341261f), new Float3(0.1984478035f, -0.3214342325f, -0.2445373252f), new Float3(-0.2929008603f, 0.2262915116f, 0.2559320961f),
4839                    new Float3(-0.1617332831f, 0.006314769776f, -0.4198838754f), new Float3(-0.3582060271f, -0.148303178f, -0.2284613961f), new Float3(-0.1852067326f, -0.3454119342f, -0.2211087107f), new Float3(0.3046301062f, 0.1026310383f, 0.314908508f), new Float3(-0.03816768434f, -0.2551766358f, -0.3686842991f), new Float3(-0.4084952196f, 0.1805950793f, 0.05492788837f), new Float3(-0.02687443361f, -0.2749741471f, 0.3551999201f), new Float3(-0.03801098351f, 0.3277859044f, 0.3059600725f),
4840                    new Float3(0.2371120802f, 0.2900386767f, -0.2493099024f), new Float3(0.4447660503f, 0.03946930643f, 0.05590469027f), new Float3(0.01985147278f, -0.01503183293f, -0.4493105419f), new Float3(0.4274339143f, 0.03345994256f, -0.1366772882f), new Float3(-0.2072988631f, 0.2871414597f, -0.2776273824f), new Float3(-0.3791240978f, 0.1281177671f, 0.2057929936f), new Float3(-0.2098721267f, -0.1007087278f, -0.3851122467f), new Float3(0.01582798878f, 0.4263894424f, 0.1429738373f),
4841                    new Float3(-0.1888129464f, -0.3160996813f, -0.2587096108f), new Float3(0.1612988974f, -0.1974805082f, -0.3707885038f), new Float3(-0.08974491322f, 0.229148752f, -0.3767448739f), new Float3(0.07041229526f, 0.4150230285f, -0.1590534329f), new Float3(-0.1082925611f, -0.1586061639f, 0.4069604477f), new Float3(0.2474100658f, -0.3309414609f, 0.1782302128f), new Float3(-0.1068836661f, -0.2701644537f, -0.3436379634f), new Float3(0.2396452163f, 0.06803600538f, -0.3747549496f),
4842                    new Float3(-0.3063886072f, 0.2597428179f, 0.2028785103f), new Float3(0.1593342891f, -0.3114350249f, -0.2830561951f), new Float3(0.2709690528f, 0.1412648683f, -0.3303331794f), new Float3(-0.1519780427f, 0.3623355133f, 0.2193527988f), new Float3(0.1699773681f, 0.3456012883f, 0.2327390037f), new Float3(-0.1986155616f, 0.3836276443f, -0.1260225743f), new Float3(-0.1887482106f, -0.2050154888f, -0.353330953f), new Float3(0.2659103394f, 0.3015631259f, -0.2021172246f),
4843                    new Float3(-0.08838976154f, -0.4288819642f, -0.1036702021f), new Float3(-0.04201869311f, 0.3099592485f, 0.3235115047f), new Float3(-0.3230334656f, 0.201549922f, -0.2398478873f), new Float3(0.2612720941f, 0.2759854499f, -0.2409749453f), new Float3(0.385713046f, 0.2193460345f, 0.07491837764f), new Float3(0.07654967953f, 0.3721732183f, 0.241095919f), new Float3(0.4317038818f, -0.02577753072f, 0.1243675091f), new Float3(-0.2890436293f, -0.3418179959f, -0.04598084447f),
4844                    new Float3(-0.2201947582f, 0.383023377f, -0.08548310451f), new Float3(0.4161322773f, -0.1669634289f, -0.03817251927f), new Float3(0.2204718095f, 0.02654238946f, -0.391391981f), new Float3(-0.1040307469f, 0.3890079625f, -0.2008741118f), new Float3(-0.1432122615f, 0.371614387f, -0.2095065525f), new Float3(0.3978380468f, -0.06206669342f, 0.2009293758f), new Float3(-0.2599274663f, 0.2616724959f, -0.2578084893f), new Float3(0.4032618332f, -0.1124593585f, 0.1650235939f),
4845                    new Float3(-0.08953470255f, -0.3048244735f, 0.3186935478f), new Float3(0.118937202f, -0.2875221847f, 0.325092195f), new Float3(0.02167047076f, -0.03284630549f, -0.4482761547f), new Float3(-0.3411343612f, 0.2500031105f, 0.1537068389f), new Float3(0.3162964612f, 0.3082064153f, -0.08640228117f), new Float3(0.2355138889f, -0.3439334267f, -0.1695376245f), new Float3(-0.02874541518f, -0.3955933019f, 0.2125550295f), new Float3(-0.2461455173f, 0.02020282325f, -0.3761704803f),
4846                    new Float3(0.04208029445f, -0.4470439576f, 0.02968078139f), new Float3(0.2727458746f, 0.2288471896f, -0.2752065618f), new Float3(-0.1347522818f, -0.02720848277f, -0.4284874806f), new Float3(0.3829624424f, 0.1231931484f, -0.2016512234f), new Float3(-0.3547613644f, 0.1271702173f, 0.2459107769f), new Float3(0.2305790207f, 0.3063895591f, 0.2354968222f), new Float3(-0.08323845599f, -0.1922245118f, 0.3982726409f), new Float3(0.2993663085f, -0.2619918095f, -0.2103333191f),
4847                    new Float3(-0.2154865723f, 0.2706747713f, 0.287751117f), new Float3(0.01683355354f, -0.2680655787f, -0.3610505186f), new Float3(0.05240429123f, 0.4335128183f, -0.1087217856f), new Float3(0.00940104872f, -0.4472890582f, 0.04841609928f), new Float3(0.3465688735f, 0.01141914583f, -0.2868093776f), new Float3(-0.3706867948f, -0.2551104378f, 0.003156692623f), new Float3(0.2741169781f, 0.2139972417f, -0.2855959784f), new Float3(0.06413433865f, 0.1708718512f, 0.4113266307f),
4848                    new Float3(-0.388187972f, -0.03973280434f, -0.2241236325f), new Float3(0.06419469312f, -0.2803682491f, 0.3460819069f), new Float3(-0.1986120739f, -0.3391173584f, 0.2192091725f), new Float3(-0.203203009f, -0.3871641506f, 0.1063600375f), new Float3(-0.1389736354f, -0.2775901578f, -0.3257760473f), new Float3(-0.06555641638f, 0.342253257f, -0.2847192729f), new Float3(-0.2529246486f, -0.2904227915f, 0.2327739768f), new Float3(0.1444476522f, 0.1069184044f, 0.4125570634f),
4849                    new Float3(-0.3643780054f, -0.2447099973f, -0.09922543227f), new Float3(0.4286142488f, -0.1358496089f, -0.01829506817f), new Float3(0.165872923f, -0.3136808464f, -0.2767498872f), new Float3(0.2219610524f, -0.3658139958f, 0.1393320198f), new Float3(0.04322940318f, -0.3832730794f, 0.2318037215f), new Float3(-0.08481269795f, -0.4404869674f, -0.03574965489f), new Float3(0.1822082075f, -0.3953259299f, 0.1140946023f), new Float3(-0.3269323334f, 0.3036542563f, 0.05838957105f),
4850                    new Float3(-0.4080485344f, 0.04227858267f, -0.184956522f), new Float3(0.2676025294f, -0.01299671652f, 0.36155217f), new Float3(0.3024892441f, -0.1009990293f, -0.3174892964f), new Float3(0.1448494052f, 0.425921681f, -0.0104580805f), new Float3(0.4198402157f, 0.08062320474f, 0.1404780841f), new Float3(-0.3008872161f, -0.333040905f, -0.03241355801f), new Float3(0.3639310428f, -0.1291284382f, -0.2310412139f), new Float3(0.3295806598f, 0.0184175994f, -0.3058388149f),
4851                    new Float3(0.2776259487f, -0.2974929052f, -0.1921504723f), new Float3(0.4149000507f, -0.144793182f, -0.09691688386f), new Float3(0.145016715f, -0.0398992945f, 0.4241205002f), new Float3(0.09299023471f, -0.299732164f, -0.3225111565f), new Float3(0.1028907093f, -0.361266869f, 0.247789732f), new Float3(0.2683057049f, -0.07076041213f, -0.3542668666f), new Float3(-0.4227307273f, -0.07933161816f, -0.1323073187f), new Float3(-0.1781224702f, 0.1806857196f, -0.3716517945f),
4852                    new Float3(0.4390788626f, -0.02841848598f, -0.09435116353f), new Float3(0.2972583585f, 0.2382799621f, -0.2394997452f), new Float3(-0.1707002821f, 0.2215845691f, 0.3525077196f), new Float3(0.3806686614f, 0.1471852559f, -0.1895464869f), new Float3(-0.1751445661f, -0.274887877f, 0.3102596268f), new Float3(-0.2227237566f, -0.2316778837f, 0.3149912482f), new Float3(0.1369633021f, 0.1341343041f, -0.4071228836f), new Float3(-0.3529503428f, -0.2472893463f, -0.129514612f),
4853                    new Float3(-0.2590744185f, -0.2985577559f, -0.2150435121f), new Float3(-0.3784019401f, 0.2199816631f, -0.1044989934f), new Float3(-0.05635805671f, 0.1485737441f, 0.4210102279f), new Float3(0.3251428613f, 0.09666046873f, -0.2957006485f), new Float3(-0.4190995804f, 0.1406751354f, -0.08405978803f), new Float3(-0.3253150961f, -0.3080335042f, -0.04225456877f), new Float3(0.2857945863f, -0.05796152095f, 0.3427271751f), new Float3(-0.2733604046f, 0.1973770973f, -0.2980207554f),
4854                    new Float3(0.219003657f, 0.2410037886f, -0.3105713639f), new Float3(0.3182767252f, -0.271342949f, 0.1660509868f), new Float3(-0.03222023115f, -0.3331161506f, -0.300824678f), new Float3(-0.3087780231f, 0.1992794134f, -0.2596995338f), new Float3(-0.06487611647f, -0.4311322747f, 0.1114273361f), new Float3(0.3921171432f, -0.06294284106f, -0.2116183942f), new Float3(-0.1606404506f, -0.358928121f, -0.2187812825f), new Float3(-0.03767771199f, -0.2290351443f, 0.3855169162f),
4855                    new Float3(0.1394866832f, -0.3602213994f, 0.2308332918f), new Float3(-0.4345093872f, 0.005751117145f, 0.1169124335f), new Float3(-0.1044637494f, 0.4168128432f, -0.1336202785f), new Float3(0.2658727501f, 0.2551943237f, 0.2582393035f), new Float3(0.2051461999f, 0.1975390727f, 0.3484154868f), new Float3(-0.266085566f, 0.23483312f, 0.2766800993f), new Float3(0.07849405464f, -0.3300346342f, -0.2956616708f), new Float3(-0.2160686338f, 0.05376451292f, -0.3910546287f),
4856                    new Float3(-0.185779186f, 0.2148499206f, 0.3490352499f), new Float3(0.02492421743f, -0.3229954284f, -0.3123343347f), new Float3(-0.120167831f, 0.4017266681f, 0.1633259825f), new Float3(-0.02160084693f, -0.06885389554f, 0.4441762538f), new Float3(0.2597670064f, 0.3096300784f, 0.1978643903f), new Float3(-0.1611553854f, -0.09823036005f, 0.4085091653f), new Float3(-0.3278896792f, 0.1461670309f, 0.2713366126f), new Float3(0.2822734956f, 0.03754421121f, -0.3484423997f),
4857                    new Float3(0.03169341113f, 0.347405252f, -0.2842624114f), new Float3(0.2202613604f, -0.3460788041f, -0.1849713341f), new Float3(0.2933396046f, 0.3031973659f, 0.1565989581f), new Float3(-0.3194922995f, 0.2453752201f, -0.200538455f), new Float3(-0.3441586045f, -0.1698856132f, -0.2349334659f), new Float3(0.2703645948f, -0.3574277231f, 0.04060059933f), new Float3(0.2298568861f, 0.3744156221f, 0.0973588921f), new Float3(0.09326603877f, -0.3170108894f, 0.3054595587f),
4858                    new Float3(-0.1116165319f, -0.2985018719f, 0.3177080142f), new Float3(0.2172907365f, -0.3460005203f, -0.1885958001f), new Float3(0.1991339479f, 0.3820341668f, -0.1299829458f), new Float3(-0.0541918155f, -0.2103145071f, 0.39412061f), new Float3(0.08871336998f, 0.2012117383f, 0.3926114802f), new Float3(0.2787673278f, 0.3505404674f, 0.04370535101f), new Float3(-0.322166438f, 0.3067213525f, 0.06804996813f), new Float3(-0.4277366384f, 0.132066775f, 0.04582286686f),
4859                    new Float3(0.240131882f, -0.1612516055f, 0.344723946f), new Float3(0.1448607981f, -0.2387819045f, 0.3528435224f), new Float3(-0.3837065682f, -0.2206398454f, 0.08116235683f), new Float3(-0.4382627882f, -0.09082753406f, -0.04664855374f), new Float3(-0.37728353f, 0.05445141085f, 0.2391488697f), new Float3(0.1259579313f, 0.348394558f, 0.2554522098f), new Float3(-0.1406285511f, -0.270877371f, -0.3306796947f), new Float3(-0.1580694418f, 0.4162931958f, -0.06491553533f),
4860                    new Float3(0.2477612106f, -0.2927867412f, -0.2353514536f), new Float3(0.2916132853f, 0.3312535401f, 0.08793624968f), new Float3(0.07365265219f, -0.1666159848f, 0.411478311f), new Float3(-0.26126526f, -0.2422237692f, 0.2748965434f), new Float3(-0.3721862032f, 0.252790166f, 0.008634938242f), new Float3(-0.3691191571f, -0.255281188f, 0.03290232422f), new Float3(0.2278441737f, -0.3358364886f, 0.1944244981f), new Float3(0.363398169f, -0.2310190248f, 0.1306597909f),
4861                    new Float3(-0.304231482f, -0.2698452035f, 0.1926830856f), new Float3(-0.3199312232f, 0.316332536f, -0.008816977938f), new Float3(0.2874852279f, 0.1642275508f, -0.304764754f), new Float3(-0.1451096801f, 0.3277541114f, -0.2720669462f), new Float3(0.3220090754f, 0.0511344108f, 0.3101538769f), new Float3(-0.1247400865f, -0.04333605335f, -0.4301882115f), new Float3(-0.2829555867f, -0.3056190617f, -0.1703910946f), new Float3(0.1069384374f, 0.3491024667f, -0.2630430352f),
4862                    new Float3(-0.1420661144f, -0.3055376754f, -0.2982682484f), new Float3(-0.250548338f, 0.3156466809f, -0.2002316239f), new Float3(0.3265787872f, 0.1871229129f, 0.2466400438f), new Float3(0.07646097258f, -0.3026690852f, 0.324106687f), new Float3(0.3451771584f, 0.2757120714f, -0.0856480183f), new Float3(0.298137964f, 0.2852657134f, 0.179547284f), new Float3(0.2812250376f, 0.3466716415f, 0.05684409612f), new Float3(0.4390345476f, -0.09790429955f, -0.01278335452f),
4863                    new Float3(0.2148373234f, 0.1850172527f, 0.3494474791f), new Float3(0.2595421179f, -0.07946825393f, 0.3589187731f), new Float3(0.3182823114f, -0.307355516f, -0.08203022006f), new Float3(-0.4089859285f, -0.04647718411f, 0.1818526372f), new Float3(-0.2826749061f, 0.07417482322f, 0.3421885344f), new Float3(0.3483864637f, 0.225442246f, -0.1740766085f), new Float3(-0.3226415069f, -0.1420585388f, -0.2796816575f), new Float3(0.4330734858f, -0.118868561f, -0.02859407492f),
4864                    new Float3(-0.08717822568f, -0.3909896417f, -0.2050050172f), new Float3(-0.2149678299f, 0.3939973956f, -0.03247898316f), new Float3(-0.2687330705f, 0.322686276f, -0.1617284888f), new Float3(0.2105665099f, -0.1961317136f, -0.3459683451f), new Float3(0.4361845915f, -0.1105517485f, 0.004616608544f), new Float3(0.05333333359f, -0.313639498f, -0.3182543336f), new Float3(-0.05986216652f, 0.1361029153f, -0.4247264031f), new Float3(0.3664988455f, 0.2550543014f, -0.05590974511f),
4865                    new Float3(-0.2341015558f, -0.182405731f, 0.3382670703f), new Float3(-0.04730947785f, -0.4222150243f, -0.1483114513f), new Float3(-0.2391566239f, -0.2577696514f, -0.2808182972f), new Float3(-0.1242081035f, 0.4256953395f, -0.07652336246f), new Float3(0.2614832715f, -0.3650179274f, 0.02980623099f), new Float3(-0.2728794681f, -0.3499628774f, 0.07458404908f), new Float3(0.007892900508f, -0.1672771315f, 0.4176793787f), new Float3(-0.01730330376f, 0.2978486637f, -0.3368779738f),
4866                    new Float3(0.2054835762f, -0.3252600376f, -0.2334146693f), new Float3(-0.3231994983f, 0.1564282844f, -0.2712420987f), new Float3(-0.2669545963f, 0.2599343665f, -0.2523278991f), new Float3(-0.05554372779f, 0.3170813944f, -0.3144428146f), new Float3(-0.2083935713f, -0.310922837f, -0.2497981362f), new Float3(0.06989323478f, -0.3156141536f, 0.3130537363f), new Float3(0.3847566193f, -0.1605309138f, -0.1693876312f), new Float3(-0.3026215288f, -0.3001537679f, -0.1443188342f),
4867                    new Float3(0.3450735512f, 0.08611519592f, 0.2756962409f), new Float3(0.1814473292f, -0.2788782453f, -0.3029914042f), new Float3(-0.03855010448f, 0.09795110726f, 0.4375151083f), new Float3(0.3533670318f, 0.2665752752f, 0.08105160988f), new Float3(-0.007945601311f, 0.140359426f, -0.4274764309f), new Float3(0.4063099273f, -0.1491768253f, -0.1231199324f), new Float3(-0.2016773589f, 0.008816271194f, -0.4021797064f), new Float3(-0.07527055435f, -0.425643481f, -0.1251477955f),
4868            };
4869
4870    protected static final float[] grad6f = {
4871            0.31733186658157f, 0.043599150809166f, -0.63578104939541f,
4872            0.60224147484783f, -0.061995657882187f, 0.35587048501823f,
4873            -0.54645425808647f, -0.75981513883963f, -0.035144342454363f,
4874            0.13137365402959f, 0.29650029456531f, 0.13289887942467f,
4875            0.72720729277573f, -0.0170513084554f, 0.10403853926717f, 0.57016794579524f,
4876            0.10006650294475f, -0.35348266879289f,
4877            0.0524867271859f, 0.16599786784909f, -0.49406271077513f, 0.51847470894887f,
4878            0.63927166664011f, -0.21933445140234f,
4879            -0.57224122530978f, -0.089985946187774f, 0.44829955643248f,
4880            0.53836681748476f, -0.051299333576026f, -0.41352093713992f,
4881            -0.35034584363296f, -0.37367516013323f, -0.52676009109159f,
4882            0.12379417201967f, 0.42566489477591f, 0.51345191723381f,
4883            0.40936909283115f, 0.33036021753157f, 0.46771483894695f, 0.15073372728805f,
4884            0.51541333179083f, -0.46491971651678f,
4885            -0.64339751231027f, -0.29341468636474f, -0.50841617762291f,
4886            -0.080659811936781f, -0.46873502824317f, -0.12345817650503f,
4887            0.46950904113222f, 0.41685007896275f, -0.33378791988356f,
4888            -0.39617029121348f, 0.54659770033168f, 0.19662896748851f,
4889            -0.49213884108338f, 0.50450587466563f, -0.0073247243900323f,
4890            0.57958418990163f, 0.39591449230465f, 0.10272980841415f,
4891            0.34572956497624f, 0.62770109739866f, 0.12165109216674f, 0.35267248385686f,
4892            0.34842369637704f, -0.47527514024373f,
4893            0.076282233884284f, 0.56461194794873f, -0.392426730607f,
4894            -0.20639693057567f, 0.33197602170266f, 0.60711436994661f,
4895            0.46792592791359f, -0.38434666353171f, -0.46719345820863f,
4896            -0.40169520060432f, -0.061343490026986f, 0.49993117813162f,
4897            -0.25398819915038f, -0.82255018555745f, 0.40372967512401f,
4898            0.21051604195389f, 0.020384827146984f, 0.22621006002887f,
4899            0.23269489013955f, -0.42234243708413f, -0.18886779174866f,
4900            0.44290933725703f, -0.40895242871151f, 0.60695810498111f,
4901            -0.13615585122038f, 0.26142849716038f, 0.68738606675966f,
4902            0.42914965171764f, 0.26332301994884f, 0.43256061294487f,
4903            0.06145597366231f, -0.25432792035414f, 0.65050463165568f,
4904            0.35622065678761f, -0.52670947710524f, -0.32259598080167f,
4905            -0.28027055313228f, 0.30275296247348f, 0.39083872911587f,
4906            0.17564171472763f, 0.25278203996272f, 0.76307625890429f,
4907            -0.62937098181034f, -0.24958587788613f, 0.11855057687171f,
4908            0.52714220921895f, 0.47759151204224f, -0.14687496867489f,
4909            0.68607574135496f, 0.28465344118508f, 0.57132493696771f, 0.11365238375433f,
4910            -0.32111327299854f, -0.076352560636185f,
4911            0.42669573845021f, -0.1643996530281f, -0.54881376863042f,
4912            -0.56551221465284f, 0.4027156095588f, -0.087880721039792f,
4913            -0.30211042220321f, -0.47278547361731f, 0.050137867251391f,
4914            0.46804387457884f, -0.39450159355792f, 0.55497099667426f,
4915            0.31255895138908f, 0.034478918459459f, -0.079232996020732f,
4916            0.39803160685016f, 0.82281399721198f, 0.24369695191021f,
4917            -0.5524321671417f, 0.49350231710234f, 0.52530668244467f, 0.253625789825f,
4918            0.26218499242504f, -0.20557247282514f,
4919            0.060763010271891f, -0.023938406391206f, 0.36557410300471f,
4920            0.55368747615095f, 0.25557899769702f, -0.70014279913759f,
4921            0.36398574324757f, 0.049110464042478f, -0.2428951164628f,
4922            -0.18733973495522f, 0.020130805835303f, 0.87784000694654f,
4923            -0.62385490124849f, 0.020947599003133f, -0.44548631925386f,
4924            -0.21069894502123f, -0.60559127508405f, 0.027809382425643f,
4925            0.51562840479369f, -0.27416131751628f, -0.14365580420426f,
4926            -0.46525735490594f, 0.16338488557607f, 0.62862302132303f,
4927            0.52085189275139f, 0.51359303425374f, 0.021844789421786f,
4928            0.53521775458267f, -0.23767218281397f, -0.34858599348565f,
4929            0.12263603513069f, 0.53912951801629f, 0.57550729534804f,
4930            -0.10335514143554f, 0.57524709075397f, 0.14662748040551f,
4931            0.40942178494947f, 0.17197663954561f, -0.025238012475873f,
4932            -0.20104824969996f, -0.60303014654018f, 0.63094779803243f,
4933            0.051685704973311f, 0.23577798459204f, -0.19154992327678f,
4934            -0.67743578708385f, -0.51070301615526f, 0.43047548181493f,
4935            0.21373839204543f, -0.44348268823586f, 0.34347986958921f,
4936            -0.49945694096162f, 0.45888698118478f, -0.42382317871053f,
4937            -0.60376535923059f, -0.065300874745824f, 0.49448067868339f,
4938            0.12358559784007f, 0.58623743735263f, -0.16656623971303f,
4939            0.44140930948322f, -0.41692548571374f, -0.23774988226818f,
4940            -0.27542786466885f, 0.39264397083621f, 0.58717642823542f,
4941            -0.67860697457746f, 0.2070991391515f, -0.12832398784247f,
4942            -0.58381216132288f, 0.24050209342748f, 0.2854077401022f,
4943            -0.021324501342617f, 0.0098658783730532f, 0.2694901128571f,
4944            0.42580554353158f, -0.82903198308789f, -0.24128534823695f,
4945            -0.20344882384938f, 0.51719618805529f, 0.24379623299129f,
4946            0.11303683173372f, -0.46058654895958f, -0.63777957124993f,
4947            0.15686479897897f, -0.67777169905813f, -0.04974608057712f,
4948            0.51313211803344f, 0.49928667286231f, -0.030863149692696f,
4949            0.53527130791104f, -0.50102597915466f, -0.60754472649714f,
4950            -0.25235098830686f, 0.13490559284448f, 0.10708155847142f,
4951            -0.20613512232544f, 0.39533044356843f, -0.34422306275706f,
4952            0.4792145528465f, -0.19178040223502f, -0.64521804411898f,
4953            0.3304779611047f, 0.49148538926455f, -0.30004348427342f,
4954            0.33473309391851f, 0.31079743137844f, 0.59208027276116f,
4955            -0.52688857216953f, 0.40250311061529f, 0.38833191043333f,
4956            0.50432308135853f, -0.33327489215794f, -0.21015252001231f,
4957            -0.30306420816123f, -0.34460825415019f, -0.26894228639121f,
4958            -0.58579646837355f, -0.51178483212848f, 0.33464319317466f,
4959            -0.20258582390514f, -0.29195675136034f, 0.11887973573086f,
4960            0.91211540292822f, 0.034118810787236f, -0.16269371903027f,
4961            0.61207678339522f, -0.21883722070929f, -0.23415725333464f,
4962            0.0041447691596985f, -0.34019274152454f, 0.6378827339521f,
4963            0.11272999861808f, -0.54780877011146f, -0.62497664375172f,
4964            -0.41373740141301f, 0.33306010353229f, 0.12039112788093f,
4965            0.24918468395037f, -0.068734287809286f, -0.42234580029763f,
4966            0.12235329631887f, -0.26545138767734f, 0.81815148205875f,
4967            0.32048708659406f, -0.40233908147851f, 0.24633289057781f,
4968            -0.37087758270512f, -0.55466799718133f, -0.47908728788262f,
4969            -0.33748729653627f, -0.45507986822699f, -0.50597645316527f,
4970            -0.2863701644881f, -0.5404199724601f, -0.22120318557996f,
4971            -0.23520314824941f, 0.82195093398991f, -0.22661283339659f,
4972            0.16382454786402f, -0.41400232366734f, -0.13959354720703f,
4973            -0.30495751902889f, -0.47964557116121f, -0.68490238495876f,
4974            -0.4324077675155f, -0.13521732523742f, -0.050887702629247f,
4975            -0.56629250538137f, 0.19768903044f, -0.080075220953828f,
4976            -0.29952637623112f, 0.095974426142512f, -0.73136356489112f,
4977            -0.21316607993139f, 0.47585902758173f, -0.49429850443227f,
4978            -0.24146904800157f, 0.45631329089651f, 0.46610972545109f,
4979            0.12647584748018f, -0.10203700758813f, 0.20801341293098f,
4980            0.66418891258418f, -0.65219775460192f, -0.2526141453282f,
4981            -0.69345279552921f, 0.30149980453822f, -0.46870940095961f,
4982            0.20092958919922f, -0.21817920622376f, 0.34721422759447f,
4983            -0.69001417476102f, 0.09722776919634f, -0.37852252163632f,
4984            -0.24995374433763f, 0.24829304775112f, 0.4970126640943f,
4985            -0.82278510972964f, 0.050748830242865f, -0.3934733016285f,
4986            0.00029980431140623f, -0.34677214869339f, -0.21301870187776f,
4987            -0.51821811089111f, -0.22147302694699f, 0.53524316281446f,
4988            0.12892242816244f, -0.5543955478928f, -0.26821451961648f,
4989            -0.21006612796354f, 0.26079212570498f, -0.021870637510645f,
4990            0.72402587064608f, -0.27651658712238f, 0.53544979218311f,
4991            -0.099744280251479f, -0.4534212871731f, 0.71954978543864f,
4992            -0.31082396323078f, -0.26933824624449f, 0.31233586755618f,
4993            -0.48121951222937f, -0.43051247772929f, -0.5038415181805f,
4994            0.12342710418307f, 0.037467829082858f, -0.55909965468017f,
4995            -0.51180831908824f, -0.079955485578946f, -0.53046702060975f,
4996            0.48748209854708f, 0.16148937559829f, -0.43191028009105f,
4997            -0.38131649706702f, 0.46242477534251f, 0.46416075424014f,
4998            -0.20634110277567f, -0.53778490132009f, 0.30582118902172f,
4999            0.6245043069106f, 0.14316692963071f, -0.1436103838143f,
5000            0.27519251589203f, -0.60467865310212f, -0.35708047307373f,
5001            0.52425890739441f, -0.20390682829262f, -0.33609142609195f,
5002            0.51803372559413f, 0.28921536255925f, 0.46756035964091f,
5003            -0.4455164148456f, 0.31831805515328f, 0.24217750314789f,
5004            0.49821219078654f, -0.47209418708575f, 0.41285649844363f,
5005            -0.015857310429397f, -0.45214512052441f, -0.14591363373753f,
5006            0.74070676188619f, 0.0098874230592725f, -0.47463489014478f,
5007            0.24260837156464f, 0.44639366601915f, 0.31528570191456f,
5008            0.45334773303464f, -0.47964168123625f, -0.45484996397296f,
5009            0.47123463487178f, 0.64525048646519f, -0.064257637508608f,
5010            -0.18737730572971f, -0.11735335340515f, -0.55549853319118f,
5011            -0.025197229767488f, -0.257963271803f, 0.26277107860996f,
5012            -0.58236203161499f, -0.41893538667715f, 0.59086294196016f,
5013            -0.48940330017687f, 0.33728563842186f, -0.057634928591543f,
5014            0.44862021996899f, -0.40048256377746f, 0.53080564921806f,
5015            0.73350664260388f, -0.021482988114587f, 0.016568147533453f,
5016            0.0021905972927896f, 0.49384961731337f, 0.46619710394628f,
5017            -0.25151229880228f, -0.62009962583403f, -0.26948657433033f,
5018            0.31711936293198f, -0.35081923073755f, 0.50592112116981f,
5019            0.0094298597779172f, -0.35925999444899f, 0.47529205807388f,
5020            -0.26709475088579f, -0.53352146543694f, 0.53754630836074f,
5021            -0.5948549517534f, -0.53195924881292f, -0.094383768924555f,
5022            -0.41704491211939f, -0.41397531920841f, -0.09463944474724f,
5023            -0.74917126125127f, -0.24166385705367f, 0.22864554725283f,
5024            0.31721357549513f, 0.06066292638611f, -0.47303041351952f,
5025            -0.3300396030254f, -0.08758658200966f, -0.096726092930468f,
5026            -0.39607089556472f, 0.55566932028997f, 0.63906648027271f,
5027            -0.58933068378397f, -0.38176870540341f, 0.46748019640554f,
5028            -0.061358837959321f, 0.36268480315292f, -0.39127879224432f,
5029            -0.066556695042975f, -0.73863083674701f, -0.32153946998935f,
5030            0.57454599361106f, -0.090856896694743f, -0.09082394033963f,
5031            -0.36335404704287f, -0.41643677881158f, -0.57839830999334f,
5032            -0.030959887755637f, 0.5989792522053f, -0.016582566905843f,
5033            0.23126668855143f, 0.2107790785413f, -0.14272193312959f,
5034            -0.29232225134991f, -0.48451339172564f, -0.74934159314943f,
5035            0.48188197979627f, -0.040214759215399f, -0.15667971883369f,
5036            0.16054853668069f, -0.6083975436752f, -0.58796308779952f,
5037            0.31319356064062f, -0.19280657835646f, 0.76136690598738f,
5038            -0.084506239097717f, 0.4768786755523f, -0.22472488900872f,
5039            0.67504537519138f, 0.36920158913876f, 0.40321048682396f,
5040            0.034436041975613f, -0.29332731631919f, 0.39774172001359f,
5041            -0.1459159803857f, -0.59726183207777f, -0.036384224081948f,
5042            -0.65093487874945f, 0.39515711468056f, -0.20198429937477f,
5043            0.60092128630869f, 0.18110182176699f, 0.2579491954112f,
5044            -0.39594768022975f, 0.15112959843347f, 0.59995268930018f,
5045            -0.42310244265976f, -0.26937197256148f, 0.074700012546319f,
5046            0.53119510349465f, 0.41614374632783f, 0.53618944036115f,
5047            0.0071605427687482f, -0.69599782505338f, -0.053138604739257f,
5048            -0.00054500262230378f, 0.69533871546989f, 0.1709263483943f,
5049            0.12447149375466f, 0.33265313001972f, 0.35070015349473f,
5050            0.53879932284829f, 0.37648083373421f, 0.56463759722353f,
5051            0.29540077719054f, 0.04954124873475f, -0.48345087234985f,
5052            0.72758494948264f, 0.070069102610626f, 0.377186640377f,
5053            0.4882414260383f, 0.45135801463006f, 0.48450857902353f,
5054            -0.26042407965644f, -0.4251358047458f, 0.2731053563007f,
5055            -0.49806371818291f, -0.4719759672029f, 0.029647087810764f,
5056            -0.13788472163255f, -0.45346141932978f, -0.5510470160674f,
5057            -0.5359511936033f, -0.53585470245895f, 0.1771036246335f,
5058            -0.4537763243703f, 0.41838964069644f, 0.11527149720722f,
5059            -0.36846431808379f, -0.46533180802325f, 0.65800816763703f,
5060            -0.28691297783558f, 0.31521457275327f, 0.18178647457201f,
5061            -0.29243126901345f, -0.4352956525447f, -0.58895978125929f,
5062            -0.49649471729812f, 0.29271342931272f, 0.21433587621517f,
5063            0.056256690265475f, -0.50387710054371f, 0.48145041862725f,
5064            0.44723671964597f, -0.55771174894027f, -0.0092449146014199f,
5065            -0.40973125164006f, -0.73147173623276f, -0.094076302480945f,
5066            0.43033451471976f, 0.014334271843521f, -0.32066459724334f,
5067            0.26752725373294f, 0.50477344684769f, 0.065069516529324f,
5068            0.36001097578267f, 0.59393393889869f, -0.43247366096278f,
5069            0.48945720845334f, 0.6043315650632f, 0.12458128550608f,
5070            -0.48327805813458f, -0.25681943056744f, 0.28316179557217f,
5071            -0.45182760404001f, 0.21574002665039f, -0.31462623994251f,
5072            0.25279349500371f, 0.44865729380505f, -0.62058075048081f,
5073            0.44017304540101f, 0.43789555905674f, 0.58423563606269f,
5074            0.41842994331139f, -0.26836655962348f, 0.16143005677844f,
5075            -0.67897032028819f, -0.32730885869255f, -0.0243997359109f,
5076            0.40649244381227f, 0.47711065295824f, -0.19596475712206f,
5077            0.57441588138131f, 0.09386994843744f, 0.28400793066375f,
5078            0.59394229842661f, 0.45349906020748f, 0.14881354725974f,
5079            -0.3393739967757f, -0.54929055652002f, 0.26209493900588f,
5080            0.0733800373509f, 0.56557076402003f, 0.43492125584075f,
5081            0.050007991188197f, 0.74652764513134f, -0.36432144611385f,
5082            -0.20993543754239f, -0.1352041047841f, 0.49508839805322f,
5083            -0.041332158875019f, -0.20655741061568f, 0.52511282214888f,
5084            0.047248635933477f, -0.6276121766011f, -0.5326844609727f,
5085            -0.1889491176448f, 0.05188976739355f, -0.45677123586268f,
5086            0.42884456750344f, 0.61612085530435f, -0.43526216197988f,
5087            -0.65873541163911f, -0.094770059351695f, 0.40844030815782f,
5088            0.35536013391048f, -0.16940065827957f, 0.48506226422661f,
5089            -0.45779281442862f, -0.46052673126242f, 0.34138050378631f,
5090            -0.54943270263121f, 0.37140594702643f, -0.14826175595089f,
5091            -0.069378715405383f, -0.14845488608058f, -0.73991837897813f,
5092            0.41519184526768f, -0.11098464009855f, -0.49088356499611f,
5093            0.46422563805447f, 0.46130716873201f, -0.44207791495441f,
5094            0.12050605352899f, 0.34969556083561f, -0.4893349322843f,
5095            -0.35482925073362f, 0.28146983672487f, -0.35356606227648f,
5096            -0.38774754218768f, 0.35979702647173f, -0.62454776976122f,
5097            -0.48343191508515f, 0.41492185792886f, -0.50175316406656f,
5098            0.21953122931153f, -0.54083165333237f, 0.041040952107647f,
5099            -0.51280508048852f, -0.54131124436697f, -0.0099287129207481f,
5100            0.23788701199175f, 0.4350333223576f, 0.44505087885649f,
5101            0.2253837335044f, -0.30117119745248f, 0.46587685049056f,
5102            -0.46672901001472f, -0.59182069765377f, 0.27086737661249f,
5103            0.43015756480475f, -0.067851118947538f, -0.26917802105288f,
5104            -0.57731860676632f, -0.53950120703807f, -0.33696522367557f,
5105            0.20858352742161f, 0.63695057987625f, 0.49453142202915f,
5106            -0.046235371593379f, -0.54436247241885f, -0.088075720520231f,
5107            -0.35626464703623f, 0.067539543974725f, -0.18142793486226f,
5108            -0.49044207117167f, 0.5542388249925f, 0.53654796190017f,
5109            0.52238539932434f, 0.55175875223621f, 0.29070268774296f,
5110            -0.14119026819648f, -0.55841587206055f, -0.080029639759127f,
5111            -0.025988002903175f, 0.46612949273683f, -0.56880970348453f,
5112            -0.44824563336003f, -0.030000490931808f, 0.50663523727173f,
5113            0.047284583258099f, -0.26595723160738f, 0.21032033434131f,
5114            0.52986834914146f, -0.52245334572957f, -0.5736534757312f,
5115            -0.31924244568277f, -0.13888420092891f, 0.30725800370737f,
5116            0.49792332552544f, 0.61035592292817f, -0.40487771982263f,
5117            0.038758575627018f, -0.53813545398707f, -0.56167256912901f,
5118            0.46815373895572f, -0.14142713486975f, 0.39276248966752f,
5119            -0.19936871608885f, 0.12488860648831f, -0.62990029833727f,
5120            -0.29296146144627f, 0.49734531468753f, 0.46335923993672f,
5121            -0.078826705546604f, -0.15548800857414f, 0.57456768467721f,
5122            0.5558854465212f, -0.56893054194692f, -0.082408823513622f,
5123            0.11678856295109f, 0.53358760166951f, 0.49302489382249f,
5124            -0.53981846952046f, -0.237913367643f, -0.33251226509871f,
5125            0.39126928439834f, -0.39416116630681f, -0.35778844984527f,
5126            -0.39395609960567f, 0.50270356681194f, -0.39448759513757f,
5127            -0.17961290695406f, 0.34239532682819f, -0.21870225043453f,
5128            -0.23322835296688f, 0.75997835134209f, 0.41317237364121f,
5129            0.29699501400111f, 0.17195435585404f, -0.34903627841034f,
5130            -0.31751884057854f, -0.59661546358767f, 0.55102732418683f,
5131            -0.2237291316445f, -0.51254305965518f, -0.31277318571798f,
5132            0.54270199705442f, -0.34885011313806f, 0.41616819064585f,
5133            0.53534023676892f, 0.45905986582643f, -0.20308675275303f,
5134            0.019523641323632f, 0.3378580580099f, 0.58898336258938f,
5135            -0.045038463119119f, -0.52553334288797f, -0.6098545897634f,
5136            0.46226027841702f, -0.36069029000651f, 0.077984430434637f,
5137            -0.40129033029845f, 0.39526722066586f, -0.20379584931963f,
5138            0.45466492237669f, 0.46504795737483f, -0.46712669863522f,
5139            -0.43845831945339f, -0.59284534057943f, 0.050241908216277f,
5140            -0.36494839821973f, 0.32363879325018f, 0.46458051299488f,
5141            -0.46057360356064f, -0.34584626825548f, -0.12264748451482f,
5142            0.48835437094478f, 0.21102526990984f, 0.60843919401837f,
5143            -0.086047549693024f, -0.16981605114589f, -0.37222833669973f,
5144            0.45158609930017f, -0.55710254634126f, 0.55759406480139f,
5145            0.54697451263099f, -0.45070837355303f, 0.032962522247893f,
5146            -0.48584332140086f, -0.28055687213837f, 0.42642516953676f,
5147            0.34061925303691f, 0.38443007758012f, 0.61614808332652f,
5148            -0.55774172327958f, -0.075660378162998f, 0.19938218730551f,
5149            0.30626924920956f, -0.057939049897675f, -0.10461119704504f,
5150            -0.4395638756485f, -0.57307193269415f, 0.60849886616281f,
5151            -0.52519951444608f, -0.42567534157254f, -0.19896500097138f,
5152            0.48819483593271f, 0.12539008064447f, 0.49932157157064f,
5153            -0.10173361116951f, -0.07873850987854f, 0.3713554090283f,
5154            0.65889542748449f, 0.63411890875068f, 0.096414235519521f,
5155            0.60342393773609f, 0.057617370697663f, 0.35558841250938f,
5156            0.20766418929404f, 0.030670189501999f, -0.67974377143949f,
5157            -0.071971052874019f, -0.44567383014704f, 0.65917594080871f,
5158            0.44113802003588f, -0.29627117199757f, 0.28160739274962f,
5159            0.38284479693596f, 0.43552320173998f, -0.4282368470258f,
5160            -0.54809258921772f, -0.27202273485667f, 0.32551612927831f,
5161            -0.74755699288716f, -0.20979308948438f, 0.19268299390085f,
5162            0.27864013929953f, -0.39085278833717f, 0.36001727246301f,
5163            -0.64575536737195f, 0.59253747557756f, 0.040885512266333f,
5164            -0.20167391777406f, -0.43481684011627f, -0.02212841779644f,
5165            0.45874103754271f, -0.0066587566394561f, -0.30494054091993f,
5166            0.52731059172348f, -0.64443887148677f, 0.056264275617853f,
5167            0.61573773369959f, -0.00074622703454316f, 0.25455659350429f,
5168            0.30670278147618f, -0.18573195942296f, 0.65383825999316f,
5169            -0.089919562456316f, -0.28968403215216f, -0.60618287937171f,
5170            0.53370861364121f, 0.37921556323246f, -0.33450055738044f,
5171            -0.47481167613763f, 0.3899274103573f, -0.1047963185367f,
5172            0.45545456567005f, 0.12142073778317f, 0.62397625076847f,
5173            0.59154225785278f, -0.10812441303593f, -0.4685834521013f,
5174            -0.36007270807588f, -0.1012374701199f, 0.52812407295968f,
5175            -0.01292122984647f, -0.23607532114711f, -0.57680411110671f,
5176            -0.44955815301222f, -0.31913443306122f, -0.55448100298376f,
5177            0.54231398466289f, -0.31845386154668f, -0.38636423612049f,
5178            0.22187979539931f, -0.6346425853783f, -0.056599490898788f,
5179            -0.41950690366157f, -0.4578028963184f, 0.31139813874057f,
5180            0.39787962066193f, -0.20885901240181f, 0.56172180435883f,
5181            -0.031404881097728f, 0.56267475273157f, -0.5556815383811f,
5182            0.33075363850824f, 0.39071115867626f, 0.3340294973255f,
5183            -0.51485161085589f, -0.34037011091125f, -0.46826090820473f,
5184            -0.60086679836276f, -0.075069409610657f, 0.18202033570633f,
5185            -0.49669644859095f, 0.13236483793072f, 0.53440735955877f,
5186            0.4720120049858f, -0.05992551666341f, -0.47306929861073f,
5187            -0.32796852486185f, 0.65593302097807f, 0.20800030327303f,
5188            -0.38965914824176f, -0.51564565153044f, -0.034636725857177f,
5189            -0.30473794783797f, 0.12584230588041f, 0.63911213518179f,
5190            0.11269477188219f, 0.62944339013855f, 0.27191006392352f,
5191            -0.53642197294029f, 0.50742224701512f, -0.22907820767928f,
5192            0.47022559371179f, -0.1914125650624f, 0.38019261684316f,
5193            -0.28865425091309f, 0.76169672032907f, -0.36166127667225f,
5194            -0.30555403321368f, -0.12541657537884f, -0.31081403770203f,
5195            0.0025978417989835f, 0.3737146483793f, -0.3151511957077f,
5196            0.62032810853005f, 0.60524642517936f, -0.09939888944988f,
5197            -0.40019833530022f, 0.15931480693456f, -0.61653030345628f,
5198            -0.49479441153976f, -0.021517911098538f, -0.43481713333933f,
5199            -0.26445143166732f, -0.48401155081335f, 0.27737058096082f,
5200            -0.12537486208624f, -0.46956235249512f, 0.61859207953377f,
5201            -0.49776294425122f, 0.6509513246149f, -0.20147785800704f,
5202            0.26022926925791f, 0.39526195830317f, -0.25288299425858f,
5203            0.20792543895216f, 0.6725599557329f, 0.013296712014115f,
5204            0.069082404776847f, -0.37233547685047f, 0.60070560947898f,
5205            -0.60329265885108f, 0.40708027238668f, -0.17229997007444f,
5206            -0.52997954496878f, 0.22211745651394f, -0.33229784433365f,
5207            0.61826884506104f, -0.62582169643111f, 0.33820439950773f,
5208            0.23870919720066f, -0.20670655096227f, -0.10953969425599f,
5209            -0.63678168786213f, -0.51101649337563f, -0.19131817442969f,
5210            -0.49493417544846f, -0.22614515287593f, 0.025828539221376f,
5211            0.7068462559507f, 0.072932806612059f, -0.30827034359477f,
5212            -0.52659704221432f, -0.33954839093364f, 0.086145323573817f,
5213            -0.52429050496975f, 0.39091424683727f, 0.52819210715237f,
5214            -0.16569162349745f, 0.447191673089f, 0.25667977984796f,
5215            0.85033978527922f, -0.37311666188152f, -0.031585518143925f,
5216            -0.063546921071094f, -0.35026506762952f, 0.099923633151172f,
5217            -0.43149574251927f, 0.16017753208259f, -0.36624037246965f,
5218            0.49372029676385f, -0.60067103922455f, 0.2223896202103f,
5219            -0.43599537393092f, -0.360658355506f, -0.42475053011196f,
5220            -0.52301759011739f, 0.039454536357949f, 0.47362064109658f,
5221            -0.35793170214797f, -0.43917817788312f, -0.49072242572643f,
5222            -0.32880277826743f, -0.38509560837703f, -0.42636724894184f,
5223            -0.043679644403255f, 0.74697226557232f, -0.40732954428872f,
5224            -0.48088968590275f, 0.18029290312902f, -0.10220931735307f,
5225            -0.058902573502295f, 0.0082595236590186f, 0.7136596141971f,
5226            -0.53043791172483f, 0.22906331492979f, 0.39155822265168f,
5227            0.43459649233879f, 0.18964470832196f, 0.15217427204218f,
5228            0.59694624534505f, 0.053786588105393f, 0.62671041756872f,
5229            -0.48833575031057f, 0.068909881680922f, 0.60168404074737f,
5230            -0.055455043023162f, -0.62426261497771f, -0.044461939113733f,
5231            -0.71822145541427f, 0.054494951105527f, 0.25733756171599f,
5232            -0.42706881935297f, -0.44024663347316f, 0.19687748949208f,
5233            0.4723221071836f, 0.63009683957253f, 0.2166256995021f,
5234            0.31063720960745f, 0.079455887335627f, 0.47974409023622f,
5235            -0.39506538843406f, 0.42517729990346f, 0.29375773990216f,
5236            0.044503633424429f, -0.46173213926286f, 0.60139575234582f,
5237            -0.40354126620316f, 0.41304136826673f, -0.29533980868045f,
5238            -0.45300699221804f, 0.23702354154238f, -0.56385297528377f,
5239            -0.62315380378984f, -0.42397903326965f, 0.53044082394843f,
5240            0.37874432092957f, 0.054922713129263f, 0.063952196248596f,
5241            0.41959045692314f, -0.83420441875842f, -0.25505372502578f,
5242            0.25012310515014f, 0.010974237503127f, 0.017675743681809f,
5243            -0.25231575134089f, -0.17034034508503f, -0.0022254428444259f,
5244            -0.4967771056787f, 0.43184899693064f, -0.68850194407078f,
5245            -0.1852812882862f, -0.48330898597592f, 0.13528868642679f,
5246            0.15202104844417f, 0.57661281495368f, -0.59848767913131f,
5247            0.64287473226568f, -0.30923674494923f, 0.22234318117192f,
5248            0.099248962994541f, 0.64370450011427f, 0.13206961744112f,
5249            -0.49018899717866f, 0.68654120859156f, -0.27238863334662f,
5250            -0.085832423495263f, 0.44161945604453f, 0.10856057983467f,
5251            0.48795432482822f, 0.42184193883513f, -0.43797315744756f,
5252            0.35186997012044f, -0.46483432791096f, 0.22857392808385f,
5253            0.52970834834669f, -0.50684486922008f, -0.39782161731912f,
5254            -0.3932709335414f, -0.34863027587322f, 0.16748196501934f,
5255            -0.46048505533f, -0.3887126918161f, -0.68287320410729f,
5256            -0.18448530888361f, -0.25358256326157f, 0.26870280714361f,
5257            0.6889557358588f, -0.3101022706485f, -0.35882194962822f,
5258            0.30088738418801f, -0.039139540883101f, -0.45646277242166f,
5259            -0.21954767479275f, 0.40838837410593f, 0.23284186868997f,
5260            0.30349649888064f, 0.57233263099925f, 0.55778817953937f,
5261            0.57731035290905f, 0.091218309942656f, 0.70670016667131f,
5262            0.016358033634041f, 0.3939245235472f, -0.059352634867484f,
5263            0.50055570130024f, -0.021749790970703f, 0.56767851040093f,
5264            0.50580176326624f, 0.34691320957643f, 0.22478399991032f,
5265            -0.37901911159632f, 0.53804099887537f, -0.46780195460858f,
5266            0.51497346779204f, -0.27981005467588f, 0.067278440906787f,
5267            0.67241900483514f, 0.074099582737f, 0.43138117954806f,
5268            0.054567519697911f, -0.37927768894619f, 0.45764946429346f,
5269            0.14529189179172f, -0.23854982910384f, 0.45401647091062f,
5270            0.25466539906731f, 0.46182069803887f, -0.66160446396375f,
5271            -0.15570980059397f, -0.38476787034627f, 0.37322840954917f,
5272            -0.43977613626294f, -0.61243005550684f, -0.34631643815896f,
5273            -0.19590302894013f, 0.42065974653653f, 0.43447548638809f,
5274            -0.10575548452794f, 0.70439951675651f, -0.29754920754254f,
5275            -0.13558865796725f, 0.1427073453776f, 0.49647494823192f,
5276            -0.65533234019218f, -0.11714854214663f, 0.5211321311867f,
5277            -0.6228374766114f, 0.20812698103217f, -0.16205154548883f,
5278            0.20384566967497f, -0.59321895467652f, 0.38604941246779f,
5279            0.44487837128099f, -0.37224943035393f, -0.22188447638327f,
5280            0.48921538939858f, 0.41432418029434f, -0.45087099253189f,
5281            0.66422841315008f, 0.21517761068003f, 0.094012579794123f,
5282            -0.4358159040875f, 0.22245680154647f, -0.51404116085847f,
5283            -0.11369362736032f, 0.32284689991698f, -0.38818285117689f,
5284            0.49680024166881f, 0.047684866166158f, -0.69503480904222f,
5285            -0.5137200731924f, -0.50673230867252f, 0.32715252974108f,
5286            -0.26799714004956f, -0.47616510509846f, 0.27153195326233f,
5287            -0.47315177716491f, -0.45711495983609f, -0.31178280842352f,
5288            -0.51697763052226f, -0.14302372043059f, -0.42689944315384f,
5289            -0.050442035795027f, 0.23609184251469f, 0.38634880236106f,
5290            0.56012774305243f, 0.38963669840218f, -0.57174382424149f,
5291            -0.15472134925391f, -0.15333579424307f, -0.14189768300467f,
5292            0.032279269476252f, -0.66054298438621f, -0.70360180527557f,
5293            -0.10345191679557f, -0.30503725808375f, 0.31038263802383f,
5294            0.36878846502877f, -0.76824774853417f, 0.2714830658427f,
5295            -0.060212868606223f, -0.4172755444983f, 0.39199300681258f,
5296            -0.44040104260082f, 0.24955102139032f, -0.64215903203727f,
5297            0.25443195353315f, -0.013789583113498f, 0.44365000614699f,
5298            0.53296203342425f, -0.55057750350733f, -0.38867053403178f,
5299            -0.36068564301268f, -0.65616661625162f, -0.48495997865466f,
5300            0.24088316031012f, -0.18080297655217f, -0.33682435258394f,
5301            -0.53824550487673f, -0.096728907851005f, -0.5208619866167f,
5302            0.33195321221408f, -0.032263947064791f, 0.56427315050798f,
5303            0.40151657866643f, -0.44825725748635f, -0.54910020122855f,
5304            -0.095936272447708f, 0.5719563905078f, 0.00097783623607218f,
5305            0.21961099467771f, 0.62823723408945f, -0.010045934028323f,
5306            -0.6610564872634f, -0.17161595423903f, -0.30089924032373f,
5307            0.27961471530636f, 0.054523395513076f, 0.61485903249347f,
5308            0.11958885677663f, -0.61032561244673f, -0.39241856813031f,
5309            -0.30223065341134f, -0.23605925177166f, -0.09697276975263f,
5310            -0.46458104180761f, -0.37853464945647f, 0.69599203908657f,
5311            0.0023635513043496f, 0.62702100484886f, 0.49658954056984f,
5312            -0.20369645124455f, -0.56457560315907f, 0.00021299797811461f,
5313            -0.64198493892962f, 0.59676262320476f, 0.46274573284143f,
5314            0.088421912306785f, 0.098029994490406f, -0.012953072012707f,
5315            -0.053965435026011f, 0.13439533803278f, -0.33103493780685f,
5316            0.55991756423782f, -0.58127599631056f, -0.46696041830103f,
5317            -0.43965993689353f, 0.07544961763381f, 0.1509639518808f,
5318            -0.38868406689028f, -0.0033436054452783f, -0.79191533434483f,
5319            -0.21743914630025f, -0.32019630124298f, -0.56067107727615f,
5320            0.027284914419519f, -0.49444926389798f, -0.53908992599417f,
5321            -0.36492599248168f, 0.52529904803377f, 0.18002253442693f,
5322            0.14829474115897f, 0.17212619314998f, -0.71194315827942f,
5323            0.0051876209353066f, 0.50490293404098f, 0.24361032552454f,
5324            0.13688117617809f, -0.61381291176911f, -0.5386997104485f,
5325            0.66421180843392f, 0.21833854629637f, -0.087909936660014f,
5326            0.15624552502148f, -0.68780724971724f, 0.077015056461268f,
5327            0.52710630558705f, -0.42143671471468f, -0.069964559463205f,
5328            -0.24196341534187f, -0.68814841622245f, 0.08695091377684f,
5329            0.62392249806692f, -0.23663281560035f, -0.59058622185178f,
5330            0.22685863859977f, -0.36683948058558f, -0.14105848121323f,
5331            0.18069852004855f, -0.083828559172887f, 0.66240167877879f,
5332            0.16722813432165f, -0.25503640214793f, -0.65462662498637f,
5333            -0.37112528006203f, 0.43100319401562f, -0.11342774633614f,
5334            0.14418808646988f, 0.5753326931164f, 0.55842502411684f,
5335            0.55378724068611f, 0.21098160548047f, -0.3224976646632f,
5336            0.31268307369255f, -0.37624695517597f, -0.55269271266764f,
5337            0.2601465870231f, 0.56373458886982f, -0.21638357910201f,
5338            0.41216916619413f, -0.25078072187299f, -0.57873208070982f,
5339            0.11217864148346f, 0.54196554704815f, -0.31989128683717f,
5340            0.54691221598945f, 0.24062434044524f, 0.48409277788476f,
5341            0.087564423746579f, -0.12083081671284f, 0.69931172084498f,
5342            0.35220575672909f, 0.28770484569954f, -0.53091668762919f,
5343            0.3395702120398f, 0.042520943289575f, -0.30935928261896f,
5344            0.61022210846475f, 0.54650816974112f, 0.34079124619266f,
5345            0.32746112891934f, 0.32095220193351f, -0.61142534799442f,
5346            0.32197324480666f, -0.38236071343678f, 0.40749411210419f,
5347            0.58741915356593f, -0.30916030490652f, -0.57642977381104f,
5348            -0.038846190358607f, 0.047926713761208f, -0.4725265742377f,
5349            0.026224389898652f, 0.031768907187292f, -0.12510902263321f,
5350            0.36102734397001f, -0.72217212865059f, 0.57513252722531f,
5351            -0.27510374152496f, -0.5153402145828f, 0.025774022629799f,
5352            0.59201067073603f, 0.40728366085253f, -0.37645913420642f,
5353            -0.29983338495183f, -0.61017291361195f, -0.18551919513643f,
5354            0.50515945610161f, 0.18206593801497f, -0.46372136367049f,
5355            -0.64290893575119f, -0.34887011406157f, -0.55318606770362f,
5356            -0.21230198963112f, -0.19828983785672f, 0.2730419816548f,
5357            -0.32778879906348f, -0.094317293167129f, 0.57811170538439f,
5358            0.54346692190204f, 0.17699503497579f, -0.47197676839855f,
5359            -0.075738705663962f, 0.53381750682665f, -0.13406342524856f,
5360            0.71765386263773f, 0.34271060834977f, 0.24259408122628f,
5361            -0.30574273227855f, 0.17419449782542f, -0.78861555508124f,
5362            0.43305678368813f, 0.064853328282818f, 0.25003806266734f,
5363            0.4397035983709f, -0.51651518914239f, -0.3972346186176f,
5364            -0.34513492086703f, 0.32129829777342f, -0.39965829527563f,
5365            -0.25184899643619f, -0.35937572373004f, 0.15273239148905f,
5366            -0.51640931868766f, 0.4218715745627f, -0.58261460582976f,
5367            -0.57396000790758f, 0.1912786199605f, 0.45995634753032f,
5368            -0.43664716984512f, 0.4601630113166f, 0.14146310231856f,
5369            0.11500068018889f, 0.05112652754666f, -0.25672855859366f,
5370            -0.54715738035577f, 0.67669928552409f, 0.40118355777989f,
5371            -0.45252668004418f, -0.40809988524453f, -0.064931545867856f,
5372            0.19116562077283f, 0.76523014995576f, 0.048337406798767f,
5373            -0.080075651760374f, 0.75305314115418f, 0.34797424409913f,
5374            0.29104493928016f, 0.0040185919664457f, -0.46977598520425f,
5375            -0.3890257668276f, 0.49100041230416f, -0.17812126809985f,
5376            -0.43787557151231f, -0.46923187878333f, 0.40489108352503f,
5377            0.37433236324043f, -0.29441766760791f, -0.066285137006724f,
5378            0.33217472508825f, 0.73917165688328f, 0.33479099915638f,
5379            -0.02973230696179f, -0.51371026289118f, 0.34133522703692f,
5380            -0.41361792362786f, -0.51561746819514f, -0.4263412462482f,
5381            0.51057171220039f, -0.23740201245544f, 0.26673587003088f,
5382            0.5521767379032f, 0.16849318602455f, 0.52774964064755f,
5383    };
5384
5385}