Class KDTree<T>

java.lang.Object
com.hypixel.hytale.component.spatial.KDTree<T>
Type Parameters:
T - the type of data stored in the structure.
All Implemented Interfaces:
SpatialStructure<T>

public class KDTree<T> extends Object implements SpatialStructure<T>
A KD-Tree implementation of a spatial structure.
  • Constructor Summary

    Constructors
    Constructor
    Description
    KDTree(Predicate<T> collectionFilter)
    Default Constructor for a KDTree instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    closest(org.joml.Vector3dc point)
    Gets the data closest to a point, or null if there is no data in the structure.
    void
    collect(org.joml.Vector3dc center, double radius, List<T> results)
    Gets all data that is within a specified spherical radius of a point, defined by center and radius.
    void
    collectBox(org.joml.Vector3dc min, org.joml.Vector3dc max, List<T> results)
    Gets all data that is within a specified axis-aligned box, defined by min and max positions.
    void
    collectCylinder(org.joml.Vector3dc center, double radius, double height, List<T> results)
    Gets all data that is within a specified cylindrical area, defined by a center point, radius, and height.
     
    void
    ordered(org.joml.Vector3dc center, double radius, List<T> results)
    Gets all data that is within a specified radius of a point in order of closest to furthest.
    void
    ordered3DAxis(org.joml.Vector3dc center, double xSearchRadius, double ySearchRadius, double zSearchRadius, List<T> results)
    Gets all data that is within specified radius along each axis of a point.
    void
    rebuild(SpatialData<T> spatialData)
    Builds the structure using the provided data.
    int
     

    Methods inherited from class Object

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

    • KDTree

      public KDTree(@Nonnull Predicate<T> collectionFilter)
      Default Constructor for a KDTree instance.
      Parameters:
      collectionFilter - The filter to apply when collecting data from the structure.
  • Method Details

    • size

      public int size()
      Specified by:
      size in interface SpatialStructure<T>
      Returns:
      the number of pieces of data in the structure.
    • rebuild

      public void rebuild(@Nonnull SpatialData<T> spatialData)
      Description copied from interface: SpatialStructure
      Builds the structure using the provided data. This clears any existing data in the structure.
      Specified by:
      rebuild in interface SpatialStructure<T>
      Parameters:
      spatialData - The data to build the structure with.
    • closest

      @Nullable public T closest(@Nonnull org.joml.Vector3dc point)
      Description copied from interface: SpatialStructure
      Gets the data closest to a point, or null if there is no data in the structure.
      Specified by:
      closest in interface SpatialStructure<T>
      Parameters:
      point - The point to search from.
      Returns:
      the data closest to the provided point, or null if there is no data in the structure.
    • collect

      public void collect(@Nonnull org.joml.Vector3dc center, double radius, @Nonnull List<T> results)
      Description copied from interface: SpatialStructure
      Gets all data that is within a specified spherical radius of a point, defined by center and radius.
      Specified by:
      collect in interface SpatialStructure<T>
      Parameters:
      center - The center of the sphere.
      radius - The radius of the sphere.
      results - The list to populate with results.
    • collectCylinder

      public void collectCylinder(@Nonnull org.joml.Vector3dc center, double radius, double height, @Nonnull List<T> results)
      Description copied from interface: SpatialStructure
      Gets all data that is within a specified cylindrical area, defined by a center point, radius, and height.
      Specified by:
      collectCylinder in interface SpatialStructure<T>
      Parameters:
      center - The center point of the cylinder's base.
      radius - The radius of the cylinder.
      height - The height of the cylinder.
      results - The list to populate with results.
    • collectBox

      public void collectBox(@Nonnull org.joml.Vector3dc min, @Nonnull org.joml.Vector3dc max, @Nonnull List<T> results)
      Description copied from interface: SpatialStructure
      Gets all data that is within a specified axis-aligned box, defined by min and max positions.
      Specified by:
      collectBox in interface SpatialStructure<T>
      Parameters:
      min - The minimum corner of the box (inclusive).
      max - The maximum corner of the box (inclusive).
      results - The list to populate with results.
    • ordered

      public void ordered(@Nonnull org.joml.Vector3dc center, double radius, @Nonnull List<T> results)
      Description copied from interface: SpatialStructure
      Gets all data that is within a specified radius of a point in order of closest to furthest.

      If the use case doesn't require the order then please use SpatialStructure.collect(Vector3dc, double, List) instead.

      Specified by:
      ordered in interface SpatialStructure<T>
      Parameters:
      center - The center point from which to search.
      radius - The radius of the search.
      results - The list to populate with results, ordered from closest to furthest.
    • ordered3DAxis

      public void ordered3DAxis(@Nonnull org.joml.Vector3dc center, double xSearchRadius, double ySearchRadius, double zSearchRadius, @Nonnull List<T> results)
      Description copied from interface: SpatialStructure
      Gets all data that is within specified radius along each axis of a point.
      Specified by:
      ordered3DAxis in interface SpatialStructure<T>
      Parameters:
      center - The center point from which to search.
      xSearchRadius - The search radius along the X axis.
      ySearchRadius - The search radius along the Y axis.
      zSearchRadius - The search radius along the Z axis.
      results - The output list to store data within the specified radius, ordered from closest to furthest.
    • dump

      @Nonnull public String dump()
      Specified by:
      dump in interface SpatialStructure<T>
      Returns:
      an information dump of this spatial structure, for debugging purposes.