Derivative API documentation

This commit is contained in:
Astrash
2024-04-19 21:25:16 +10:00
parent 35246d65b9
commit ff03b38b81
3 changed files with 28 additions and 7 deletions

View File

@@ -14,7 +14,7 @@ public class DerivativeNoiseSamplerTemplate extends SamplerTemplate<DerivativeNo
@Override @Override
public boolean validate() throws ValidationException { public boolean validate() throws ValidationException {
if (!DerivativeNoiseSampler.providesDerivative(sampler)) throw new ValidationException("Provided sampler does not support calculating a derivative"); if (!DerivativeNoiseSampler.isDifferentiable(sampler)) throw new ValidationException("Provided sampler does not support calculating a derivative");
return super.validate(); return super.validate();
} }

View File

@@ -65,7 +65,7 @@ public class DerivativeFractal implements DerivativeNoiseSampler {
} }
@Override @Override
public boolean isDerivable() { public boolean isDifferentiable() {
return true; return true;
} }

View File

@@ -1,20 +1,41 @@
package com.dfsek.terra.api.noise; package com.dfsek.terra.api.noise;
/** /**
* A NoiseSampler which additionally provides directional derivatives * A NoiseSampler which additionally may provide a 1st directional derivative
*/ */
public interface DerivativeNoiseSampler extends NoiseSampler { public interface DerivativeNoiseSampler extends NoiseSampler {
static boolean providesDerivative(NoiseSampler sampler) { static boolean isDifferentiable(NoiseSampler sampler) {
if (sampler instanceof DerivativeNoiseSampler dSampler) { if (sampler instanceof DerivativeNoiseSampler dSampler) {
return dSampler.isDerivable(); return dSampler.isDifferentiable();
} }
return false; return false;
} }
boolean isDerivable(); /**
* Samplers may or may not be able to provide a derivative depending on what
* inputs they take, this method signals whether this is the case.
*
* @return If the noise sampler provides a derivative or not
*/
boolean isDifferentiable();
/**
* Derivative return version of standard 2D noise evaluation
* @param seed
* @param x
* @param y
* @return 3 element array, in index order: noise value, partial x derivative, partial y derivative
*/
double[] noised(long seed, double x, double y); double[] noised(long seed, double x, double y);
/**
* Derivative return version of standard 3D noise evaluation
* @param seed
* @param x
* @param y
* @param z
* @return 4 element array, in index order: noise value, partial x derivative, partial y derivative, partial z derivative
*/
double[] noised(long seed, double x, double y, double z); double[] noised(long seed, double x, double y, double z);
} }