Class SphereOffsets

java.lang.Object
com.hypixel.hytale.math.iterator.SphereOffsets

public final class SphereOffsets extends Object
Immutable, pre-computed list of (dx, dy, dz) offsets contained in a sphere centred on the origin, sorted ascending by 3D Euclidean distance² from the origin.

A point (dx, dy, dz) is inside when dx² + dy² + dz² <= R².

Build once at the server's maximum allowed radius and share the resulting instance across every SphereSpiralIterator; each player iterator records its own (smaller-or-equal) radius and the iterator's upfront binary search clamps the cursor so a player smaller than the shared maximum walks only their portion of the list. Because the list is sorted by distSq, every offset before the player's clamp is guaranteed inside the player's sphere, so no per-cell filter is needed in the hot loop.

Memory: roughly 10 bytes per offset (three shorts plus an int for distSq). At R=24 the list is ~58k offsets ≈ 580 KB.

Thread-safe: all fields are final, all arrays are read-only after construction.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int
    Number of offsets stored (length of each array).
    final int[]
    distSq[i] = dx[i]² + dy[i]² + dz[i]², sorted ascending.
    final short[]
    Offset x-components in distance² order.
    final short[]
    Offset y-components in distance² order.
    final short[]
    Offset z-components in distance² order.
    final int
    Radius R the list was built for.
  • Method Summary

    Modifier and Type
    Method
    Description
    build(int maxR)
    Builds the sorted offset list for a sphere of the given radius.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • dx

      @Nonnull public final short[] dx
      Offset x-components in distance² order. Read-only.
    • dy

      @Nonnull public final short[] dy
      Offset y-components in distance² order. Read-only.
    • dz

      @Nonnull public final short[] dz
      Offset z-components in distance² order. Read-only.
    • distSq

      @Nonnull public final int[] distSq
      distSq[i] = dx[i]² + dy[i]² + dz[i]², sorted ascending. Read-only.
    • count

      public final int count
      Number of offsets stored (length of each array).
    • maxR

      public final int maxR
      Radius R the list was built for.
  • Method Details

    • build

      @Nonnull public static SphereOffsets build(int maxR)
      Builds the sorted offset list for a sphere of the given radius.

      One-shot cost is dominated by the sort: roughly O(V log V) where V is the sphere's cell count. At R=24 this is a few ms on contemporary hardware. Intended to run once at server startup (and again on configuration reload).

      Parameters:
      maxR - radius, must be >= 0
      Returns:
      the immutable, sorted offset list