-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update OpenSimplex, add missing annotations and improve structure
- Loading branch information
Showing
29 changed files
with
2,692 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 57 additions & 57 deletions
114
...e/articdive/jnoise/api/Interpolation.java → ...e/jnoise/interpolation/Interpolation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,57 @@ | ||
/* | ||
* JNoise | ||
* Copyright (C) 2021 Articdive (Lukas Mansour) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package de.articdive.jnoise.api; | ||
|
||
/** | ||
* @author Lukas Mansour | ||
*/ | ||
public interface Interpolation { | ||
|
||
/** | ||
* Interpolates a value between two known values. | ||
* | ||
* @param x Position for the data to be interpolated. | ||
* @param a The first known value. | ||
* @param b The second known value. | ||
* @return an interpolated value for x. | ||
*/ | ||
double lerp(double x, double a, double b); | ||
|
||
/** | ||
* Interpolates between an unknown number of values. | ||
* The amount of positions repsents the dimension | ||
* The amount of values must be 2^(amount of position). | ||
* | ||
* @param positions A list of positions starting with the first stage position and going up in order. | ||
* @param values A list of values starting with the first stage values and going up in order. | ||
* @return an interpolated value between all the given positions. | ||
*/ | ||
default double lerp(double[] positions, double[] values) { | ||
if (values.length != 1 << positions.length) { | ||
throw new IllegalArgumentException("The amount of values must be 2^(amount of fractals)."); | ||
} | ||
for (int i = 0; i < positions.length; i++) { | ||
for (int j = 0; j < ((1 << positions.length) - i); j += 2) { | ||
values[j / 2] = lerp(positions[i], values[j], values[j + 1]); | ||
} | ||
} | ||
// This should only have 1 element, the final value! | ||
return values[0]; | ||
} | ||
} | ||
/* | ||
* JNoise | ||
* Copyright (C) 2021 Articdive (Lukas Mansour) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package de.articdive.jnoise.interpolation; | ||
|
||
/** | ||
* @author Lukas Mansour | ||
*/ | ||
public interface Interpolation { | ||
|
||
/** | ||
* Interpolates a value between two known values. | ||
* | ||
* @param x Position for the data to be interpolated. | ||
* @param a The first known value. | ||
* @param b The second known value. | ||
* @return an interpolated value for x. | ||
*/ | ||
double lerp(double x, double a, double b); | ||
|
||
/** | ||
* Interpolates between an unknown number of values. | ||
* The amount of positions repsents the dimension | ||
* The amount of values must be 2^(amount of position). | ||
* | ||
* @param positions A list of positions starting with the first stage position and going up in order. | ||
* @param values A list of values starting with the first stage values and going up in order. | ||
* @return an interpolated value between all the given positions. | ||
*/ | ||
default double lerp(double[] positions, double[] values) { | ||
if (values.length != 1 << positions.length) { | ||
throw new IllegalArgumentException("The amount of values must be 2^(amount of fractals)."); | ||
} | ||
for (int i = 0; i < positions.length; i++) { | ||
for (int j = 0; j < ((1 << positions.length) - i); j += 2) { | ||
values[j / 2] = lerp(positions[i], values[j], values[j + 1]); | ||
} | ||
} | ||
// This should only have 1 element, the final value! | ||
return values[0]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/main/java/de/articdive/jnoise/noise/opensimplex/FastSimplexBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* JNoise | ||
* Copyright (C) 2021 Articdive (Lukas Mansour) | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package de.articdive.jnoise.noise.opensimplex; | ||
|
||
import de.articdive.jnoise.JNoise; | ||
import de.articdive.jnoise.api.NoiseBuilder; | ||
import de.articdive.jnoise.simplex_variants.Simplex2DVariant; | ||
import de.articdive.jnoise.simplex_variants.Simplex3DVariant; | ||
import de.articdive.jnoise.simplex_variants.Simplex4DVariant; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* @author Lukas Mansour | ||
*/ | ||
public class FastSimplexBuilder extends NoiseBuilder<FastSimplexBuilder> { | ||
private double frequency = 1.0; | ||
private Simplex2DVariant variant2D = Simplex2DVariant.CLASSIC; | ||
private Simplex3DVariant variant3D = Simplex3DVariant.CLASSIC; | ||
private Simplex4DVariant variant4D = Simplex4DVariant.CLASSIC; | ||
|
||
@NotNull | ||
@Override | ||
protected FastSimplexBuilder self() { | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the frequency for the {@link FastSimplexGenerator}. | ||
* | ||
* @param frequency the new frequency for the {@link FastSimplexGenerator}. | ||
* @return {@link FastSimplexBuilder} this | ||
*/ | ||
@NotNull | ||
public FastSimplexBuilder setFrequency(double frequency) { | ||
if (frequency <= 0) { | ||
throw new IllegalArgumentException("Frequency must be a non-zero positive value."); | ||
} | ||
this.frequency = frequency; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the variant used for 2D OpenSimplex noise | ||
* | ||
* @param variant2D the new {@link Simplex2DVariant} for the {@link FastSimplexGenerator}. | ||
* @return {@link FastSimplexBuilder} this | ||
*/ | ||
@NotNull | ||
public FastSimplexBuilder setVariant2D(@NotNull Simplex2DVariant variant2D) { | ||
this.variant2D = variant2D; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the variant used for 3D OpenSimplex noise | ||
* | ||
* @param variant3D the new {@link Simplex3DVariant} for the {@link FastSimplexGenerator}. | ||
* @return {@link FastSimplexBuilder} this | ||
*/ | ||
@NotNull | ||
public FastSimplexBuilder setVariant3D(@NotNull Simplex3DVariant variant3D) { | ||
this.variant3D = variant3D; | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the variant used for 4D OpenSimplex noise | ||
* | ||
* @param variant4D the new {@link Simplex4DVariant} for the {@link FastSimplexGenerator}. | ||
* @return {@link FastSimplexBuilder} this | ||
*/ | ||
@NotNull | ||
public FastSimplexBuilder setVariant4D(@NotNull Simplex4DVariant variant4D) { | ||
this.variant4D = variant4D; | ||
return this; | ||
} | ||
|
||
@Override | ||
@NotNull | ||
public JNoise build() { | ||
return JNoise.build(new FastSimplexGenerator(seed, frequency, variant2D, variant3D, variant4D)); | ||
} | ||
} |
Oops, something went wrong.