CircleSpiralIterator class

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

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

Поля (11)

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

Методы (27)

МодификаторыВозвратСигнатура
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 IllegalStateExceptionthrow new IllegalStateException("SpiralIterator is not setup!")
abstract throw new NoSuchElementExceptionthrow new NoSuchElementException("No more positions inside the circle!")
public int getCompletedRadiusint getCompletedRadius()
public int getCurrentRadiusint getCurrentRadius()
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.hasNext)
if if(!this.hasNext)
if if(!this.setup)
if if(!this.hasNext)
if if(var5 >= this.radiusFromSq && var5 <= this.radiusToSq)
if if(this.x == this.z || this.x < 0 && this.x == -this.z || this.x > 0 && this.x == 1 - this.z)
public void initvoid init(int var1, int var2, int var3)
public void initvoid init(int var1, int var2, int var3, int var4)
public long nextlong next()
private void prepareNextvoid prepareNext()
public void resetvoid reset()
while while(!this.hasNext && this.i < this.maxI)

Исходный код

Показать/скрыть
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">import java.util.NoSuchElementException;

class="kw">public class CircleSpiralIterator {
   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">private long radiusFromSq;
   class="kw">private long radiusToSq;
   class="kw">private boolean hasNext;
   class="kw">private long nextChunk;

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

   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;
      this.radiusFromSq = (long)var3 * var3;
      this.radiusToSq = (long)var4 * var4;
      long var5 = 1L + var4 * 2L;
      this.maxI = var5 * var5;
      if (var3 != 0) {
         float var7 = var3 / 2.0F;
         float var8 = var7 * var7;
         int var9 = (int)Math.sqrt(var8 + var8);
         long var10 = 1L + var9 * 2L;
         this.i = var10 * var10;
         long var12 = SpiralIterator.getPosFromIndex((int)this.i);
         this.x = ChunkUtil.xOfChunkIndex(var12);
         this.z = ChunkUtil.zOfChunkIndex(var12);
         this.dx = 1;
         this.dz = 0;
      } else {
         this.i = 0L;
         this.x = this.z = 0;
         this.dx = 0;
         this.dz = -1;
      }

      this.hasNext = false;
      this.prepareNext();
      this.setup = true;
   }

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

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

      if (!this.hasNext) {
         this.prepareNext();
      }

      if (!this.hasNext) {
         throw new NoSuchElementException("No more positions inside the circle!");
      }

      this.hasNext = false;
      class="kw">return this.nextChunk;
   }

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

      if (!this.hasNext) {
         this.prepareNext();
      }

      class="kw">return this.hasNext;
   }

   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">private void prepareNext() {
      while (!this.hasNext && this.i < this.maxI) {
         long var1 = this.x;
         long var3 = this.z;
         long var5 = var1 * var1 + var3 * var3;
         if (var5 >= this.radiusFromSq && var5 <= this.radiusToSq) {
            this.nextChunk = ChunkUtil.indexChunk(this.chunkX + this.x, this.chunkZ + this.z);
            this.hasNext = true;
         }

         if (this.x == this.z || this.x < 0 && this.x == -this.z || this.x > 0 && this.x == 1 - this.z) {
            int var7 = this.dx;
            this.dx = -this.dz;
            this.dz = var7;
         }

         this.x = this.x + this.dx;
         this.z = this.z + this.dz;
         this.i++;
      }
   }
}