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