SpatialData.java
package com.hypixel.hytale.component.spatial;
import com.hypixel.hytale.common.util.ArrayUtil;
import com.hypixel.hytale.math.vector.Vector3d;
import it.unimi.dsi.fastutil.ints.IntArrays;
import java.util.Arrays;
import java.util.Objects;
import javax.annotation.Nonnull;
public class SpatialData<T> {
public static final Vector3d[] EMPTY_VECTOR_ARRAY = new Vector3d[0];
@Nonnull
private int[] indexes;
@Nonnull
private long[] moroton;
private Vector3d[] vectors;
@Nonnull
private T[] data;
private int size;
public SpatialData() {
this.indexes = ArrayUtil.EMPTY_INT_ARRAY;
this.moroton = ArrayUtil.EMPTY_LONG_ARRAY;
this.vectors = EMPTY_VECTOR_ARRAY;
this.data = (T[])ArrayUtil.emptyArray();
}
public int size() {
return .size;
}
{
.indexes[i];
}
Vector3d {
.vectors[i];
}
T {
(T).data[i];
}
{
Objects.requireNonNull(value);
(.vectors.length < .size + ) {
ArrayUtil.grow(.size);
.indexes = Arrays.copyOf(.indexes, newLength);
.vectors = (Vector3d[])Arrays.copyOf(.vectors, newLength);
.data = (T[])Arrays.copyOf(.data, newLength);
( .size; i < newLength; ++i) {
.vectors[i] = ();
}
}
.size++;
.indexes[index] = index;
.vectors[index].assign(vector);
.data[index] = value;
}
{
.size + additionalSize;
(.vectors.length < newSize) {
ArrayUtil.grow(newSize);
.indexes = Arrays.copyOf(.indexes, newLength);
.vectors = (Vector3d[])Arrays.copyOf(.vectors, newLength);
.data = (T[])Arrays.copyOf(.data, newLength);
( .size; i < newLength; ++i) {
.vectors[i] = ();
}
}
}
{
Objects.requireNonNull(value);
.size++;
.indexes[index] = index;
.vectors[index].assign(vector);
.data[index] = value;
}
{
IntArrays.quickSort(.indexes, , .size, (i1, i2) -> {
.vectors[i1];
.vectors[i2];
Double.compare(v1.x, v2.x);
(xComp != ) {
xComp;
} {
Double.compare(v1.z, v2.z);
zComp != ? zComp : Double.compare(v1.y, v2.y);
}
});
}
{
/ ;
/ ;
/ ;
- / ;
- / ;
- / ;
( ; i < .size; ++i) {
.vectors[i];
(v.x < minX) {
minX = v.x;
}
(v.y < minY) {
minY = v.y;
}
(v.z < minZ) {
minZ = v.z;
}
(v.x > maxX) {
maxX = v.x;
}
(v.y > maxY) {
maxY = v.y;
}
(v.z > maxZ) {
maxZ = v.z;
}
}
.moroton = .moroton.length < .size ? Arrays.copyOf(.moroton, .size) : .moroton;
( ; i < .size; ++i) {
.vectors[i];
.moroton[i] = Long.reverse(MortonCode.encode(v.x, v.y, v.z, minX, minY, minZ, maxX, maxY, maxZ));
}
IntArrays.quickSort(.indexes, , .size, (i1, i2) -> Long.compare(.moroton[i1], .moroton[i2]));
}
{
Arrays.fill(.data, , .size, (Object));
.size = ;
}
}