propane 3.8.0-java → 3.9.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,470 +0,0 @@
1
- package monkstone.noise;
2
-
3
- /*
4
- * A speed-improved simplex noise algorithm for 2D, 3D and 4D in Java.
5
- *
6
- * Based on example code by Stefan Gustavson (stegu@itn.liu.se).
7
- * Optimisations by Peter Eastman (peastman@drizzle.stanford.edu).
8
- * Better rank ordering method for 4D by Stefan Gustavson in 2012.
9
- *
10
- * This could be speeded up even further, but it's useful as it is.
11
- *
12
- * Version 2012-03-09
13
- *
14
- * This code was placed in the public domain by its original author,
15
- * Stefan Gustavson. You may use it as you see fit, but
16
- * attribution is appreciated.
17
- *
18
- */
19
-
20
-
21
- public class SimplexNoise implements Noise{ // Simplex noise in 2D, 3D and 4D
22
-
23
- private static Grad grad3[] = {new Grad(1, 1, 0), new Grad(-1, 1, 0), new Grad(1, -1, 0), new Grad(-1, -1, 0),
24
- new Grad(1, 0, 1), new Grad(-1, 0, 1), new Grad(1, 0, -1), new Grad(-1, 0, -1),
25
- new Grad(0, 1, 1), new Grad(0, -1, 1), new Grad(0, 1, -1), new Grad(0, -1, -1)};
26
-
27
- private static Grad grad4[] = {new Grad(0, 1, 1, 1), new Grad(0, 1, 1, -1), new Grad(0, 1, -1, 1), new Grad(0, 1, -1, -1),
28
- new Grad(0, -1, 1, 1), new Grad(0, -1, 1, -1), new Grad(0, -1, -1, 1), new Grad(0, -1, -1, -1),
29
- new Grad(1, 0, 1, 1), new Grad(1, 0, 1, -1), new Grad(1, 0, -1, 1), new Grad(1, 0, -1, -1),
30
- new Grad(-1, 0, 1, 1), new Grad(-1, 0, 1, -1), new Grad(-1, 0, -1, 1), new Grad(-1, 0, -1, -1),
31
- new Grad(1, 1, 0, 1), new Grad(1, 1, 0, -1), new Grad(1, -1, 0, 1), new Grad(1, -1, 0, -1),
32
- new Grad(-1, 1, 0, 1), new Grad(-1, 1, 0, -1), new Grad(-1, -1, 0, 1), new Grad(-1, -1, 0, -1),
33
- new Grad(1, 1, 1, 0), new Grad(1, 1, -1, 0), new Grad(1, -1, 1, 0), new Grad(1, -1, -1, 0),
34
- new Grad(-1, 1, 1, 0), new Grad(-1, 1, -1, 0), new Grad(-1, -1, 1, 0), new Grad(-1, -1, -1, 0)};
35
-
36
- private final static short p[] = {151, 160, 137, 91, 90, 15,
37
- 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142, 8, 99, 37, 240, 21, 10, 23,
38
- 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117, 35, 11, 32, 57, 177, 33,
39
- 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71, 134, 139, 48, 27, 166,
40
- 77, 146, 158, 231, 83, 111, 229, 122, 60, 211, 133, 230, 220, 105, 92, 41, 55, 46, 245, 40, 244,
41
- 102, 143, 54, 65, 25, 63, 161, 1, 216, 80, 73, 209, 76, 132, 187, 208, 89, 18, 169, 200, 196,
42
- 135, 130, 116, 188, 159, 86, 164, 100, 109, 198, 173, 186, 3, 64, 52, 217, 226, 250, 124, 123,
43
- 5, 202, 38, 147, 118, 126, 255, 82, 85, 212, 207, 206, 59, 227, 47, 16, 58, 17, 182, 189, 28, 42,
44
- 223, 183, 170, 213, 119, 248, 152, 2, 44, 154, 163, 70, 221, 153, 101, 155, 167, 43, 172, 9,
45
- 129, 22, 39, 253, 19, 98, 108, 110, 79, 113, 224, 232, 178, 185, 112, 104, 218, 246, 97, 228,
46
- 251, 34, 242, 193, 238, 210, 144, 12, 191, 179, 162, 241, 81, 51, 145, 235, 249, 14, 239, 107,
47
- 49, 192, 214, 31, 181, 199, 106, 157, 184, 84, 204, 176, 115, 121, 50, 45, 127, 4, 150, 254,
48
- 138, 236, 205, 93, 222, 114, 67, 29, 24, 72, 243, 141, 128, 195, 78, 66, 215, 61, 156, 180};
49
- // To remove the need for index wrapping, double the permutation table length
50
- final static short[] PERM = new short[512];
51
- static short[] PERM_MOD_12 = new short[512];
52
-
53
- static {
54
- for (int i = 0; i < 512; i++) {
55
- PERM[i] = p[i & 255];
56
- PERM_MOD_12[i] = (short) (PERM[i] % 12);
57
- }
58
- }
59
-
60
- // Skewing and unskewing factors for 2, 3, and 4 dimensions
61
- private static final float F2 = 0.5f * (float)(Math.sqrt(3.0) - 1.0);
62
- private static final float G2 = (float)(3.0 - Math.sqrt(3.0)) / 6.0f;
63
- private static final float F3 = 1.0f / 3.0f;
64
- private static final float G3 = 1.0f / 6.0f;
65
- private static final float F4 = (float)(Math.sqrt(5.0) - 1.0) / 4.0f;
66
- private static final float G4 = (float)(5.0 - Math.sqrt(5.0)) / 20.0f;
67
-
68
- // This method is a *lot* faster than using (int)Math.floor(x)
69
- private static int fastfloor(float x) {
70
- int xi = (int) x;
71
- return x < xi ? xi - 1 : xi;
72
- }
73
-
74
- private static float dot(Grad g, float x, float y) {
75
- return g.x * x + g.y * y;
76
- }
77
-
78
- private static float dot(Grad g, float x, float y, float z) {
79
- return g.x * x + g.y * y + g.z * z;
80
- }
81
-
82
- private static float dot(Grad g, float x, float y, float z, float w) {
83
- return g.x * x + g.y * y + g.z * z + g.w * w;
84
- }
85
-
86
- // 2D simplex noise
87
- @Override
88
- public float noise(float xin, float yin) {
89
- float n0, n1, n2; // Noise contributions from the three corners
90
- // Skew the input space to determine which simplex cell we're in
91
- float s = (xin + yin) * F2; // Hairy factor for 2D
92
- int i = fastfloor(xin + s);
93
- int j = fastfloor(yin + s);
94
- float t = (i + j) * G2;
95
- float X0 = i - t; // Unskew the cell origin back to (x,y) space
96
- float Y0 = j - t;
97
- float x0 = xin - X0; // The x,y distances from the cell origin
98
- float y0 = yin - Y0;
99
- // For the 2D case, the simplex shape is an equilateral triangle.
100
- // Determine which simplex we are in.
101
- int i1, j1; // Offsets for second (middle) corner of simplex in (i,j) coords
102
- if (x0 > y0) {
103
- i1 = 1;
104
- j1 = 0;
105
- } // lower triangle, XY order: (0,0)->(1,0)->(1,1)
106
- else {
107
- i1 = 0;
108
- j1 = 1;
109
- } // upper triangle, YX order: (0,0)->(0,1)->(1,1)
110
- // A step of (1,0) in (i,j) means a step of (1-c,-c) in (x,y), and
111
- // a step of (0,1) in (i,j) means a step of (-c,1-c) in (x,y), where
112
- // c = (3-sqrt(3))/6
113
- float x1 = x0 - i1 + G2; // Offsets for middle corner in (x,y) unskewed coords
114
- float y1 = y0 - j1 + G2;
115
- float x2 = x0 - 1.0f + 2.0f * G2; // Offsets for last corner in (x,y) unskewed coords
116
- float y2 = y0 - 1.0f + 2.0f * G2;
117
- // Work out the hashed gradient indices of the three simplex corners
118
- int ii = i & 255;
119
- int jj = j & 255;
120
- int gi0 = PERM_MOD_12[ii + PERM[jj]];
121
- int gi1 = PERM_MOD_12[ii + i1 + PERM[jj + j1]];
122
- int gi2 = PERM_MOD_12[ii + 1 + PERM[jj + 1]];
123
- // Calculate the contribution from the three corners
124
- float t0 = 0.5f - x0 * x0 - y0 * y0;
125
- if (t0 < 0) {
126
- n0 = 0.0f;
127
- } else {
128
- t0 *= t0;
129
- n0 = t0 * t0 * dot(grad3[gi0], x0, y0); // (x,y) of grad3 used for 2D gradient
130
- }
131
- float t1 = 0.5f - x1 * x1 - y1 * y1;
132
- if (t1 < 0) {
133
- n1 = 0.0f;
134
- } else {
135
- t1 *= t1;
136
- n1 = t1 * t1 * dot(grad3[gi1], x1, y1);
137
- }
138
- float t2 = 0.5f - x2 * x2 - y2 * y2;
139
- if (t2 < 0) {
140
- n2 = 0.0f;
141
- } else {
142
- t2 *= t2;
143
- n2 = t2 * t2 * dot(grad3[gi2], x2, y2);
144
- }
145
- // Add contributions from each corner to get the final noise value.
146
- // The result is scaled to return values in the interval [-1,1].
147
- return 70.0f * (n0 + n1 + n2);
148
- }
149
-
150
- // 3D simplex noise
151
- @Override
152
- public float noise(float xin, float yin, float zin) {
153
- float n0, n1, n2, n3; // Noise contributions from the four corners
154
- // Skew the input space to determine which simplex cell we're in
155
- float s = (xin + yin + zin) * F3; // Very nice and simple skew factor for 3D
156
- int i = fastfloor(xin + s);
157
- int j = fastfloor(yin + s);
158
- int k = fastfloor(zin + s);
159
- float t = (i + j + k) * G3;
160
- float X0 = i - t; // Unskew the cell origin back to (x,y,z) space
161
- float Y0 = j - t;
162
- float Z0 = k - t;
163
- float x0 = xin - X0; // The x,y,z distances from the cell origin
164
- float y0 = yin - Y0;
165
- float z0 = zin - Z0;
166
- // For the 3D case, the simplex shape is a slightly irregular tetrahedron.
167
- // Determine which simplex we are in.
168
- int i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords
169
- int i2, j2, k2; // Offsets for third corner of simplex in (i,j,k) coords
170
- if (x0 >= y0) {
171
- if (y0 >= z0) {
172
- i1 = 1;
173
- j1 = 0;
174
- k1 = 0;
175
- i2 = 1;
176
- j2 = 1;
177
- k2 = 0;
178
- } // X Y Z order
179
- else if (x0 >= z0) {
180
- i1 = 1;
181
- j1 = 0;
182
- k1 = 0;
183
- i2 = 1;
184
- j2 = 0;
185
- k2 = 1;
186
- } // X Z Y order
187
- else {
188
- i1 = 0;
189
- j1 = 0;
190
- k1 = 1;
191
- i2 = 1;
192
- j2 = 0;
193
- k2 = 1;
194
- } // Z X Y order
195
- } else { // x0<y0
196
- if (y0 < z0) {
197
- i1 = 0;
198
- j1 = 0;
199
- k1 = 1;
200
- i2 = 0;
201
- j2 = 1;
202
- k2 = 1;
203
- } // Z Y X order
204
- else if (x0 < z0) {
205
- i1 = 0;
206
- j1 = 1;
207
- k1 = 0;
208
- i2 = 0;
209
- j2 = 1;
210
- k2 = 1;
211
- } // Y Z X order
212
- else {
213
- i1 = 0;
214
- j1 = 1;
215
- k1 = 0;
216
- i2 = 1;
217
- j2 = 1;
218
- k2 = 0;
219
- } // Y X Z order
220
- }
221
- // A step of (1,0,0) in (i,j,k) means a step of (1-c,-c,-c) in (x,y,z),
222
- // a step of (0,1,0) in (i,j,k) means a step of (-c,1-c,-c) in (x,y,z), and
223
- // a step of (0,0,1) in (i,j,k) means a step of (-c,-c,1-c) in (x,y,z), where
224
- // c = 1/6.
225
- float x1 = x0 - i1 + G3; // Offsets for second corner in (x,y,z) coords
226
- float y1 = y0 - j1 + G3;
227
- float z1 = z0 - k1 + G3;
228
- float x2 = x0 - i2 + 2.0f * G3; // Offsets for third corner in (x,y,z) coords
229
- float y2 = y0 - j2 + 2.0f * G3;
230
- float z2 = z0 - k2 + 2.0f * G3;
231
- float x3 = x0 - 1.0f + 3.0f * G3; // Offsets for last corner in (x,y,z) coords
232
- float y3 = y0 - 1.0f + 3.0f * G3;
233
- float z3 = z0 - 1.0f + 3.0f * G3;
234
- // Work out the hashed gradient indices of the four simplex corners
235
- int ii = i & 255;
236
- int jj = j & 255;
237
- int kk = k & 255;
238
- int gi0 = PERM_MOD_12[ii + PERM[jj + PERM[kk]]];
239
- int gi1 = PERM_MOD_12[ii + i1 + PERM[jj + j1 + PERM[kk + k1]]];
240
- int gi2 = PERM_MOD_12[ii + i2 + PERM[jj + j2 + PERM[kk + k2]]];
241
- int gi3 = PERM_MOD_12[ii + 1 + PERM[jj + 1 + PERM[kk + 1]]];
242
- // Calculate the contribution from the four corners
243
- float t0 = 0.5f - x0 * x0 - y0 * y0 - z0 * z0;
244
- if (t0 < 0) {
245
- n0 = 0.0f;
246
- } else {
247
- t0 *= t0;
248
- n0 = t0 * t0 * dot(grad3[gi0], x0, y0, z0);
249
- }
250
- float t1 = 0.5f - x1 * x1 - y1 * y1 - z1 * z1;
251
- if (t1 < 0) {
252
- n1 = 0.0f;
253
- } else {
254
- t1 *= t1;
255
- n1 = t1 * t1 * dot(grad3[gi1], x1, y1, z1);
256
- }
257
- float t2 = 0.5f - x2 * x2 - y2 * y2 - z2 * z2;
258
- if (t2 < 0) {
259
- n2 = 0.0f;
260
- } else {
261
- t2 *= t2;
262
- n2 = t2 * t2 * dot(grad3[gi2], x2, y2, z2);
263
- }
264
- float t3 = 0.5f - x3 * x3 - y3 * y3 - z3 * z3;
265
- if (t3 < 0) {
266
- n3 = 0.0f;
267
- } else {
268
- t3 *= t3;
269
- n3 = t3 * t3 * dot(grad3[gi3], x3, y3, z3);
270
- }
271
- // Add contributions from each corner to get the final noise value.
272
- // The result is scaled to stay just inside [-1,1]
273
- return 32.0f * (n0 + n1 + n2 + n3);
274
- }
275
-
276
- // 4D simplex noise, better simplex rank ordering method 2012-03-09
277
-
278
- /**
279
- *
280
- * @param x
281
- * @param y
282
- * @param z
283
- * @param w
284
- * @return
285
- */
286
- @Override
287
- public float noise(float x, float y, float z, float w) {
288
-
289
- float n0, n1, n2, n3, n4; // Noise contributions from the five corners
290
- // Skew the (x,y,z,w) space to determine which cell of 24 simplices we're in
291
- float s = (x + y + z + w) * F4; // Factor for 4D skewing
292
- int i = fastfloor(x + s);
293
- int j = fastfloor(y + s);
294
- int k = fastfloor(z + s);
295
- int l = fastfloor(w + s);
296
- float t = (i + j + k + l) * G4; // Factor for 4D unskewing
297
- float X0 = i - t; // Unskew the cell origin back to (x,y,z,w) space
298
- float Y0 = j - t;
299
- float Z0 = k - t;
300
- float W0 = l - t;
301
- float x0 = x - X0; // The x,y,z,w distances from the cell origin
302
- float y0 = y - Y0;
303
- float z0 = z - Z0;
304
- float w0 = w - W0;
305
- // For the 4D case, the simplex is a 4D shape I won't even try to describe.
306
- // To find out which of the 24 possible simplices we're in, we need to
307
- // determine the magnitude ordering of x0, y0, z0 and w0.
308
- // Six pair-wise comparisons are performed between each possible pair
309
- // of the four coordinates, and the results are used to rank the numbers.
310
- int rankx = 0;
311
- int ranky = 0;
312
- int rankz = 0;
313
- int rankw = 0;
314
- if (x0 > y0) {
315
- rankx++;
316
- } else {
317
- ranky++;
318
- }
319
- if (x0 > z0) {
320
- rankx++;
321
- } else {
322
- rankz++;
323
- }
324
- if (x0 > w0) {
325
- rankx++;
326
- } else {
327
- rankw++;
328
- }
329
- if (y0 > z0) {
330
- ranky++;
331
- } else {
332
- rankz++;
333
- }
334
- if (y0 > w0) {
335
- ranky++;
336
- } else {
337
- rankw++;
338
- }
339
- if (z0 > w0) {
340
- rankz++;
341
- } else {
342
- rankw++;
343
- }
344
- int i1, j1, k1, l1; // The integer offsets for the second simplex corner
345
- int i2, j2, k2, l2; // The integer offsets for the third simplex corner
346
- int i3, j3, k3, l3; // The integer offsets for the fourth simplex corner
347
- // [rankx, ranky, rankz, rankw] is a 4-vector with the numbers 0, 1, 2 and 3
348
- // in some order. We use a thresholding to set the coordinates in turn.
349
- // Rank 3 denotes the largest coordinate.
350
- i1 = rankx >= 3 ? 1 : 0;
351
- j1 = ranky >= 3 ? 1 : 0;
352
- k1 = rankz >= 3 ? 1 : 0;
353
- l1 = rankw >= 3 ? 1 : 0;
354
- // Rank 2 denotes the second largest coordinate.
355
- i2 = rankx >= 2 ? 1 : 0;
356
- j2 = ranky >= 2 ? 1 : 0;
357
- k2 = rankz >= 2 ? 1 : 0;
358
- l2 = rankw >= 2 ? 1 : 0;
359
- // Rank 1 denotes the second smallest coordinate.
360
- i3 = rankx >= 1 ? 1 : 0;
361
- j3 = ranky >= 1 ? 1 : 0;
362
- k3 = rankz >= 1 ? 1 : 0;
363
- l3 = rankw >= 1 ? 1 : 0;
364
- // The fifth corner has all coordinate offsets = 1, so no need to compute that.
365
- float x1 = x0 - i1 + G4; // Offsets for second corner in (x,y,z,w) coords
366
- float y1 = y0 - j1 + G4;
367
- float z1 = z0 - k1 + G4;
368
- float w1 = w0 - l1 + G4;
369
- float x2 = x0 - i2 + 20.f * G4; // Offsets for third corner in (x,y,z,w) coords
370
- float y2 = y0 - j2 + 20.f * G4;
371
- float z2 = z0 - k2 + 20.f * G4;
372
- float w2 = w0 - l2 + 20.f * G4;
373
- float x3 = x0 - i3 + 30.f * G4; // Offsets for fourth corner in (x,y,z,w) coords
374
- float y3 = y0 - j3 + 30.f * G4;
375
- float z3 = z0 - k3 + 30.f * G4;
376
- float w3 = w0 - l3 + 30.f * G4;
377
- float x4 = x0 - 1.0f + 40.f * G4; // Offsets for last corner in (x,y,z,w) coords
378
- float y4 = y0 - 1.0f + 40.f * G4;
379
- float z4 = z0 - 1.0f + 40.f * G4;
380
- float w4 = w0 - 1.0f + 40.f * G4;
381
- // Work out the hashed gradient indices of the five simplex corners
382
- int ii = i & 255;
383
- int jj = j & 255;
384
- int kk = k & 255;
385
- int ll = l & 255;
386
- int gi0 = PERM[ii + PERM[jj + PERM[kk + PERM[ll]]]] % 32;
387
- int gi1 = PERM[ii + i1 + PERM[jj + j1 + PERM[kk + k1 + PERM[ll + l1]]]] % 32;
388
- int gi2 = PERM[ii + i2 + PERM[jj + j2 + PERM[kk + k2 + PERM[ll + l2]]]] % 32;
389
- int gi3 = PERM[ii + i3 + PERM[jj + j3 + PERM[kk + k3 + PERM[ll + l3]]]] % 32;
390
- int gi4 = PERM[ii + 1 + PERM[jj + 1 + PERM[kk + 1 + PERM[ll + 1]]]] % 32;
391
- // Calculate the contribution from the five corners
392
- float t0 = 0.5f - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;
393
- if (t0 < 0) {
394
- n0 = 0.0f;
395
- } else {
396
- t0 *= t0;
397
- n0 = t0 * t0 * dot(grad4[gi0], x0, y0, z0, w0);
398
- }
399
- float t1 = 0.5f - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1;
400
- if (t1 < 0) {
401
- n1 = 0.0f;
402
- } else {
403
- t1 *= t1;
404
- n1 = t1 * t1 * dot(grad4[gi1], x1, y1, z1, w1);
405
- }
406
- float t2 = 0.5f - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2;
407
- if (t2 < 0) {
408
- n2 = 0.0f;
409
- } else {
410
- t2 *= t2;
411
- n2 = t2 * t2 * dot(grad4[gi2], x2, y2, z2, w2);
412
- }
413
- float t3 = 0.5f - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3;
414
- if (t3 < 0) {
415
- n3 = 0.0f;
416
- } else {
417
- t3 *= t3;
418
- n3 = t3 * t3 * dot(grad4[gi3], x3, y3, z3, w3);
419
- }
420
- float t4 = 0.5f - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4;
421
- if (t4 < 0) {
422
- n4 = 0.0f;
423
- } else {
424
- t4 *= t4;
425
- n4 = t4 * t4 * dot(grad4[gi4], x4, y4, z4, w4);
426
- }
427
- // Sum up and scale the result to cover the range [-1,1]
428
- return 27.0f * (n0 + n1 + n2 + n3 + n4);
429
- }
430
-
431
- @Override
432
- public void noiseDetail(int lod) {
433
-
434
- }
435
-
436
- @Override
437
- public void noiseDetail(int lod, float falloff) {
438
-
439
- }
440
-
441
- @Override
442
- public void noiseSeed(long seed) {
443
-
444
- }
445
-
446
- @Override
447
- public void noiseMode(NoiseMode mode) {
448
-
449
- }
450
-
451
- // Inner class to speed upp gradient computations
452
- // (In Java, array access is a lot slower than member access)
453
- private static class Grad {
454
-
455
- float x, y, z, w;
456
-
457
- Grad(float x, float y, float z) {
458
- this.x = x;
459
- this.y = y;
460
- this.z = z;
461
- }
462
-
463
- Grad(float x, float y, float z, float w) {
464
- this.x = x;
465
- this.y = y;
466
- this.z = z;
467
- this.w = w;
468
- }
469
- }
470
- }