]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/commitdiff
Change Sphere center to use Point not Coords and Offsets
authorIrtimaled <irtimaled@gmail.com>
Sun, 10 May 2020 16:42:50 +0000 (09:42 -0700)
committerIrtimaled <irtimaled@gmail.com>
Mon, 18 May 2020 00:31:27 +0000 (17:31 -0700)
15 files changed:
src/main/java/com/irtimaled/bbor/client/Player.java
src/main/java/com/irtimaled/bbor/client/interop/SpawningSphereHelper.java
src/main/java/com/irtimaled/bbor/client/models/BoundingBoxConduit.java
src/main/java/com/irtimaled/bbor/client/models/BoundingBoxSpawningSphere.java
src/main/java/com/irtimaled/bbor/client/models/Point.java [deleted file]
src/main/java/com/irtimaled/bbor/client/providers/SpawningSphereProvider.java
src/main/java/com/irtimaled/bbor/client/renderers/ConduitRenderer.java
src/main/java/com/irtimaled/bbor/client/renderers/OffsetBox.java
src/main/java/com/irtimaled/bbor/client/renderers/OffsetPoint.java
src/main/java/com/irtimaled/bbor/client/renderers/SpawningSphereRenderer.java
src/main/java/com/irtimaled/bbor/client/renderers/VillageRenderer.java
src/main/java/com/irtimaled/bbor/common/messages/BoundingBoxSerializer.java
src/main/java/com/irtimaled/bbor/common/models/BoundingBoxSphere.java
src/main/java/com/irtimaled/bbor/common/models/BoundingBoxVillage.java
src/main/java/com/irtimaled/bbor/common/models/Point.java [new file with mode: 0644]

index 33e714e1fa2834ab7bddbd76ed93c198a4447472..1085a22c580ccc8153ba72b7377b8d52e374264b 100644 (file)
@@ -1,6 +1,7 @@
 package com.irtimaled.bbor.client;
 
 import com.irtimaled.bbor.common.models.Coords;
+import com.irtimaled.bbor.common.models.Point;
 import net.minecraft.entity.player.EntityPlayer;
 
 public class Player {
@@ -50,4 +51,8 @@ public class Player {
     public static Coords getCoords() {
         return new Coords(x, y, z);
     }
+
+    public static Point getPoint() {
+        return new Point(x, y, z);
+    }
 }
index b937f21315e6532cd5587351e7879aae6bd531fe..9485450dcfd15dcfe05b11a37218701f661211df 100644 (file)
@@ -1,8 +1,8 @@
 package com.irtimaled.bbor.client.interop;
 
 import com.irtimaled.bbor.client.models.BoundingBoxSpawningSphere;
-import com.irtimaled.bbor.client.models.Point;
 import com.irtimaled.bbor.common.models.Coords;
+import com.irtimaled.bbor.common.models.Point;
 import net.minecraft.block.Block;
 import net.minecraft.block.state.IBlockState;
 import net.minecraft.client.Minecraft;
index 3407e26d0a9b85a006fed601e96e08c3539c74cb..a894843393108ac111edd9cb4225e1a000e47653 100644 (file)
@@ -4,13 +4,13 @@ import com.irtimaled.bbor.common.BoundingBoxType;
 import com.irtimaled.bbor.common.TypeHelper;
 import com.irtimaled.bbor.common.models.BoundingBoxSphere;
 import com.irtimaled.bbor.common.models.Coords;
+import com.irtimaled.bbor.common.models.Point;
 
 public class BoundingBoxConduit extends BoundingBoxSphere {
     private final int level;
 
     private BoundingBoxConduit(Coords coords, int level, int radius) {
-        super(coords, radius, BoundingBoxType.Conduit);
-        setCenterOffsets(0.5, 0.5, 0.5);
+        super(new Point(coords).offset(0.5D, 0.5D, 0.5D), radius, BoundingBoxType.Conduit);
 
         this.level = level;
     }
@@ -22,7 +22,7 @@ public class BoundingBoxConduit extends BoundingBoxSphere {
 
     @Override
     public int hashCode() {
-        return TypeHelper.combineHashCodes(getType().hashCode(), getCenter().hashCode());
+        return TypeHelper.combineHashCodes(getType().hashCode(), getPoint().hashCode());
     }
 
     @Override
@@ -30,7 +30,7 @@ public class BoundingBoxConduit extends BoundingBoxSphere {
         if (this == obj) return true;
         if (obj == null || getClass() != obj.getClass()) return false;
         BoundingBoxConduit other = (BoundingBoxConduit) obj;
-        return getCenter().equals(other.getCenter());
+        return getPoint().equals(other.getPoint());
     }
 
     public int getLevel() {
index dd5c76ad20f45d3d263189bbd31070a2bcc2ec78..8229e97b10164d5ff5b4e27563b7178558be44c3 100644 (file)
@@ -2,7 +2,7 @@ package com.irtimaled.bbor.client.models;
 
 import com.irtimaled.bbor.common.BoundingBoxType;
 import com.irtimaled.bbor.common.models.BoundingBoxSphere;
-import com.irtimaled.bbor.common.models.Coords;
+import com.irtimaled.bbor.common.models.Point;
 
 public class BoundingBoxSpawningSphere extends BoundingBoxSphere {
     public static final int SAFE_RADIUS = 24;
@@ -10,16 +10,8 @@ public class BoundingBoxSpawningSphere extends BoundingBoxSphere {
 
     private Integer spawnableCount;
 
-    public BoundingBoxSpawningSphere(Coords coords, double xOffset, double yOffset, double zOffset) {
-        super(coords, 128, BoundingBoxType.AFKSphere);
-        setCenterOffsets(xOffset, yOffset, zOffset);
-    }
-
-    public boolean isCenter(Coords coords, double xOffset, double yOffset, double zOffset) {
-        return this.getCenter().equals(coords) &&
-                this.getCenterOffsetX() == xOffset &&
-                this.getCenterOffsetY() == yOffset &&
-                this.getCenterOffsetZ() == zOffset;
+    public BoundingBoxSpawningSphere(Point point) {
+        super(point, SPAWN_RADIUS, BoundingBoxType.AFKSphere);
     }
 
     public void setSpawnableCount(int count) {
diff --git a/src/main/java/com/irtimaled/bbor/client/models/Point.java b/src/main/java/com/irtimaled/bbor/client/models/Point.java
deleted file mode 100644 (file)
index d9b8928..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.irtimaled.bbor.client.models;
-
-import com.irtimaled.bbor.common.models.Coords;
-
-public class Point {
-    private final double x;
-    private final double y;
-    private final double z;
-
-    public Point(double x, double y, double z) {
-        this.x = x;
-        this.y = y;
-        this.z = z;
-    }
-
-    public Point(Coords Coords) {
-        this.x = Coords.getX();
-        this.y = Coords.getY();
-        this.z = Coords.getZ();
-    }
-
-    public double getX() {
-        return x;
-    }
-
-    public double getY() {
-        return y;
-    }
-
-    public double getZ() {
-        return z;
-    }
-
-    public Point offset(double x, double y, double z) {
-        return new Point(this.x + x, this.y + y, this.z + z);
-    }
-
-    public double getDistance(Point point) {
-        double dx = this.x - point.x;
-        double dy = this.y - point.y;
-        double dz = this.z - point.z;
-        return Math.sqrt(dx * dx + dy * dy + dz * dz);
-    }
-
-    public Coords getCoords() {
-        return new Coords(x, y, z);
-    }
-}
index 1b2c92b882468200d1bb2b7b7131de11ee6edc3f..1efd41ebf023b0a09077f2aa5729c507b93d6a0c 100644 (file)
@@ -4,10 +4,9 @@ import com.irtimaled.bbor.client.Player;
 import com.irtimaled.bbor.client.config.BoundingBoxTypeHelper;
 import com.irtimaled.bbor.client.interop.SpawningSphereHelper;
 import com.irtimaled.bbor.client.models.BoundingBoxSpawningSphere;
-import com.irtimaled.bbor.client.models.Point;
 import com.irtimaled.bbor.common.BoundingBoxType;
 import com.irtimaled.bbor.common.MathHelper;
-import com.irtimaled.bbor.common.models.Coords;
+import com.irtimaled.bbor.common.models.Point;
 
 import java.util.HashSet;
 import java.util.Set;
@@ -17,24 +16,22 @@ public class SpawningSphereProvider implements IBoundingBoxProvider<BoundingBoxS
     private static Integer dimensionId;
 
     public static void setSphere(double x, double y, double z) {
-        Coords coords = new Coords(x, y, z);
-        double xOffset = snapToNearestHalf(x -coords.getX());
-        double yOffset = y- coords.getY();
-        double zOffset = snapToNearestHalf(z-coords.getZ());
+        Point point = new Point(snapToNearestHalf(x), y, snapToNearestHalf(z));
 
-        if(spawningSphere != null && spawningSphere.isCenter(coords, xOffset, yOffset, zOffset)) {
+        if (spawningSphere != null && spawningSphere.getPoint().equals(point)) {
             return;
         }
         clear();
 
         dimensionId = Player.getDimensionId();
-        spawningSphere = new BoundingBoxSpawningSphere(coords, xOffset, yOffset, zOffset);
+        spawningSphere = new BoundingBoxSpawningSphere(point);
     }
 
     private static double snapToNearestHalf(double value) {
-        int floor = MathHelper.floor(value * 4.0);
-        if(floor % 2 == 1) floor += 1;
-        return floor / 4.0;
+        int floor = MathHelper.floor(value);
+        int fraction = MathHelper.floor((value - floor) * 4.0);
+        if (fraction % 2 == 1) fraction++;
+        return floor + (fraction / 4.0);
     }
 
     public static boolean clear() {
@@ -48,10 +45,7 @@ public class SpawningSphereProvider implements IBoundingBoxProvider<BoundingBoxS
 
     public static int recalculateSpawnableSpacesCount() {
         if (spawningSphere != null) {
-            Point sphereCenter = new Point(spawningSphere.getCenter())
-                    .offset(spawningSphere.getCenterOffsetX(),
-                            spawningSphere.getCenterOffsetY(),
-                            spawningSphere.getCenterOffsetZ());
+            Point sphereCenter = spawningSphere.getPoint();
             int spawnableSpacesCount = getSpawnableSpacesCount(sphereCenter);
             spawningSphere.setSpawnableCount(spawnableSpacesCount);
             return spawnableSpacesCount;
index a5b5ec2c311c5ccbb80ec2d9d718933b7269885b..bd510785d3ccc7c4e7f5dd43abe95e5800e00296 100644 (file)
@@ -3,26 +3,25 @@ package com.irtimaled.bbor.client.renderers;
 import com.irtimaled.bbor.client.config.ConfigManager;
 import com.irtimaled.bbor.client.models.BoundingBoxConduit;
 import com.irtimaled.bbor.common.models.Colors;
-import com.irtimaled.bbor.common.models.Coords;
+import com.irtimaled.bbor.common.models.Point;
 
 import java.awt.*;
 
 public class ConduitRenderer extends AbstractRenderer<BoundingBoxConduit> {
     @Override
     public void render(BoundingBoxConduit boundingBox) {
-        Coords center = boundingBox.getCenter();
         int level = boundingBox.getLevel();
         Color color = boundingBox.getColor();
+        Point point = boundingBox.getPoint();
 
-        renderCuboid(new OffsetBox(center, center), color);
+        OffsetPoint center = new OffsetPoint(point);
+        OffsetBox centerBox = new OffsetBox(center, center).grow(0.5, 0.5, 0.5);
+        renderCuboid(centerBox, color);
         if (level == 6 && ConfigManager.renderConduitMobHarmArea.get()) {
-            renderCuboid(new OffsetBox(center, center).grow(8, 8, 8), Colors.DARK_ORANGE);
+            renderCuboid(centerBox.grow(8, 8, 8), Colors.DARK_ORANGE);
         }
         if (level != 0) {
-            OffsetPoint sphereCenter = new OffsetPoint(center)
-                    .offset(boundingBox.getCenterOffsetX(), boundingBox.getCenterOffsetY(), boundingBox.getCenterOffsetZ());
-
-            renderSphere(sphereCenter, boundingBox.getRadius() + 0.5, color, 5, 5);
+            renderSphere(center, boundingBox.getRadius() + 0.5, color, 5, 5);
         }
     }
 }
index b629532a04bd1656d5f2a473f7cd7ef785595558..e2f1050e462a505465f8549f909bcf13ef9120af 100644 (file)
@@ -25,14 +25,10 @@ class OffsetBox {
         return new OffsetBox(min.offset(-x, -y, -z), max.offset(x, y, z));
     }
 
-    OffsetBox offset(double x, double y, double z) {
-        return new OffsetBox(min.offset(x, y, z), max.offset(x, y, z));
-    }
-
     OffsetBox nudge() {
         double growXZ = 0.001F;
         if (min.getY() == max.getY()) {
-            return grow(growXZ, 0, growXZ).offset(0, growXZ, 0);
+            return new OffsetBox(min.offset(-growXZ, growXZ, -growXZ), max.offset(growXZ, growXZ, growXZ));
         }
         return grow(growXZ, growXZ, growXZ);
     }
index f841a987667f5c6339bebb6d5e977e82000a66b4..8235343c347bff6837d5702b7634c0332976b8ae 100644 (file)
@@ -1,8 +1,8 @@
 package com.irtimaled.bbor.client.renderers;
 
 import com.irtimaled.bbor.client.Player;
-import com.irtimaled.bbor.client.models.Point;
 import com.irtimaled.bbor.common.models.Coords;
+import com.irtimaled.bbor.common.models.Point;
 
 class OffsetPoint {
     private final Point point;
@@ -15,7 +15,7 @@ class OffsetPoint {
         this(new Point(coords));
     }
 
-    private OffsetPoint(Point point) {
+    OffsetPoint(Point point) {
         this.point = point;
     }
 
@@ -38,8 +38,4 @@ class OffsetPoint {
     double getDistance(OffsetPoint offsetPoint) {
         return this.point.getDistance(offsetPoint.point);
     }
-
-    Point getPoint() {
-        return this.point;
-    }
 }
index dc4233149ddc1d3d6b0269bc5f6e7c63ef9a0f8b..ff5749c03bbe1c78f83d5920f6d63c2852bbb658 100644 (file)
@@ -5,6 +5,7 @@ import com.irtimaled.bbor.client.config.ConfigManager;
 import com.irtimaled.bbor.client.interop.SpawningSphereHelper;
 import com.irtimaled.bbor.client.models.BoundingBoxSpawningSphere;
 import com.irtimaled.bbor.common.MathHelper;
+import com.irtimaled.bbor.common.models.Point;
 import net.minecraft.client.resources.I18n;
 
 import java.awt.*;
@@ -12,8 +13,8 @@ import java.awt.*;
 public class SpawningSphereRenderer extends AbstractRenderer<BoundingBoxSpawningSphere> {
     @Override
     public void render(BoundingBoxSpawningSphere boundingBox) {
-        OffsetPoint sphereCenter = new OffsetPoint(boundingBox.getCenter())
-                .offset(boundingBox.getCenterOffsetX(), boundingBox.getCenterOffsetY(), boundingBox.getCenterOffsetZ());
+        Point point = boundingBox.getPoint();
+        OffsetPoint sphereCenter = new OffsetPoint(point);
 
         OffsetBox offsetBox = new OffsetBox(sphereCenter, sphereCenter).grow(0.5, 0, 0.5);
         renderCuboid(offsetBox, Color.GREEN);
@@ -30,16 +31,16 @@ public class SpawningSphereRenderer extends AbstractRenderer<BoundingBoxSpawning
         renderSphere(sphereCenter, BoundingBoxSpawningSphere.SPAWN_RADIUS, Color.RED, 5, 5);
 
         if(ConfigManager.renderAFKSpawnableBlocks.get()) {
-            renderSpawnableSpaces(sphereCenter);
+            renderSpawnableSpaces(point);
         }
     }
 
-    private void renderSpawnableSpaces(OffsetPoint center) {
+    private void renderSpawnableSpaces(Point center) {
         Integer renderDistance = ConfigManager.afkSpawnableBlocksRenderDistance.get();
         int width = MathHelper.floor(Math.pow(2, 2 + renderDistance));
         int height = MathHelper.floor(Math.pow(2, renderDistance));
 
-        SpawningSphereHelper.findSpawnableSpaces(center.getPoint(), Player.getCoords(), width, height,
+        SpawningSphereHelper.findSpawnableSpaces(center, Player.getCoords(), width, height,
                 (x, y, z) -> {
                     OffsetBox offsetBox = new OffsetBox(x, y, z, x + 1, y, z + 1);
                     renderCuboid(offsetBox, Color.RED);
index 900943c4012f51d3719ccabe7a713ae5a391a97b..62e5c2917a54ba5391e7b0565dedfa699ab1824e 100644 (file)
@@ -21,8 +21,7 @@ public class VillageRenderer extends AbstractRenderer<BoundingBoxVillage> {
     }
 
     private void renderIronGolemSpawnArea(BoundingBoxVillage boundingBox) {
-        OffsetPoint offsetCenter = new OffsetPoint(boundingBox.getCenter())
-                .offset(boundingBox.getCenterOffsetX(), 0.0, boundingBox.getCenterOffsetZ());
+        OffsetPoint offsetCenter = new OffsetPoint(boundingBox.getPoint());
         OffsetBox bb = new OffsetBox(offsetCenter, offsetCenter)
                 .grow(8, 3, 8);
 
@@ -30,8 +29,7 @@ public class VillageRenderer extends AbstractRenderer<BoundingBoxVillage> {
     }
 
     private void renderVillageDoors(BoundingBoxVillage boundingBox) {
-        OffsetPoint center = new OffsetPoint(boundingBox.getCenter())
-                .offset(boundingBox.getCenterOffsetX(), 0.0, boundingBox.getCenterOffsetZ());
+        OffsetPoint center = new OffsetPoint(boundingBox.getPoint());
         Color color = boundingBox.getColor();
 
         GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
@@ -47,9 +45,8 @@ public class VillageRenderer extends AbstractRenderer<BoundingBoxVillage> {
     }
 
     private void renderBoundingBoxVillageAsSphere(BoundingBoxVillage boundingBox) {
-        OffsetPoint center = new OffsetPoint(boundingBox.getCenter())
-                .offset(boundingBox.getCenterOffsetX(), 0.0, boundingBox.getCenterOffsetZ());
-        int radius = boundingBox.getRadius();
+        OffsetPoint center = new OffsetPoint(boundingBox.getPoint());
+        double radius = boundingBox.getRadius();
         Color color = boundingBox.getColor();
         int density = ConfigManager.villageSphereDensity.get();
         int dotSize = ConfigManager.villageSphereDotSize.get();
index 7fdce4220af2c848a867f8efe94826161f4b548b..d4c41d1bd8c9869a4bb31c59a395ad2d2051d82e 100644 (file)
@@ -31,7 +31,7 @@ class BoundingBoxSerializer {
     private static void serializeVillage(BoundingBoxVillage boundingBox, PayloadBuilder builder) {
         builder.writeChar('V')
                 .writeCoords(boundingBox.getCenter())
-                .writeVarInt(boundingBox.getRadius())
+                .writeVarInt((int)boundingBox.getRadius())
                 .writeBoolean(boundingBox.getSpawnsIronGolems())
                 .writeVarInt(boundingBox.getColor().getRGB());
         for (Coords door : boundingBox.getDoors()) {
index b51edd7b9234b04fb511735f7e9a94949dac19c7..9c08b1fad94f4748e45e1165eabee639a1227e7c 100644 (file)
@@ -3,22 +3,19 @@ package com.irtimaled.bbor.common.models;
 import com.irtimaled.bbor.common.BoundingBoxType;
 
 public class BoundingBoxSphere extends AbstractBoundingBox {
-    private final Coords center;
-    private final Integer radius;
-    private final int minX;
-    private final int minZ;
-    private final int maxX;
-    private final int maxZ;
-
-    private Double centerOffsetX = 0d;
-    private Double centerOffsetY = 0d;
-    private Double centerOffsetZ = 0d;
-
-    protected BoundingBoxSphere(Coords center, Integer radius, BoundingBoxType type) {
+    private final double radius;
+    private final double minX;
+    private final double minZ;
+    private final double maxX;
+    private final double maxZ;
+    private final Point point;
+
+    protected BoundingBoxSphere(Point point, double radius, BoundingBoxType type) {
         super(type);
-        this.center = center;
         this.radius = radius;
+        this.point = point;
 
+        Coords center = point.getCoords();
         this.minX = center.getX() - radius;
         this.minZ = center.getZ() - radius;
         this.maxX = center.getX() + radius;
@@ -33,29 +30,11 @@ public class BoundingBoxSphere extends AbstractBoundingBox {
                 this.minZ <= maxZ;
     }
 
-    public Integer getRadius() {
+    public double getRadius() {
         return radius;
     }
 
-    public Coords getCenter() {
-        return center;
-    }
-
-    public Double getCenterOffsetX() {
-        return centerOffsetX;
-    }
-
-    public Double getCenterOffsetY() {
-        return centerOffsetY;
-    }
-
-    public Double getCenterOffsetZ() {
-        return centerOffsetZ;
-    }
-
-    public void setCenterOffsets(double x, double y, double z) {
-        this.centerOffsetX = x;
-        this.centerOffsetY = y;
-        this.centerOffsetZ = z;
+    public Point getPoint() {
+        return point;
     }
 }
index 9b2496ba619953d54b6e8367a28a9efa42081139..c2d218077a53c83864c0ac846a6ca77dfd274aa4 100644 (file)
@@ -11,29 +11,31 @@ import java.util.Set;
 public class BoundingBoxVillage extends BoundingBoxSphere {
     private final boolean spawnsIronGolems;
     private final Color color;
+    private final Coords center;
     private final Set<Coords> doors;
     private final int villageHash;
 
-    private BoundingBoxVillage(Coords center, Integer radius, Color color, boolean spawnsIronGolems, Set<Coords> doors) {
-        super(center, radius, BoundingBoxType.VillageSpheres);
+    private BoundingBoxVillage(Point point, Integer radius, Color color, boolean spawnsIronGolems, Set<Coords> doors) {
+        super(point, radius, BoundingBoxType.VillageSpheres);
+        this.center = point.getCoords();
         this.color = color;
         this.spawnsIronGolems = spawnsIronGolems;
         this.doors = doors;
-        this.villageHash = VillageHelper.computeHash(center, radius, spawnsIronGolems, doors);
-        calculateCenterOffsets(doors);
+        this.villageHash = VillageHelper.computeHash(this.center, radius, spawnsIronGolems, doors);
     }
 
     public static BoundingBoxVillage from(Coords center, Integer radius, Color color, boolean spawnsIronGolems, Set<Coords> doors) {
-        return new BoundingBoxVillage(center, radius, color, spawnsIronGolems, doors);
+        Point point = calculateCenterPoint(center, doors);
+        return new BoundingBoxVillage(point, radius, color, spawnsIronGolems, doors);
     }
 
     public static BoundingBoxVillage from(Coords center, Integer radius, int villageId, int population, Set<Coords> doors) {
         boolean spawnsIronGolems = VillageHelper.shouldSpawnIronGolems(population, doors.size());
         Color color = VillageColorCache.getColor(villageId);
-        return new BoundingBoxVillage(center, radius, color, spawnsIronGolems, doors);
+        return from(center, radius, color, spawnsIronGolems, doors);
     }
 
-    private void calculateCenterOffsets(Set<Coords> doors) {
+    private static Point calculateCenterPoint(Coords center, Set<Coords> doors) {
         boolean processedFirstDoor = false;
         int minX = 0;
         int maxX = 0;
@@ -55,7 +57,10 @@ public class BoundingBoxVillage extends BoundingBoxSphere {
 
             processedFirstDoor = true;
         }
-        setCenterOffsets(Math.abs(maxX - minX) % 2 == 0 ? 0.5 : (minX < 0 ? 0 : 1), 0.0d, Math.abs(maxZ - minZ) % 2 == 0 ? 0.5 : (minZ < 0 ? 0 : 1));
+
+        double x = Math.abs(maxX - minX) % 2 == 0 ? 0.5 : (minX < 0 ? 0 : 1);
+        double z = Math.abs(maxZ - minZ) % 2 == 0 ? 0.5 : (minZ < 0 ? 0 : 1);
+        return new Point(center).offset(x, 0.0D, z);
     }
 
     public Color getColor() {
@@ -78,4 +83,8 @@ public class BoundingBoxVillage extends BoundingBoxSphere {
     public int getVillageHash() {
         return villageHash;
     }
+
+    public Coords getCenter() {
+        return center;
+    }
 }
diff --git a/src/main/java/com/irtimaled/bbor/common/models/Point.java b/src/main/java/com/irtimaled/bbor/common/models/Point.java
new file mode 100644 (file)
index 0000000..772bc1d
--- /dev/null
@@ -0,0 +1,61 @@
+package com.irtimaled.bbor.common.models;
+
+import com.irtimaled.bbor.common.TypeHelper;
+
+public class Point {
+    private final double x;
+    private final double y;
+    private final double z;
+
+    public Point(double x, double y, double z) {
+        this.x = x;
+        this.y = y;
+        this.z = z;
+    }
+
+    public Point(Coords Coords) {
+        this.x = Coords.getX();
+        this.y = Coords.getY();
+        this.z = Coords.getZ();
+    }
+
+    public double getX() {
+        return x;
+    }
+
+    public double getY() {
+        return y;
+    }
+
+    public double getZ() {
+        return z;
+    }
+
+    public Point offset(double x, double y, double z) {
+        return new Point(this.x + x, this.y + y, this.z + z);
+    }
+
+    public double getDistance(Point point) {
+        double dx = this.x - point.x;
+        double dy = this.y - point.y;
+        double dz = this.z - point.z;
+        return Math.sqrt(dx * dx + dy * dy + dz * dz);
+    }
+
+    public Coords getCoords() {
+        return new Coords(x, y, z);
+    }
+
+    @Override
+    public int hashCode() {
+        return TypeHelper.combineHashCodes(Double.hashCode(z), Double.hashCode(y), Double.hashCode(x));
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) return true;
+        if (obj == null || getClass() != obj.getClass()) return false;
+        Point point = (Point) obj;
+        return getX() == point.getX() && getY() == point.getY() && getZ() == point.getZ();
+    }
+}