This commit is contained in:
Daniel Mills
2021-01-08 10:12:10 -05:00
parent 3f9288c60f
commit 4b76b592d3
9 changed files with 252 additions and 20 deletions

View File

@@ -0,0 +1,46 @@
package com.volmit.iris.util;
public class AlignedPoint
{
private double x;
private double y;
private double z;
public AlignedPoint(double x, double y, double z)
{
this.x = x;
this.y = y;
this.z = z;
}
public double getX()
{
return x;
}
public void setX(double x)
{
this.x = x;
}
public double getY()
{
return y;
}
public void setY(double y)
{
this.y = y;
}
public double getZ()
{
return z;
}
public void setZ(double z)
{
this.z = z;
}
}

View File

@@ -0,0 +1,68 @@
package com.volmit.iris.util;
import com.volmit.iris.object.IrisPosition;
public class AxisAlignedBB
{
private double xa;
private double xb;
private double ya;
private double yb;
private double za;
private double zb;
public AxisAlignedBB(double xa, double xb, double ya, double yb, double za, double zb)
{
this.xa = xa;
this.xb = xb;
this.ya = ya;
this.yb = yb;
this.za = za;
this.zb = zb;
}
public AxisAlignedBB shifted(IrisPosition p)
{
return shifted(p.getX(), p.getY(), p.getZ());
}
public AxisAlignedBB shifted(double x, double y, double z)
{
return new AxisAlignedBB(min().add(new IrisPosition((int)x,(int)y,(int)z)), max().add(new IrisPosition((int)x,(int)y,(int)z)));
}
public AxisAlignedBB(AlignedPoint a, AlignedPoint b)
{
this(a.getX(), b.getX(), a.getY(), b.getY(), a.getZ(), b.getZ());
}
public AxisAlignedBB(IrisPosition a, IrisPosition b)
{
this(a.getX(), b.getX(), a.getY(), b.getY(), a.getZ(), b.getZ());
}
public boolean contains(AlignedPoint p)
{
return p.getX() >= xa && p.getX() <= xb && p.getY() >= ya && p.getZ() <= yb && p.getZ() >= za && p.getZ() <= zb;
}
public boolean contains(IrisPosition p)
{
return p.getX() >= xa && p.getX() <= xb && p.getY() >= ya && p.getZ() <= yb && p.getZ() >= za && p.getZ() <= zb;
}
public boolean intersects(AxisAlignedBB s)
{
return this.xb >= s.xa && this.yb >= s.ya && this.zb >= s.za && s.xb >= this.xa && s.yb >= this.ya && s.zb >= this.za;
}
public IrisPosition max()
{
return new IrisPosition((int)xb, (int)yb, (int)zb);
}
public IrisPosition min()
{
return new IrisPosition((int)xa, (int)ya, (int)za);
}
}

View File

@@ -4,6 +4,7 @@ import com.google.common.util.concurrent.AtomicDoubleArray;
import java.util.*;
import java.util.function.Function;
import java.util.function.Predicate;
public class KList<T> extends ArrayList<T> implements List<T>
{
@@ -213,6 +214,13 @@ public class KList<T> extends ArrayList<T> implements List<T>
return this;
}
public KList<T> shuffle(Random rng)
{
Collections.shuffle(this, rng);
return this;
}
/**
* Sort the list (based on toString comparison)
*
@@ -314,6 +322,19 @@ public class KList<T> extends ArrayList<T> implements List<T>
return v;
}
public KList<T> removeWhere(Predicate<T> t)
{
for(T i : copy())
{
if(t.test(i))
{
remove(i);
}
}
return this;
}
/**
* Adds T to the list, ignores if null
*
@@ -730,4 +751,10 @@ public class KList<T> extends ArrayList<T> implements List<T>
}
}
}
public KList<T> shuffleCopy(Random rng) {
KList<T> t = copy();
t.shuffle(rng);
return t;
}
}

View File

@@ -1,6 +1,7 @@
package com.volmit.iris.util;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Random;
import java.util.UUID;
@@ -177,4 +178,18 @@ public class RNG extends Random
public boolean chance(double chance) {
return chance >= nextDouble();
}
public <T> T pick(List<T> pieces) {
if(pieces.isEmpty())
{
return null;
}
if(pieces.size() == 1)
{
return pieces.get(0);
}
return pieces.get(nextInt(pieces.size()));
}
}