From 6cfd055becbde4aff9032bdf8054c8367e00d1af Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Mon, 19 Jul 2021 04:21:22 -0400 Subject: [PATCH] Pos utils --- .../com/volmit/iris/util/math/Position2.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/java/com/volmit/iris/util/math/Position2.java b/src/main/java/com/volmit/iris/util/math/Position2.java index 94be84e6e..4b1704145 100644 --- a/src/main/java/com/volmit/iris/util/math/Position2.java +++ b/src/main/java/com/volmit/iris/util/math/Position2.java @@ -52,6 +52,26 @@ public class Position2 { return result; } + public Position2 topLeftChunkOfRegion() + { + return new Position2((x >> 5) << 5, (z >> 5) << 5); + } + + public Position2 bottomRightChunkOfRegion() + { + return new Position2((((x >> 5)+1) << 5) - 1, (((z >> 5)+1) << 5) - 1); + } + + public Position2 topRightChunkOfRegion() + { + return new Position2((((x >> 5)+1) << 5) - 1, (z >> 5) << 5); + } + + public Position2 bottomLeftChunkOfRegion() + { + return new Position2((x >> 5) << 5, (((z >> 5)+1) << 5) - 1); + } + @Override public boolean equals(Object obj) { if (this == obj) { @@ -66,4 +86,8 @@ public class Position2 { public double distance(Position2 center) { return Math.pow(center.getX() - x, 2) + Math.pow(center.getZ() - z, 2); } + + public Position2 add(int x, int z) { + return new Position2(this.x + x, this.z + z); + } }