mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
Update lerp usage and docs
This commit is contained in:
@@ -7,6 +7,9 @@
|
||||
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation;
|
||||
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
|
||||
/**
|
||||
* Class for bilinear interpolation of values arranged on a unit square.
|
||||
*/
|
||||
@@ -28,19 +31,6 @@ public class Interpolator {
|
||||
this.v3 = v3;
|
||||
}
|
||||
|
||||
/**
|
||||
* 1D Linear interpolation between 2 points 1 unit apart.
|
||||
*
|
||||
* @param t - Distance from v0. Total distance between v0 and v1 is 1 unit.
|
||||
* @param v0 - Value at v0.
|
||||
* @param v1 - Value at v1.
|
||||
*
|
||||
* @return double - The interpolated value.
|
||||
*/
|
||||
public static double lerp(double t, double v0, double v1) {
|
||||
return v0 + t * (v1 - v0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 2D Bilinear interpolation between 4 points on a unit square.
|
||||
*
|
||||
@@ -50,8 +40,8 @@ public class Interpolator {
|
||||
* @return double - The interpolated value.
|
||||
*/
|
||||
public double bilerp(double s, double t) {
|
||||
double v01 = lerp(s, v0, v1);
|
||||
double v23 = lerp(s, v2, v3);
|
||||
return lerp(t, v01, v23);
|
||||
double v01 = MathUtil.lerp(s, v0, v1);
|
||||
double v23 = MathUtil.lerp(s, v2, v3);
|
||||
return MathUtil.lerp(t, v01, v23);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation;
|
||||
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
|
||||
|
||||
/**
|
||||
* Class for bilinear interpolation of values arranged on a unit square.
|
||||
*/
|
||||
@@ -34,6 +37,6 @@ public class Interpolator3 {
|
||||
}
|
||||
|
||||
public double trilerp(double x, double y, double z) {
|
||||
return Interpolator.lerp(x, top.bilerp(y, z), bottom.bilerp(y, z));
|
||||
return MathUtil.lerp(x, top.bilerp(y, z), bottom.bilerp(y, z));
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,9 @@ package com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation;
|
||||
|
||||
import com.dfsek.terra.addons.chunkgenerator.config.noise.BiomeNoiseProperties;
|
||||
import com.dfsek.terra.api.properties.PropertyKey;
|
||||
import com.dfsek.terra.api.util.MathUtil;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
|
||||
import static com.dfsek.terra.addons.chunkgenerator.generation.math.interpolation.Interpolator.lerp;
|
||||
|
||||
|
||||
public class LazilyEvaluatedInterpolator {
|
||||
private final Double[] samples; //
|
||||
|
||||
@@ -82,10 +80,10 @@ public class LazilyEvaluatedInterpolator {
|
||||
|
||||
double xFrac = (double) (x % horizontalRes) / horizontalRes;
|
||||
double zFrac = (double) (z % horizontalRes) / horizontalRes;
|
||||
double lerp_bottom_0 = lerp(zFrac, sample_0_0_0, sample_0_0_1);
|
||||
double lerp_bottom_1 = lerp(zFrac, sample_1_0_0, sample_1_0_1);
|
||||
double lerp_bottom_0 = MathUtil.lerp(zFrac, sample_0_0_0, sample_0_0_1);
|
||||
double lerp_bottom_1 = MathUtil.lerp(zFrac, sample_1_0_0, sample_1_0_1);
|
||||
|
||||
double lerp_bottom = lerp(xFrac, lerp_bottom_0, lerp_bottom_1);
|
||||
double lerp_bottom = MathUtil.lerp(xFrac, lerp_bottom_0, lerp_bottom_1);
|
||||
|
||||
if(yRange) { // we can do bilerp
|
||||
return lerp_bottom;
|
||||
@@ -101,11 +99,11 @@ public class LazilyEvaluatedInterpolator {
|
||||
double sample_1_1_0 = sample(xIndex + 1, yIndex + 1, zIndex, x + horizontalRes, y + verticalRes, z);
|
||||
double sample_1_1_1 = sample(xIndex + 1, yIndex + 1, zIndex + 1, x + horizontalRes, y + verticalRes, z + horizontalRes);
|
||||
|
||||
double lerp_top_0 = lerp(zFrac, sample_0_1_0, sample_0_1_1);
|
||||
double lerp_top_1 = lerp(zFrac, sample_1_1_0, sample_1_1_1);
|
||||
double lerp_top_0 = MathUtil.lerp(zFrac, sample_0_1_0, sample_0_1_1);
|
||||
double lerp_top_1 = MathUtil.lerp(zFrac, sample_1_1_0, sample_1_1_1);
|
||||
|
||||
double lerp_top = lerp(xFrac, lerp_top_0, lerp_top_1);
|
||||
double lerp_top = MathUtil.lerp(xFrac, lerp_top_0, lerp_top_1);
|
||||
|
||||
return lerp(yFrac, lerp_bottom, lerp_top);
|
||||
return MathUtil.lerp(yFrac, lerp_bottom, lerp_top);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,10 +43,6 @@ public class VanillaOre implements Structure {
|
||||
this.materials = materials;
|
||||
}
|
||||
|
||||
public static double lerp(double t, double v0, double v1) {
|
||||
return v0 + t * (v1 - v0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean generate(Vector3Int location, WritableWorld world, Random random, Rotation rotation) {
|
||||
float randomRadian = random.nextFloat() * (float) Math.PI;
|
||||
@@ -68,9 +64,9 @@ public class VanillaOre implements Structure {
|
||||
// Compute initial point positions and radius
|
||||
for(int i = 0; i < sizeInt; ++i) {
|
||||
float t = (float) i / (float) sizeInt;
|
||||
double xt = lerp(t, startX, endX);
|
||||
double yt = lerp(t, startY, endY);
|
||||
double zt = lerp(t, startZ, endZ);
|
||||
double xt = MathUtil.lerp(t, startX, endX);
|
||||
double yt = MathUtil.lerp(t, startY, endY);
|
||||
double zt = MathUtil.lerp(t, startZ, endZ);
|
||||
double roll = random.nextDouble() * size / 16.0;
|
||||
// Taper radius closer to line ends
|
||||
double radius = ((MathUtil.sin((float) Math.PI * t) + 1.0F) * roll + 1.0) / 2.0;
|
||||
|
||||
@@ -237,8 +237,17 @@ public final class MathUtil {
|
||||
return h;
|
||||
}
|
||||
|
||||
public static double lerp(double a, double b, double t) {
|
||||
return a + t * (b - a);
|
||||
/**
|
||||
* 1D Linear interpolation between 2 points 1 unit apart.
|
||||
*
|
||||
* @param t - Distance from v0. Total distance between v0 and v1 is 1 unit.
|
||||
* @param v0 - Value at v0.
|
||||
* @param v1 - Value at v1.
|
||||
*
|
||||
* @return double - The interpolated value.
|
||||
*/
|
||||
public static double lerp(double t, double v0, double v1) {
|
||||
return v0 + t * (v1 - v0);
|
||||
}
|
||||
|
||||
public static double cubicLerp(double a, double b, double c, double d, double t) {
|
||||
|
||||
Reference in New Issue
Block a user