AABBBlock shift and clone methods

This commit is contained in:
Marc Baloup 2022-11-21 15:15:48 +01:00
parent b2cd7e0bda
commit 8755725d51
Signed by: marcbal
GPG Key ID: BBC0FE3ABC30B893

View File

@ -17,7 +17,7 @@ import fr.pandacube.lib.util.RandomUtil;
* Represent the littelest cuboid selection of blocks that contains the bounding box
* passed to the constructor.
*/
public class AABBBlock implements Iterable<BlockVector> {
public class AABBBlock implements Iterable<BlockVector>, Cloneable {
public final Vector pos1, pos2;
@ -25,6 +25,14 @@ public class AABBBlock implements Iterable<BlockVector> {
private final long volume;
private AABBBlock(AABBBlock original, int shiftX, int shiftY, int shiftZ) {
Vector shiftVect = new Vector(shiftX, shiftY, shiftZ);
pos1 = original.pos1.clone().add(shiftVect);
pos2 = original.pos2.clone().add(shiftVect);
center = original.center.clone().add(shiftVect);
volume = original.volume;
}
public AABBBlock(Vector p1, Vector p2) {
this(p1.getBlockX(), p1.getBlockY(), p1.getBlockZ(), p2.getBlockX(), p2.getBlockY(), p2.getBlockZ());
}
@ -56,6 +64,16 @@ public class AABBBlock implements Iterable<BlockVector> {
volume = (long) Math.abs(p2x_ - p1x_) * Math.abs(p2x_ - p1x_) * Math.abs(p2x_ - p1x_);
}
public AABBBlock shift(int x, int y, int z) {
return new AABBBlock(this, x, y, z);
}
@SuppressWarnings("MethodDoesntCallSuperMethod")
@Override
public AABBBlock clone() throws CloneNotSupportedException {
return new AABBBlock(this, 0, 0, 0);
}
public boolean overlaps(Entity e) {
return overlaps(e.getBoundingBox());
}