This commit is contained in:
Daniel Mills 2020-10-24 00:29:40 -04:00
parent 368a74dfc9
commit 018eb2fdcd
16 changed files with 837 additions and 0 deletions

View File

@ -0,0 +1,89 @@
package com.volmit.iris.gen.v2.scaffold.stream;
import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
import com.volmit.iris.util.IrisInterpolation;
public class BiHermiteStream<T> extends BasicLayer implements ProceduralStream<T>, Interpolator<T>
{
private final ProceduralStream<T> stream;
private final int rx;
private final int ry;
private final double tension;
private final double bias;
public BiHermiteStream(ProceduralStream<T> stream, int rx, int ry, double tension, double bias)
{
this.stream = stream;
this.rx = rx;
this.ry = ry;
this.tension = tension;
this.bias = bias;
}
public BiHermiteStream(ProceduralStream<T> stream, int rx, int ry)
{
this(stream, rx, ry, 0.5, 0);
}
public T interpolate(double x, double y)
{
int fx = (int) Math.floor(x / rx);
int fz = (int) Math.floor(y / ry);
int x0 = (int) Math.round((fx - 1) * rx);
int z0 = (int) Math.round((fz - 1) * ry);
int x1 = (int) Math.round(fx * rx);
int z1 = (int) Math.round(fz * ry);
int x2 = (int) Math.round((fx + 1) * rx);
int z2 = (int) Math.round((fz + 1) * ry);
int x3 = (int) Math.round((fx + 2) * rx);
int z3 = (int) Math.round((fz + 2) * ry);
double px = IrisInterpolation.rangeScale(0, 1, x1, x2, x);
double pz = IrisInterpolation.rangeScale(0, 1, z1, z2, y);
//@builder
return stream.fromDouble(IrisInterpolation.bihermite(
stream.getDouble(x0, z0),
stream.getDouble(x0, z1),
stream.getDouble(x0, z2),
stream.getDouble(x0, z3),
stream.getDouble(x1, z0),
stream.getDouble(x1, z1),
stream.getDouble(x1, z2),
stream.getDouble(x1, z3),
stream.getDouble(x2, z0),
stream.getDouble(x2, z1),
stream.getDouble(x2, z2),
stream.getDouble(x2, z3),
stream.getDouble(x3, z0),
stream.getDouble(x3, z1),
stream.getDouble(x3, z2),
stream.getDouble(x3, z3),
px, pz, tension, bias));
//@done
}
@Override
public double toDouble(T t)
{
return stream.toDouble(t);
}
@Override
public T fromDouble(double d)
{
return stream.fromDouble(d);
}
@Override
public T get(double x, double z)
{
return interpolate(x, z);
}
@Override
public T get(double x, double y, double z)
{
return interpolate(x, z);
}
}

View File

@ -0,0 +1,80 @@
package com.volmit.iris.gen.v2.scaffold.stream;
import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
import com.volmit.iris.util.IrisInterpolation;
public class BicubicStream<T> extends BasicLayer implements ProceduralStream<T>, Interpolator<T>
{
private final ProceduralStream<T> stream;
private final int rx;
private final int ry;
public BicubicStream(ProceduralStream<T> stream, int rx, int ry)
{
this.stream = stream;
this.rx = rx;
this.ry = ry;
}
public T interpolate(double x, double y)
{
int fx = (int) Math.floor(x / rx);
int fz = (int) Math.floor(y / ry);
int x0 = (int) Math.round((fx - 1) * rx);
int z0 = (int) Math.round((fz - 1) * ry);
int x1 = (int) Math.round(fx * rx);
int z1 = (int) Math.round(fz * ry);
int x2 = (int) Math.round((fx + 1) * rx);
int z2 = (int) Math.round((fz + 1) * ry);
int x3 = (int) Math.round((fx + 2) * rx);
int z3 = (int) Math.round((fz + 2) * ry);
double px = IrisInterpolation.rangeScale(0, 1, x1, x2, x);
double pz = IrisInterpolation.rangeScale(0, 1, z1, z2, y);
//@builder
return stream.fromDouble(IrisInterpolation.bicubic(
stream.getDouble(x0, z0),
stream.getDouble(x0, z1),
stream.getDouble(x0, z2),
stream.getDouble(x0, z3),
stream.getDouble(x1, z0),
stream.getDouble(x1, z1),
stream.getDouble(x1, z2),
stream.getDouble(x1, z3),
stream.getDouble(x2, z0),
stream.getDouble(x2, z1),
stream.getDouble(x2, z2),
stream.getDouble(x2, z3),
stream.getDouble(x3, z0),
stream.getDouble(x3, z1),
stream.getDouble(x3, z2),
stream.getDouble(x3, z3),
px, pz));
//@done
}
@Override
public double toDouble(T t)
{
return stream.toDouble(t);
}
@Override
public T fromDouble(double d)
{
return stream.fromDouble(d);
}
@Override
public T get(double x, double z)
{
return interpolate(x, z);
}
@Override
public T get(double x, double y, double z)
{
return interpolate(x, z);
}
}

View File

@ -0,0 +1,64 @@
package com.volmit.iris.gen.v2.scaffold.stream;
import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
import com.volmit.iris.util.IrisInterpolation;
public class BilinearStream<T> extends BasicLayer implements ProceduralStream<T>, Interpolator<T>
{
private final ProceduralStream<T> stream;
private final int rx;
private final int ry;
public BilinearStream(ProceduralStream<T> stream, int rx, int ry)
{
this.stream = stream;
this.rx = rx;
this.ry = ry;
}
public T interpolate(double x, double y)
{
int fx = (int) Math.floor(x / rx);
int fz = (int) Math.floor(y / ry);
int x1 = (int) Math.round(fx * rx);
int z1 = (int) Math.round(fz * ry);
int x2 = (int) Math.round((fx + 1) * rx);
int z2 = (int) Math.round((fz + 1) * ry);
double px = IrisInterpolation.rangeScale(0, 1, x1, x2, x);
double pz = IrisInterpolation.rangeScale(0, 1, z1, z2, y);
//@builder
return stream.fromDouble(IrisInterpolation.blerp(
stream.getDouble(x1, z1),
stream.getDouble(x2, z1),
stream.getDouble(x1, z2),
stream.getDouble(x2, z2),
px, pz));
//@done
}
@Override
public double toDouble(T t)
{
return stream.toDouble(t);
}
@Override
public T fromDouble(double d)
{
return stream.fromDouble(d);
}
@Override
public T get(double x, double z)
{
return interpolate(x, z);
}
@Override
public T get(double x, double y, double z)
{
return interpolate(x, z);
}
}

View File

@ -0,0 +1,52 @@
package com.volmit.iris.gen.v2.scaffold.stream;
import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
import com.volmit.iris.noise.CNG;
public class CNGStream extends BasicLayer implements ProceduralStream<Double>
{
private final CNG cng;
public CNGStream(CNG cng)
{
this.cng = cng;
}
public CNGStream(CNG cng, double zoom, double offsetX, double offsetY, double offsetZ)
{
super(1337, zoom, offsetX, offsetY, offsetZ);
this.cng = cng;
}
public CNGStream(CNG cng, double zoom)
{
super(1337, zoom);
this.cng = cng;
}
@Override
public double toDouble(Double t)
{
return t;
}
@Override
public Double fromDouble(double d)
{
return d;
}
@Override
public Double get(double x, double z)
{
return cng.noise((x + getOffsetX()) / getZoom(), (z + getOffsetZ()) / getZoom());
}
@Override
public Double get(double x, double y, double z)
{
return cng.noise((x + getOffsetX()) / getZoom(), (y + getOffsetY()) / getZoom(), (z + getOffsetZ()) * getZoom());
}
}

View File

@ -0,0 +1,46 @@
package com.volmit.iris.gen.v2.scaffold.stream;
import java.util.function.Function;
import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
import com.volmit.iris.util.KMap;
public class CachedConversionStream<T, V> extends BasicLayer implements ProceduralStream<V>
{
private final ProceduralStream<T> stream;
private final Function<T, V> converter;
private final KMap<T, V> cache;
public CachedConversionStream(ProceduralStream<T> stream, Function<T, V> converter)
{
super();
this.stream = stream;
this.converter = converter;
cache = new KMap<>();
}
@Override
public double toDouble(V t)
{
return 0;
}
@Override
public V fromDouble(double d)
{
return null;
}
@Override
public V get(double x, double z)
{
return cache.compute(stream.get(x, z), (k, v) -> v != null ? v : converter.apply(k));
}
@Override
public V get(double x, double y, double z)
{
return cache.compute(stream.get(x, y, z), (k, v) -> v != null ? v : converter.apply(k));
}
}

View File

@ -0,0 +1,49 @@
package com.volmit.iris.gen.v2.scaffold.stream;
import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
public class ClampedStream<T> extends BasicLayer implements ProceduralStream<T>
{
private final ProceduralStream<T> stream;
private final double min;
private final double max;
public ClampedStream(ProceduralStream<T> stream, double min, double max)
{
super();
this.stream = stream;
this.min = min;
this.max = max;
}
@Override
public double toDouble(T t)
{
return stream.toDouble(t);
}
@Override
public T fromDouble(double d)
{
return stream.fromDouble(d);
}
private double clamp(double v)
{
return Math.max(Math.min(v, max), min);
}
@Override
public T get(double x, double z)
{
return fromDouble(clamp(stream.getDouble(x, z)));
}
@Override
public T get(double x, double y, double z)
{
return fromDouble(clamp(stream.getDouble(x, y, z)));
}
}

View File

@ -0,0 +1,43 @@
package com.volmit.iris.gen.v2.scaffold.stream;
import java.util.function.Function;
import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
public class ConversionStream<T, V> extends BasicLayer implements ProceduralStream<V>
{
private final ProceduralStream<T> stream;
private final Function<T, V> converter;
public ConversionStream(ProceduralStream<T> stream, Function<T, V> converter)
{
super();
this.stream = stream;
this.converter = converter;
}
@Override
public double toDouble(V t)
{
return 0;
}
@Override
public V fromDouble(double d)
{
return null;
}
@Override
public V get(double x, double z)
{
return converter.apply(stream.get(x, z));
}
@Override
public V get(double x, double y, double z)
{
return converter.apply(stream.get(x, y, z));
}
}

View File

@ -0,0 +1,58 @@
package com.volmit.iris.gen.v2.scaffold.stream;
import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
public class FittedStream<T> extends BasicLayer implements ProceduralStream<T>
{
private final ProceduralStream<T> stream;
private final double min;
private final double max;
private final double inMin;
private final double inMax;
public FittedStream(ProceduralStream<T> stream, double inMin, double inMax, double min, double max)
{
super();
this.stream = stream;
this.inMin = inMin;
this.inMax = inMax;
this.min = min;
this.max = max;
}
public FittedStream(ProceduralStream<T> stream, double min, double max)
{
this(stream, 0, 1, min, max);
}
@Override
public double toDouble(T t)
{
return stream.toDouble(t);
}
@Override
public T fromDouble(double d)
{
return stream.fromDouble(d);
}
private double dlerp(double v)
{
return min + ((max - min) * ((v - inMin) / (inMax - inMin)));
}
@Override
public T get(double x, double z)
{
return fromDouble(dlerp(stream.getDouble(x, z)));
}
@Override
public T get(double x, double y, double z)
{
return fromDouble(dlerp(stream.getDouble(x, y, z)));
}
}

View File

@ -0,0 +1,20 @@
package com.volmit.iris.gen.v2.scaffold.stream;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
public interface Interpolated<T>
{
public double toDouble(T t);
public T fromDouble(double d);
default InterpolatorFactory<T> interpolate()
{
if(this instanceof ProceduralStream)
{
return new InterpolatorFactory<T>((ProceduralStream<T>) this);
}
return null;
}
}

View File

@ -0,0 +1,17 @@
package com.volmit.iris.gen.v2.scaffold.stream;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
public interface Interpolator<T>
{
@SuppressWarnings("unchecked")
default InterpolatorFactory<T> into()
{
if(this instanceof ProceduralStream)
{
return new InterpolatorFactory<T>((ProceduralStream<T>) this);
}
return null;
}
}

View File

@ -0,0 +1,73 @@
package com.volmit.iris.gen.v2.scaffold.stream;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
public class InterpolatorFactory<T>
{
private final ProceduralStream<T> stream;
public InterpolatorFactory(ProceduralStream<T> stream)
{
this.stream = stream;
}
public BicubicStream<T> bicubic(int rx, int ry)
{
return new BicubicStream<>(stream, rx, ry);
}
public BicubicStream<T> bicubic(int r)
{
return bicubic(r, r);
}
public BilinearStream<T> bilinear(int rx, int ry)
{
return new BilinearStream<>(stream, rx, ry);
}
public BilinearStream<T> bilinear(int r)
{
return bilinear(r, r);
}
public StarcastStream<T> starcast(int radius, int checks)
{
return new StarcastStream<>(stream, radius, checks);
}
public StarcastStream<T> starcast3(int radius)
{
return starcast(radius, 3);
}
public StarcastStream<T> starcast6(int radius)
{
return starcast(radius, 6);
}
public StarcastStream<T> starcast9(int radius)
{
return starcast(radius, 9);
}
public BiHermiteStream<T> bihermite(int rx, int ry, double tension, double bias)
{
return new BiHermiteStream<>(stream, rx, ry, tension, bias);
}
public BiHermiteStream<T> bihermite(int rx, int ry)
{
return new BiHermiteStream<>(stream, rx, ry);
}
public BiHermiteStream<T> bihermite(int r)
{
return bihermite(r, r);
}
public BiHermiteStream<T> bihermite(int r, double tension, double bias)
{
return bihermite(r, r, tension, bias);
}
}

View File

@ -0,0 +1,46 @@
package com.volmit.iris.gen.v2.scaffold.stream;
import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
public class OffsetStream<T> extends BasicLayer implements ProceduralStream<T>
{
private final ProceduralStream<T> stream;
private final double ox;
private final double oy;
private final double oz;
public OffsetStream(ProceduralStream<T> stream, double x, double y, double z)
{
super();
this.stream = stream;
this.ox = x;
this.oy = y;
this.oz = z;
}
@Override
public double toDouble(T t)
{
return stream.toDouble(t);
}
@Override
public T fromDouble(double d)
{
return stream.fromDouble(d);
}
@Override
public T get(double x, double z)
{
return stream.get(x + ox, z + oz);
}
@Override
public T get(double x, double y, double z)
{
return stream.get(x + ox, y + oy, z + oz);
}
}

View File

@ -0,0 +1,45 @@
package com.volmit.iris.gen.v2.scaffold.stream;
import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
public class RoundingStream extends BasicLayer implements ProceduralStream<Integer>
{
private final ProceduralStream<?> stream;
public RoundingStream(ProceduralStream<?> stream)
{
super();
this.stream = stream;
}
@Override
public double toDouble(Integer t)
{
return t.doubleValue();
}
@Override
public Integer fromDouble(double d)
{
return (int) Math.round(d);
}
private int round(double v)
{
return (int) Math.round(v);
}
@Override
public Integer get(double x, double z)
{
return round(stream.getDouble(x, z));
}
@Override
public Integer get(double x, double y, double z)
{
return round(stream.getDouble(x, y, z));
}
}

View File

@ -0,0 +1,50 @@
package com.volmit.iris.gen.v2.scaffold.stream;
import java.util.List;
import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
public class SelectionStream<T> extends BasicLayer implements ProceduralStream<T>
{
private final ProceduralStream<Integer> stream;
private final T[] options;
public SelectionStream(ProceduralStream<?> stream, T[] options)
{
super();
this.stream = stream.fit(0, options.length - 1).round();
this.options = options;
}
@SuppressWarnings("unchecked")
public SelectionStream(ProceduralStream<?> stream, List<T> options)
{
this(stream, (T[]) options.toArray());
}
@Override
public double toDouble(T t)
{
throw new UnsupportedOperationException();
}
@Override
public T fromDouble(double d)
{
throw new UnsupportedOperationException();
}
@Override
public T get(double x, double z)
{
return options[stream.get(x, z)];
}
@Override
public T get(double x, double y, double z)
{
return options[stream.get(x, y, z)];
}
}

View File

@ -0,0 +1,59 @@
package com.volmit.iris.gen.v2.scaffold.stream;
import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
public class StarcastStream<T> extends BasicLayer implements ProceduralStream<T>, Interpolator<T>
{
private ProceduralStream<T> stream;
private int rad;
private int checks;
public StarcastStream(ProceduralStream<T> stream, int rad, int checks)
{
this.stream = stream;
this.rad = rad;
this.checks = checks;
}
public T interpolate(double x, double y)
{
double m = (360 / checks);
double v = 0;
for(int i = 0; i < 360; i += m)
{
double sin = Math.sin(Math.toRadians(i));
double cos = Math.cos(Math.toRadians(i));
double cx = x + ((rad * cos) - (rad * sin));
double cz = y + ((rad * sin) + (rad * cos));
v += stream.getDouble(cx, cz);
}
return stream.fromDouble(v / checks);
}
@Override
public double toDouble(T t)
{
return stream.toDouble(t);
}
@Override
public T fromDouble(double d)
{
return stream.fromDouble(d);
}
@Override
public T get(double x, double z)
{
return interpolate(x, z);
}
@Override
public T get(double x, double y, double z)
{
return interpolate(x, z);
}
}

View File

@ -0,0 +1,46 @@
package com.volmit.iris.gen.v2.scaffold.stream;
import com.volmit.iris.gen.v2.scaffold.layer.BasicLayer;
import com.volmit.iris.gen.v2.scaffold.layer.ProceduralStream;
public class ZoomStream<T> extends BasicLayer implements ProceduralStream<T>
{
private final ProceduralStream<T> stream;
private final double ox;
private final double oy;
private final double oz;
public ZoomStream(ProceduralStream<T> stream, double x, double y, double z)
{
super();
this.stream = stream;
this.ox = x;
this.oy = y;
this.oz = z;
}
@Override
public double toDouble(T t)
{
return stream.toDouble(t);
}
@Override
public T fromDouble(double d)
{
return stream.fromDouble(d);
}
@Override
public T get(double x, double z)
{
return stream.get(x / ox, z / oz);
}
@Override
public T get(double x, double y, double z)
{
return stream.get(x / ox, y / oy, z / oz);
}
}