Class KDTree<T extends Location<?>>

java.lang.Object
org.naviqore.utils.spatial.index.KDTree<T>
Type Parameters:
T - The type of location stored in the tree.

public class KDTree<T extends Location<?>> extends Object
A k-dimensional tree (k-d tree) for fast, efficient proximity searches. This implementation only supports 2-dimensional spatial data.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    nearestNeighbour(double firstComponent, double secondComponent)
    Finds the nearest neighbour to a coordinate specified by its components.
    Finds the nearest neighbour to a given coordinate.
    nearestNeighbour(T location)
    Finds the nearest neighbour to a given location.
    rangeSearch(double firstComponent, double secondComponent, double radius)
    Performs a range search to find all locations within a certain radius of a coordinate specified by its components.
    rangeSearch(Coordinate center, double radius)
    Performs a range search to find all locations within a certain radius of a center coordinate.
    rangeSearch(T center, double radius)
    Performs a range search to find all locations within a certain radius of a center location.

    Methods inherited from class java.lang.Object

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

    • KDTree

      public KDTree()
  • Method Details

    • nearestNeighbour

      public T nearestNeighbour(T location)
      Finds the nearest neighbour to a given location.
      Parameters:
      location - The location to find the nearest neighbour for.
      Returns:
      The nearest neighbour to the given location.
    • nearestNeighbour

      public T nearestNeighbour(Coordinate coordinate)
      Finds the nearest neighbour to a given coordinate.
      Parameters:
      coordinate - The coordinate to find the nearest neighbour for.
      Returns:
      The nearest neighbour to the given coordinate.
    • nearestNeighbour

      public T nearestNeighbour(double firstComponent, double secondComponent)
      Finds the nearest neighbour to a coordinate specified by its components.
      Parameters:
      firstComponent - The first component of the coordinate.
      secondComponent - The second component of the coordinate.
      Returns:
      The nearest neighbour to the coordinate specified by firstComponent and secondComponent.
    • rangeSearch

      public ArrayList<T> rangeSearch(T center, double radius)
      Performs a range search to find all locations within a certain radius of a center location.
      Parameters:
      center - The center location for the range search.
      radius - The radius within which to search.
      Returns:
      A list of all locations within the radius of the center.
    • rangeSearch

      public ArrayList<T> rangeSearch(Coordinate center, double radius)
      Performs a range search to find all locations within a certain radius of a center coordinate.
      Parameters:
      center - The center coordinate for the range search.
      radius - The radius within which to search.
      Returns:
      A list of all locations within the radius of the center.
    • rangeSearch

      public ArrayList<T> rangeSearch(double firstComponent, double secondComponent, double radius)
      Performs a range search to find all locations within a certain radius of a coordinate specified by its components.
      Parameters:
      firstComponent - The first component of the center coordinate.
      secondComponent - The second component of the center coordinate.
      radius - The radius within which to search.
      Returns:
      A list of all locations within the radius of the specified center coordinate.