Skip to content

Commit

Permalink
Performance improvements, fix javadoc and simplify APIs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Articdive committed Feb 15, 2024
1 parent 4d6594f commit 28a6f6b
Show file tree
Hide file tree
Showing 22 changed files with 381 additions and 447 deletions.
10 changes: 5 additions & 5 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ All Noise Implementations support 1D, 2D, 3D and 4D noise.
Example: Getting 2D Perlin-Noise:

```java
// 1D Noise at x = 1.0 and y = 0.5 in a 2D plane.
return perlinLinear.evaluateNoise(1.0,0.5);
// 1D Noise at x = 1.0 and y = 0.5 in a 2D plane.
return perlinLinear.evaluateNoise(1.0,0.5);
```

Example: Getting 3D Perlin-Noise:

```java
// 1D Noise at x = 1.0, y = 0.5 and z = 1.22 in a 3D plane.
return perlinLinear.evaluateNoise(1.0,0.5,1.22);
// 1D Noise at x = 1.0, y = 0.5 and z = 1.22 in a 3D plane.
return perlinLinear.evaluateNoise(1.0,0.5,1.22);
```

### Advantages of the JNoise Pipeline
Expand Down Expand Up @@ -264,7 +264,7 @@ differentely. By using the method evaluateNoiseResult(...) defined in JNoiseDeta
containing more than just the numeric value.

```java
public JNoiseDetailed<WorleyNoiseResult<Vector>>worleyNoise=JNoise.newBuilder().worley(WorleyNoiseGenerator.newBuilder().[...].build()).buildDetailed();
public JNoiseDetailed<WorleyNoiseResult> worleyNoise=JNoise.newBuilder().worley(WorleyNoiseGenerator.newBuilder().[...].build()).buildDetailed();
{
worleyNoise.evaluateNoiseResult(x,y).getClosestPoint();
worleyNoise.evaluateNoiseResult(x,y).getValue()
Expand Down
6 changes: 4 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ val exportedProjects = arrayListOf(

tasks {
register<Javadoc>("global-javadoc") {
source = files(exportedProjects.map { project(it).the<SourceSetContainer>()["main"].allJava.asFileTree }).asFileTree
source = files(exportedProjects.map { project(it).the<SourceSetContainer>()["main"].allJava.asFileTree }).filter {
!it.name.equals("module-info.java")
}.asFileTree
classpath = files(exportedProjects.map { project(it).the<SourceSetContainer>()["main"].compileClasspath })
setDestinationDir(file("${buildDir}/docs/javadoc"))
setDestinationDir(file("${layout.buildDirectory.get()}/docs/javadoc"))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.articdive.jnoise.core.api.annotations;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface Vector1D {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.articdive.jnoise.core.api.annotations;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface Vector2D {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.articdive.jnoise.core.api.annotations;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface Vector3D {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.articdive.jnoise.core.api.annotations;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.RUNTIME)
public @interface Vector4D {
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package de.articdive.jnoise.core.api.noisegen;

import de.articdive.jnoise.core.util.vectors.Vector;

/**
* Interface that denotes a noise result, which is used to wrap the results of an entire noise generation step.
* Useful when there are multiple result types, i.e. not only a double but e.g. a {@link Vector}.
* Useful when there are multiple result types, i.e. not only a double but e.g. a vector.
*
* @author Articdive
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package de.articdive.jnoise.core.api.transformers;

import de.articdive.jnoise.core.util.vectors.Vector2D;
import de.articdive.jnoise.core.util.vectors.Vector3D;
import de.articdive.jnoise.core.util.vectors.Vector4D;
import de.articdive.jnoise.core.api.annotations.Vector1D;
import de.articdive.jnoise.core.api.annotations.Vector2D;
import de.articdive.jnoise.core.api.annotations.Vector3D;
import de.articdive.jnoise.core.api.annotations.Vector4D;
import org.jspecify.annotations.NullMarked;

/**
Expand All @@ -14,40 +15,30 @@
@NullMarked
public interface DetailedTransformer {
/**
* Transforms an x coordinate before noise evaluation.
* Transforms an x coordinate before noise evaluation via a side-effect.
*
* @param x coordinate to transform.
* @return transformed x coordinate.
* @param vec1D a double array representing a 1D vector containing the x coordinate to transform.
*/
double transform(double x);
void transform1D(@Vector1D double[] vec1D);

/**
* Transforms an x and y coordinate before noise evaluation.
* Transforms an x and y coordinate before noise evaluation via a side-effect.
*
* @param x X coordinate to transform.
* @param y Y coordinate to transform.
* @return {@link Vector2D} containing the transformed x and y coordinates.
* @param vec2D a double array representing a 2D vector containing the x and y coordinate to transform.
*/
Vector2D transform(double x, double y);
void transform2D(@Vector2D double[] vec2D);

/**
* Transforms an x, y and z coordinate before noise evaluation.
* Transforms an x, y and z coordinate before noise evaluation via a side-effect.
*
* @param x X coordinate to transform.
* @param y Y coordinate to transform.
* @param z Z coordinate to transform.
* @return {@link Vector3D} containing the transformed x, y and z coordinates.
* @param vec3D a double array representing a 3D vector containing the x, y and z coordinate to transform.
*/
Vector3D transform(double x, double y, double z);
void transform3D(@Vector3D double[] vec3D);

/**
* Transforms an x, y, z and w coordinate before noise evaluation.
* Transforms an x, y, z and w coordinate before noise evaluation via a side-effect.
*
* @param x X coordinate to transform.
* @param y Y coordinate to transform.
* @param z Z coordinate to transform.
* @param w W coordinate to transform.
* @return {@link Vector4D} containing the transformed x, y, z and w coordinates.
* @param vec4D a double array representing a 4D vector containing the x, y, z and w coordinate to transform.
*/
Vector4D transform(double x, double y, double z, double w);
void transform4D(@Vector4D double[] vec4D);
}
37 changes: 37 additions & 0 deletions core/src/main/java/de/articdive/jnoise/core/util/MathUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package de.articdive.jnoise.core.util;

import de.articdive.jnoise.core.api.annotations.Vector2D;
import de.articdive.jnoise.core.api.annotations.Vector3D;
import de.articdive.jnoise.core.api.annotations.Vector4D;

/**
* Utility class for mathematical functions.
*
Expand Down Expand Up @@ -29,4 +33,37 @@ public static double exp2(double x) {
public static double log2(double x) {
return Math.log(x) / Math.log(2);
}

/**
* Calculates the dot product of the specified 2D vectors.
*
* @param a a double array representing a 2D vector.
* @param b a double array representing a 2D vector.
* @return the dot product of the two 2D vectors.
*/
public static double dot2D(@Vector2D double[] a, @Vector2D double[] b) {
return (a[0] * b[0]) + (a[1] * b[1]);
}

/**
* Calculates the dot product of the specified 3D vectors.
*
* @param a a double array representing a 3D vector.
* @param b a double array representing a 3D vector.
* @return the dot product of the two 3D vectors.
*/
public static double dot3D(@Vector3D double[] a, @Vector3D double[] b) {
return (a[0] * b[0]) + (a[1] * b[1]) + (a[2] * b[2]);
}

/**
* Calculates the dot product of the specified 4D vectors.
*
* @param a a double array representing a 4D vector.
* @param b a double array representing a 4D vector.
* @return the dot product of the two 4D vectors.
*/
public static double dot4D(@Vector4D double[] a, @Vector4D double[] b) {
return (a[0] * b[0]) + (a[1] * b[1]) + (a[2] * b[2]) + (a[3] * b[3]);
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 3 additions & 3 deletions core/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* The core JNoise module.
*
* The core JNoise module.
*
* Requires JSpecify.
*/
module de.articdive.jnoise.core {
Expand All @@ -12,7 +12,7 @@
exports de.articdive.jnoise.core.api.transformers;

exports de.articdive.jnoise.core.util;
exports de.articdive.jnoise.core.util.vectors;
exports de.articdive.jnoise.core.api.annotations;

requires transitive org.jspecify;
}
Loading

0 comments on commit 28a6f6b

Please sign in to comment.