From 25cb08f541520f05fdb831ee174e35b44fd85283 Mon Sep 17 00:00:00 2001 From: James Seibel Date: Fri, 20 Aug 2021 20:19:05 -0500 Subject: [PATCH] Eclipse auto-formating --- .../java/com/seibel/lod/objects/LevelPos.java | 325 +++++++++--------- 1 file changed, 164 insertions(+), 161 deletions(-) diff --git a/src/main/java/com/seibel/lod/objects/LevelPos.java b/src/main/java/com/seibel/lod/objects/LevelPos.java index cd86a64e7..d38c0e3cc 100644 --- a/src/main/java/com/seibel/lod/objects/LevelPos.java +++ b/src/main/java/com/seibel/lod/objects/LevelPos.java @@ -4,165 +4,168 @@ import com.seibel.lod.util.LodUtil; public class LevelPos implements Cloneable { - public final byte detailLevel; - public final int posX; - public final int posZ; - - public LevelPos(byte detailLevel, int posX, int posZ) - { - this.posX = posX; - this.posZ = posZ; - this.detailLevel = detailLevel; - } - - public LevelPos convert(byte newDetailLevel) - { - if (newDetailLevel >= detailLevel) - { - return new LevelPos( - newDetailLevel, - Math.floorDiv(posX, (int) Math.pow(2, newDetailLevel - detailLevel)), - Math.floorDiv(posZ, (int) Math.pow(2, newDetailLevel - detailLevel))); - } else - { - return new LevelPos( - newDetailLevel, - posX * (int) Math.pow(2, detailLevel - newDetailLevel), - posZ * (int) Math.pow(2, detailLevel - newDetailLevel)); - } - } - - public LevelPos regionModule() - { - return new LevelPos( - detailLevel, - Math.floorMod(posX, (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel)), - Math.floorMod(posZ, (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel))); - } - - public RegionPos getRegionPos() - { - return new RegionPos( - Math.floorDiv(posX, (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel)), - Math.floorDiv(posZ, (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel))); - } - - - public LevelPos clone() - { - return new LevelPos(detailLevel, posX, posZ); - } - - public int maxDistance(int playerPosX, int playerPosZ, int regionPosX, int regionPosZ) - { - int width = (int) Math.pow(2, detailLevel); - - int startPosX = regionPosX * 512 + posX * width; - int startPosZ = regionPosZ * 512 + posZ * width; - int endPosX = startPosX + width; - int endPosZ = startPosZ + width; - - int maxDistance = (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - startPosZ, 2)); - maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - endPosZ, 2))); - maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - startPosZ, 2))); - maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - endPosZ, 2))); - - return maxDistance; - } - - public int maxDistance(int playerPosX, int playerPosZ) - { - int width = (int) Math.pow(2, detailLevel); - - int startPosX = posX * width; - int startPosZ = posZ * width; - int endPosX = startPosX + width; - int endPosZ = startPosZ + width; - - int maxDistance = (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - startPosZ, 2)); - maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - endPosZ, 2))); - maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - startPosZ, 2))); - maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - endPosZ, 2))); - - return maxDistance; - } - - public int minDistance(int playerPosX, int playerPosZ, int regionPosX, int regionPosZ) - { - int width = (int) Math.pow(2, detailLevel); - - int startPosX = regionPosX * 512 + posX * width; - int startPosZ = regionPosZ * 512 + posZ * width; - int endPosX = startPosX + width; - int endPosZ = startPosZ + width; - - boolean inXArea = playerPosX >= startPosX && playerPosX <= endPosX; - boolean inZArea = playerPosZ >= startPosZ && playerPosZ <= endPosZ; - if (inXArea && inZArea) - { - return 0; - } else if (inXArea) - { - return Math.min( - Math.abs(playerPosZ - startPosZ), - Math.abs(playerPosZ - endPosZ) - ); - } else if (inZArea) - { - return Math.min( - Math.abs(playerPosX - startPosX), - Math.abs(playerPosX - endPosX) - ); - } else - { - int minDistance = (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - startPosZ, 2)); - minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - endPosZ, 2))); - minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - startPosZ, 2))); - minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - endPosZ, 2))); - return minDistance; - } - } - - public int minDistance(int playerPosX, int playerPosZ) - { - int width = (int) Math.pow(2, detailLevel); - - int startPosX = posX * width; - int startPosZ = posZ * width; - int endPosX = startPosX + width; - int endPosZ = startPosZ + width; - - boolean inXArea = playerPosX >= startPosX && playerPosX <= endPosX; - boolean inZArea = playerPosZ >= startPosZ && playerPosZ <= endPosZ; - - if (inXArea && inZArea) - { - return 0; - } else if (inXArea) - { - return Math.min( - Math.abs(playerPosZ - startPosZ), - Math.abs(playerPosZ - endPosZ) - ); - } else if (inZArea) - { - return Math.min( - Math.abs(playerPosX - startPosX), - Math.abs(playerPosX - endPosX) - ); - } else - { - int minDistance = (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - startPosZ, 2)); - minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - endPosZ, 2))); - minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - startPosZ, 2))); - minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - endPosZ, 2))); - return minDistance; - } - } - - public String toString() - { - String s = (detailLevel + " " + posX + " " + posZ); - return s; - } + public final byte detailLevel; + public final int posX; + public final int posZ; + + public LevelPos(byte detailLevel, int posX, int posZ) + { + this.posX = posX; + this.posZ = posZ; + this.detailLevel = detailLevel; + } + + public LevelPos convert(byte newDetailLevel) + { + if (newDetailLevel >= detailLevel) + { + return new LevelPos( + newDetailLevel, + Math.floorDiv(posX, (int) Math.pow(2, newDetailLevel - detailLevel)), + Math.floorDiv(posZ, (int) Math.pow(2, newDetailLevel - detailLevel))); + } else + { + return new LevelPos( + newDetailLevel, + posX * (int) Math.pow(2, detailLevel - newDetailLevel), + posZ * (int) Math.pow(2, detailLevel - newDetailLevel)); + } + } + + public LevelPos regionModule() + { + return new LevelPos( + detailLevel, + Math.floorMod(posX, (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel)), + Math.floorMod(posZ, (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel))); + } + + public RegionPos getRegionPos() + { + return new RegionPos( + Math.floorDiv(posX, (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel)), + Math.floorDiv(posZ, (int) Math.pow(2, LodUtil.REGION_DETAIL_LEVEL - detailLevel))); + } + + + @Override + public LevelPos clone() + { + return new LevelPos(detailLevel, posX, posZ); + } + + + public int maxDistance(int playerPosX, int playerPosZ, int regionPosX, int regionPosZ) + { + int width = (int) Math.pow(2, detailLevel); + + int startPosX = regionPosX * 512 + posX * width; + int startPosZ = regionPosZ * 512 + posZ * width; + int endPosX = startPosX + width; + int endPosZ = startPosZ + width; + + int maxDistance = (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - startPosZ, 2)); + maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - endPosZ, 2))); + maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - startPosZ, 2))); + maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - endPosZ, 2))); + + return maxDistance; + } + + public int maxDistance(int playerPosX, int playerPosZ) + { + int width = (int) Math.pow(2, detailLevel); + + int startPosX = posX * width; + int startPosZ = posZ * width; + int endPosX = startPosX + width; + int endPosZ = startPosZ + width; + + int maxDistance = (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - startPosZ, 2)); + maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - endPosZ, 2))); + maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - startPosZ, 2))); + maxDistance = Math.max(maxDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - endPosZ, 2))); + + return maxDistance; + } + + public int minDistance(int playerPosX, int playerPosZ, int regionPosX, int regionPosZ) + { + int width = (int) Math.pow(2, detailLevel); + + int startPosX = regionPosX * 512 + posX * width; + int startPosZ = regionPosZ * 512 + posZ * width; + int endPosX = startPosX + width; + int endPosZ = startPosZ + width; + + boolean inXArea = playerPosX >= startPosX && playerPosX <= endPosX; + boolean inZArea = playerPosZ >= startPosZ && playerPosZ <= endPosZ; + if (inXArea && inZArea) + { + return 0; + } else if (inXArea) + { + return Math.min( + Math.abs(playerPosZ - startPosZ), + Math.abs(playerPosZ - endPosZ) + ); + } else if (inZArea) + { + return Math.min( + Math.abs(playerPosX - startPosX), + Math.abs(playerPosX - endPosX) + ); + } else + { + int minDistance = (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - startPosZ, 2)); + minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - endPosZ, 2))); + minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - startPosZ, 2))); + minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - endPosZ, 2))); + return minDistance; + } + } + + public int minDistance(int playerPosX, int playerPosZ) + { + int width = (int) Math.pow(2, detailLevel); + + int startPosX = posX * width; + int startPosZ = posZ * width; + int endPosX = startPosX + width; + int endPosZ = startPosZ + width; + + boolean inXArea = playerPosX >= startPosX && playerPosX <= endPosX; + boolean inZArea = playerPosZ >= startPosZ && playerPosZ <= endPosZ; + + if (inXArea && inZArea) + { + return 0; + } else if (inXArea) + { + return Math.min( + Math.abs(playerPosZ - startPosZ), + Math.abs(playerPosZ - endPosZ) + ); + } else if (inZArea) + { + return Math.min( + Math.abs(playerPosX - startPosX), + Math.abs(playerPosX - endPosX) + ); + } else + { + int minDistance = (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - startPosZ, 2)); + minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - startPosX, 2) + Math.pow(playerPosZ - endPosZ, 2))); + minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - startPosZ, 2))); + minDistance = Math.min(minDistance, (int) Math.sqrt(Math.pow(playerPosX - endPosX, 2) + Math.pow(playerPosZ - endPosZ, 2))); + return minDistance; + } + } + + @Override + public String toString() + { + String s = (detailLevel + " " + posX + " " + posZ); + return s; + } }