SpiralIterator class

Пакет: com.hypixel.hytale.math.iterator

Файл: com/hypixel/hytale/math/iterator/SpiralIterator.java

Поля (13)

МодификаторыТипИмя
final long MAX_RADIUS_LONG
long var1
int var1
int var2
int var3
int var3
var3
var3
int var4
long var5
int var5
long var7
long var9

Методы (33)

МодификаторыВозвратСигнатура
abstract throw new IllegalArgumentExceptionthrow new IllegalArgumentException("radiusFrom must be >= 0: " + var3)
abstract throw new IllegalArgumentExceptionthrow new IllegalArgumentException("radiusTo must be > 0: " + var4)
abstract throw new IllegalArgumentExceptionthrow new IllegalArgumentException("radiusTo must be < MAX_RADIUS " + MAX_RADIUS + ": " + var4)
abstract throw new IllegalArgumentExceptionthrow new IllegalArgumentException("radiusFrom must be < radiusTo: " + var3 + " -> " + var4)
abstract throw new IllegalArgumentExceptionthrow new IllegalArgumentException("Index mus be >= 0")
abstract throw new IllegalStateExceptionthrow new IllegalStateException("SpiralIterator is not setup!")
public int getChunkXint getChunkX()
public int getChunkZint getChunkZ()
public int getCompletedRadiusint getCompletedRadius()
public int getCurrentRadiusint getCurrentRadius()
public int getDxint getDx()
public int getDzint getDz()
public long getIndexlong getIndex()
public long getMaxIndexlong getMaxIndex()
static long getPosFromIndexlong getPosFromIndex(int var0)
public int getXint getX()
public int getZint getZ()
public boolean hasNextboolean hasNext()
if if(var3 < 0)
if if(var4 <= 0)
if if(var4 > MAX_RADIUS)
if if(var3 >= var4)
if if(var3 != 0)
if if(!this.setup)
if if(this.x == this.z || this.x < 0 && this.x == -this.z || this.x > 0 && this.x == 1 - this.z)
if if(var0 < 0)
if if(var0 < var4)
if if(var0 < var5)
public void initvoid init(int var1, int var2, int var3)
public void initvoid init(int var1, int var2, int var3, int var4)
public boolean isSetupboolean isSetup()
public long nextlong next()
public void resetvoid reset()

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.math.iterator;

class="kw">import com.hypixel.hytale.math.util.ChunkUtil;
class="kw">import com.hypixel.hytale.math.util.MathUtil;

class="kw">public class SpiralIterator {
   class="kw">public class="kw">static class="kw">final long MAX_RADIUS_LONG = (long)Math.sqrt(9.223372E18F) / 2L - 1L;
   class="kw">public class="kw">static class="kw">final int MAX_RADIUS = (int)MAX_RADIUS_LONG;
   class="kw">private boolean setup;
   class="kw">private int chunkX;
   class="kw">private int chunkZ;
   class="kw">private long maxI;
   class="kw">private long i;
   class="kw">private int x;
   class="kw">private int z;
   class="kw">private int dx;
   class="kw">private int dz;

   class="kw">public SpiralIterator() {
   }

   class="kw">public SpiralIterator(int var1, int var2, int var3) {
      this.init(var1, var2, var3);
   }

   class="kw">public SpiralIterator(int var1, int var2, int var3, int var4) {
      this.init(var1, var2, var3, var4);
   }

   class="kw">public void init(int var1, int var2, int var3) {
      this.init(var1, var2, 0, var3);
   }

   class="kw">public void init(int var1, int var2, int var3, int var4) {
      if (var3 < 0) {
         throw new IllegalArgumentException("radiusFrom must be >= 0: " + var3);
      }

      if (var4 <= 0) {
         throw new IllegalArgumentException("radiusTo must be > 0: " + var4);
      }

      if (var4 > MAX_RADIUS) {
         throw new IllegalArgumentException("radiusTo must be < MAX_RADIUS " + MAX_RADIUS + ": " + var4);
      }

      if (var3 >= var4) {
         throw new IllegalArgumentException("radiusFrom must be < radiusTo: " + var3 + " -> " + var4);
      }

      this.chunkX = var1;
      this.chunkZ = var2;
      long var5 = 1L + var4 * 2L;
      this.maxI = var5 * var5;
      if (var3 != 0) {
         long var7 = 1L + var3 * 2L;
         this.i = var7 * var7;
         long var9 = getPosFromIndex((int)this.i);
         this.x = ChunkUtil.xOfChunkIndex(var9);
         this.z = ChunkUtil.zOfChunkIndex(var9);
         this.dx = 1;
         this.dz = 0;
      } else {
         this.i = 0L;
         this.x = this.z = 0;
         this.dx = 0;
         this.dz = -1;
      }

      this.setup = true;
   }

   class="kw">public void reset() {
      this.setup = false;
   }

   class="kw">public long next() {
      if (!this.setup) {
         throw new IllegalStateException("SpiralIterator is not setup!");
      }

      long var1 = ChunkUtil.indexChunk(this.chunkX + this.x, this.chunkZ + this.z);
      if (this.x == this.z || this.x < 0 && this.x == -this.z || this.x > 0 && this.x == 1 - this.z) {
         int var3 = this.dx;
         this.dx = -this.dz;
         this.dz = var3;
      }

      this.x = this.x + this.dx;
      this.z = this.z + this.dz;
      this.i++;
      class="kw">return var1;
   }

   class="kw">public boolean hasNext() {
      class="kw">return this.i < this.maxI;
   }

   class="kw">public boolean isSetup() {
      class="kw">return this.setup;
   }

   class="kw">public long getIndex() {
      class="kw">return this.i;
   }

   class="kw">public long getMaxIndex() {
      class="kw">return this.maxI;
   }

   class="kw">public int getChunkX() {
      class="kw">return this.chunkX;
   }

   class="kw">public int getChunkZ() {
      class="kw">return this.chunkZ;
   }

   class="kw">public int getX() {
      class="kw">return this.x;
   }

   class="kw">public int getZ() {
      class="kw">return this.z;
   }

   class="kw">public int getDx() {
      class="kw">return this.dx;
   }

   class="kw">public int getDz() {
      class="kw">return this.dz;
   }

   class="kw">public int getCurrentRadius() {
      class="kw">return MathUtil.ceil((Math.sqrt(this.i) - 1.0) / 2.0);
   }

   class="kw">public int getCompletedRadius() {
      class="kw">return (int)((Math.sqrt(this.i) - 1.0) / 2.0);
   }

   class="kw">public class="kw">static long getPosFromIndex(int var0) {
      if (var0 < 0) {
         throw new IllegalArgumentException("Index mus be >= 0");
      }

      var0++;
      int var1 = MathUtil.ceil((Math.sqrt(var0) - 1.0) / 2.0);
      int var2 = 2 * var1;
      int var3 = (int)Math.pow(1 + var2, 2.0);
      int var4 = var3 - var2;
      if (var0 < var4) {
         var3 = var4;
         int var5 = var3 - var2;
         if (var0 < var5) {
            var3 = var5;
            class="kw">return var0 >= var3 - var2 ? ChunkUtil.indexChunk(-var1 + (var3 - var0), var1) : ChunkUtil.indexChunk(var1, var1 - (var3 - var0 - var2));
         } else {
            class="kw">return ChunkUtil.indexChunk(-var1, -var1 + (var3 - var0));
         }
      } else {
         class="kw">return ChunkUtil.indexChunk(var1 - (var3 - var0), -var1);
      }
   }
}