Package org.stianloader.stianknn

# Class SpatialBufferedQueryArray<E>

java.lang.Object
org.stianloader.stianknn.SpatialBufferedQueryArray<E>

Type Parameters:
  `E` - The type of elements this container may store. Note that the elements have to be wrapped in a `PointObjectPair`, see the constructor's signature for more.

All Implemented Interfaces:
  `SpatialIndex1NN<E>`, `SpatialIndexIterable<E>`, `SpatialIndexKNN<E>`, `SpatialRingIndex1NN<E>`

public class SpatialBufferedQueryArray<E> extends Object implements SpatialRingIndex1NN<E>, SpatialIndexIterable<E>
An improved variant of the original variant of KNN spatial queries implemented by this library. In specific, this class makes use of buffering to avoid cases where object with equal distance get absorbed. At a technical level, this variant retains the core design idea wherein the points are stored in an array sorted by their horizontal position. This allows objects with similar coordinates to be grouped together closer in memory. It also avoid the use of nests or otherwise multiple arrays, which is a property that is commonly used across traditional spatial queries, but which can be inefficient at times.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SpatialBufferedQueryArray(@NotNull Collection<@NotNull PointObjectPair<E>> points)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `Iterator<@NotNull E>`
  `createIterator(float x, float y)`
  Create an iterator that fetches the element close to the point defined by the parameters `x` and `y`.
  `E`
  `query1nn(float x, float y, float minDistSq, float maxDistSq)`
  `void`
  `queryKnn(float x, float y, int neighbourCount, @NotNull Consumer<@NotNull E> out)`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.stianloader.stianknn.SpatialRingIndex1NN

  `query1nn`

- ## Constructor Details

  - ### SpatialBufferedQueryArray

    public SpatialBufferedQueryArray(@NotNull @NotNull Collection<@NotNull PointObjectPair<E>> points)

- ## Method Details

  - ### createIterator

    public Iterator<@NotNull E> createIterator(float x, float y)
    Description copied from interface: `SpatialIndexIterable`
    Create an iterator that fetches the element close to the point defined by the parameters `x` and `y`. The iterator will return the elements closest to the point first, then return the elements further away from the point.

    Note that the iterator may be inefficient when fetching large amounts of points, though it concretely depends on the implementation.

    Specified by:
      `createIterator` in interface `SpatialIndexIterable<E>`
    Parameters:
      `x` - The x component of the position of the point which will be the origin for the proximity evaluations.
      `y` - The y component of the position of the point which will be the origin for the proximity evaluations.
    Returns:
      An iterator that iterates over the elements based on the proximity from the given point.

  - ### query1nn

    @Nullable public E query1nn(float x, float y, float minDistSq, float maxDistSq)
    Specified by:
      `query1nn` in interface `SpatialRingIndex1NN<E>`

  - ### queryKnn

    public void queryKnn(float x, float y, int neighbourCount, @NotNull @NotNull Consumer<@NotNull E> out)
    Specified by:
      `queryKnn` in interface `SpatialIndexKNN<E>`