Skip to content

Commit 819b5b4

Browse files
committed
Fix lint
1 parent de5cbfc commit 819b5b4

File tree

2 files changed

+39
-33
lines changed

2 files changed

+39
-33
lines changed

src/main/java/com/thealgorithms/others/PerlinNoise.java

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,54 @@
77
* Utility for generating 2D value-noise blended across octaves (commonly known
88
* as Perlin-like noise).
99
*
10-
* <p>The implementation follows the classic approach of:
10+
* <p>
11+
* The implementation follows the classic approach of:
1112
* <ol>
12-
* <li>Generate a base grid of random values in [0, 1).</li>
13-
* <li>For each octave k, compute a layer by bilinear interpolation of the base grid
14-
* at period 2^k.</li>
15-
* <li>Blend all layers from coarse to fine using a geometric series of amplitudes
16-
* controlled by {@code persistence}, then normalize to [0, 1].</li>
13+
* <li>Generate a base grid of random values in [0, 1).</li>
14+
* <li>For each octave k, compute a layer by bilinear interpolation of the base
15+
* grid
16+
* at period 2^k.</li>
17+
* <li>Blend all layers from coarse to fine using a geometric series of
18+
* amplitudes
19+
* controlled by {@code persistence}, then normalize to [0, 1].</li>
1720
* </ol>
1821
*
19-
* <p>For background see: <a href="http://devmag.org.za/2009/04/25/perlin-noise/">Perlin Noise</a>.
22+
* <p>
23+
* For background see:
24+
* <a href="http://devmag.org.za/2009/04/25/perlin-noise/">Perlin Noise</a>.
2025
*
21-
* <p>Constraints and notes:
26+
* <p>
27+
* Constraints and notes:
2228
* <ul>
23-
* <li>{@code width} and {@code height} should be positive.</li>
24-
* <li>{@code octaveCount} must be at least 1 (0 would lead to a division by zero).</li>
25-
* <li>{@code persistence} should be in (0, 1], typical values around 0.5–0.8.</li>
26-
* <li>Given the same seed and parameters, results are deterministic.</li>
29+
* <li>{@code width} and {@code height} should be positive.</li>
30+
* <li>{@code octaveCount} must be at least 1 (0 would lead to a division by
31+
* zero).</li>
32+
* <li>{@code persistence} should be in (0, 1], typical values around
33+
* 0.5–0.8.</li>
34+
* <li>Given the same seed and parameters, results are deterministic.</li>
2735
* </ul>
2836
*/
37+
2938
public final class PerlinNoise {
30-
private PerlinNoise() {}
39+
private PerlinNoise() {
40+
}
3141

3242
/**
3343
* Generate a 2D array of blended noise values normalized to [0, 1].
3444
*
35-
* @param width width of the noise array (columns)
36-
* @param height height of the noise array (rows)
45+
* @param width width of the noise array (columns)
46+
* @param height height of the noise array (rows)
3747
* @param octaveCount number of octaves (layers) to blend; must be >= 1
3848
* @param persistence per-octave amplitude multiplier in (0, 1]
39-
* @param seed seed for the random base grid
40-
* @return a {@code width x height} array containing blended noise values in [0, 1]
49+
* @param seed seed for the random base grid
50+
* @return a {@code width x height} array containing blended noise values in [0,
51+
* 1]
4152
*/
4253
static float[][] generatePerlinNoise(int width, int height, int octaveCount, float persistence, long seed) {
4354
if (width <= 0 || height <= 0) {
4455
throw new IllegalArgumentException("width and height must be > 0");
4556
}
57+
4658
if (octaveCount < 1) {
4759
throw new IllegalArgumentException("octaveCount must be >= 1");
4860
}
@@ -110,8 +122,8 @@ static float[][] blendAndNormalize(float[][][] layers, int width, int height, fl
110122
* Generate a single octave layer by bilinear interpolation of a base grid at a
111123
* given octave (period = 2^octave).
112124
*
113-
* @param base base random float array of size {@code width x height}
114-
* @param width width of noise array
125+
* @param base base random float array of size {@code width x height}
126+
* @param width width of noise array
115127
* @param height height of noise array
116128
* @param octave current octave (0 for period 1, 1 for period 2, ...)
117129
* @return float array containing the octave's interpolated values
@@ -152,8 +164,8 @@ static float[][] generatePerlinNoiseLayer(float[][] base, int width, int height,
152164
/**
153165
* Linear interpolation between two values.
154166
*
155-
* @param a value at alpha = 0
156-
* @param b value at alpha = 1
167+
* @param a value at alpha = 0
168+
* @param b value at alpha = 1
157169
* @param alpha interpolation factor in [0, 1]
158170
* @return interpolated value {@code (1 - alpha) * a + alpha * b}
159171
*/

src/test/java/com/thealgorithms/others/PerlinNoiseTest.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,11 @@ void testSingleOctaveLayer() {
8888
@Test
8989
@DisplayName("Invalid inputs are rejected")
9090
void testInvalidInputs() {
91-
assertThatThrownBy(() -> PerlinNoise.generatePerlinNoise(0, 5, 1, 0.5f, 1L))
92-
.isInstanceOf(IllegalArgumentException.class);
93-
assertThatThrownBy(() -> PerlinNoise.generatePerlinNoise(5, -1, 1, 0.5f, 1L))
94-
.isInstanceOf(IllegalArgumentException.class);
95-
assertThatThrownBy(() -> PerlinNoise.generatePerlinNoise(5, 5, 0, 0.5f, 1L))
96-
.isInstanceOf(IllegalArgumentException.class);
97-
assertThatThrownBy(() -> PerlinNoise.generatePerlinNoise(5, 5, 1, 0f, 1L))
98-
.isInstanceOf(IllegalArgumentException.class);
99-
assertThatThrownBy(() -> PerlinNoise.generatePerlinNoise(5, 5, 1, Float.NaN, 1L))
100-
.isInstanceOf(IllegalArgumentException.class);
101-
assertThatThrownBy(() -> PerlinNoise.generatePerlinNoise(5, 5, 1, 1.1f, 1L))
102-
.isInstanceOf(IllegalArgumentException.class);
91+
assertThatThrownBy(() -> PerlinNoise.generatePerlinNoise(0, 5, 1, 0.5f, 1L)).isInstanceOf(IllegalArgumentException.class);
92+
assertThatThrownBy(() -> PerlinNoise.generatePerlinNoise(5, -1, 1, 0.5f, 1L)).isInstanceOf(IllegalArgumentException.class);
93+
assertThatThrownBy(() -> PerlinNoise.generatePerlinNoise(5, 5, 0, 0.5f, 1L)).isInstanceOf(IllegalArgumentException.class);
94+
assertThatThrownBy(() -> PerlinNoise.generatePerlinNoise(5, 5, 1, 0f, 1L)).isInstanceOf(IllegalArgumentException.class);
95+
assertThatThrownBy(() -> PerlinNoise.generatePerlinNoise(5, 5, 1, Float.NaN, 1L)).isInstanceOf(IllegalArgumentException.class);
96+
assertThatThrownBy(() -> PerlinNoise.generatePerlinNoise(5, 5, 1, 1.1f, 1L)).isInstanceOf(IllegalArgumentException.class);
10397
}
10498
}

0 commit comments

Comments
 (0)