Class TwoDTree<T extends TwoDTree.Point>

java.lang.Object
rgu.transport.algorithms.collections.TwoDTree<T>
Type Parameters:
T - the type of object
All Implemented Interfaces:
NearestFinder<T>

public class TwoDTree<T extends TwoDTree.Point> extends Object implements NearestFinder<T>
A 2D tree used as a nearest finder with a compatible metric.
Author:
Lee A. Christie
  • Method Details

    • of

      public static <T extends TwoDTree.Point> TwoDTree<T> of(Set<T> points)
      Creates a new 2D tree from the given set of points.
      Type Parameters:
      T - the element type
      Parameters:
      points - the points, not null
      Returns:
      the tree
    • of

      public static <T extends TwoDTree.Point> TwoDTree<T> of(Set<T> points, ProgressListener progress)
      Creates a new 2D tree from the given set of points.
      Type Parameters:
      T - the element type
      Parameters:
      points - the points, not null
      progress - listener for the progress between 0.0 and 1.0, not null
      Returns:
      the tree
    • of

      public static <T extends TwoDTree.Point> TwoDTree<T> of(Set<T> points, ProgressListener progress, boolean subStageOnly)
      Creates a new 2D tree from the given set of points.
      Type Parameters:
      T - the element type
      Parameters:
      points - the points, not null
      progress - listener for the progress between 0.0 and 1.0, not null
      subStageOnly - if ture, will not call onNewStage or onCompletion on the progress listener
      Returns:
      the tree
      Throws:
      NoSuchElementException - if the collection is empty
    • nearest

      public T nearest(T target)
      Finds the nearest neighbour in the tree based on a Euclidean distance.
      Specified by:
      nearest in interface NearestFinder<T extends TwoDTree.Point>
      Parameters:
      target - the target, not null
      Returns:
      the nearest neighbour
    • withRatio

      public NearestFinder<T> withRatio(double ratio)
      Returns this 2D tree adapted to use a given stretch ratio (applied to the x-axis).
      Parameters:
      ratio - the ratio, finite, positive
      Returns:
      this 2D tree with the given scale ratio