Interface SpatialIndex

  • All Known Implementing Classes:
    RTree


    public interface SpatialIndex
    Defines methods that must be implemented by all spatial indexes. This includes the RTree and its variants.
    • Method Summary

      Modifier and Type Method and Description
      void add(Rectangle r, int id)
      Adds a new rectangle to the spatial index
      void contains(Rectangle r, TIntProcedure ip)
      Finds all rectangles contained by the passed rectangle.
      boolean delete(Rectangle r, int id)
      Deletes a rectangle from the spatial index
      Rectangle getBounds()
      Returns the bounds of all the entries in the spatial index, or null if there are no entries.
      void intersects(Rectangle r, TIntProcedure ip)
      Finds all rectangles that intersect the passed rectangle.
      void nearest(Point p, TIntProcedure v, float furthestDistance)
      Finds the nearest rectangles to the passed rectangle and calls v.execute(id) for each one.
      void nearestN(Point p, TIntProcedure v, int n, float distance)
      Finds the N nearest rectangles to the passed rectangle, and calls execute(id, distance) on each one, in order of increasing distance.
      void nearestNUnsorted(Point p, TIntProcedure v, int n, float distance)
      Same as nearestN, except the found rectangles are not returned in sorted order.
      int size()
      Returns the number of entries in the spatial index
    • Method Detail

      • add

        void add(Rectangle r,
                 int id)
        Adds a new rectangle to the spatial index
        Parameters:
        r - The rectangle to add to the spatial index.
        id - The ID of the rectangle to add to the spatial index. The result of adding more than one rectangle with the same ID is undefined.
      • delete

        boolean delete(Rectangle r,
                       int id)
        Deletes a rectangle from the spatial index
        Parameters:
        r - The rectangle to delete from the spatial index
        id - The ID of the rectangle to delete from the spatial index
        Returns:
        true if the rectangle was deleted false if the rectangle was not found, or the rectangle was found but with a different ID
      • nearest

        void nearest(Point p,
                     TIntProcedure v,
                     float furthestDistance)
        Finds the nearest rectangles to the passed rectangle and calls v.execute(id) for each one. If multiple rectangles are equally near, they will all be returned.
        Parameters:
        p - The point for which this method finds the nearest neighbours.
        v - The IntProcedure whose execute() method is is called for each nearest neighbour.
        furthestDistance - The furthest distance away from the rectangle to search. Rectangles further than this will not be found. This should be as small as possible to minimise the search time. Use Float.POSITIVE_INFINITY to guarantee that the nearest rectangle is found, no matter how far away, although this will slow down the algorithm.
      • nearestN

        void nearestN(Point p,
                      TIntProcedure v,
                      int n,
                      float distance)
        Finds the N nearest rectangles to the passed rectangle, and calls execute(id, distance) on each one, in order of increasing distance. Note that fewer than N rectangles may be found if fewer entries exist within the specified furthest distance, or more if rectangles N and N+1 have equal distances.
        Parameters:
        p - The point for which this method finds the nearest neighbours.
        v - The IntfloatProcedure whose execute() method is is called for each nearest neighbour.
        n - The desired number of rectangles to find (but note that fewer or more may be returned)
        distance - The furthest distance away from the rectangle to search. Rectangles further than this will not be found. This should be as small as possible to minimise the search time. Use Float.POSITIVE_INFINITY to guarantee that the nearest rectangle is found, no matter how far away, although this will slow down the algorithm.
      • nearestNUnsorted

        void nearestNUnsorted(Point p,
                              TIntProcedure v,
                              int n,
                              float distance)
        Same as nearestN, except the found rectangles are not returned in sorted order. This will be faster, if sorting is not required
      • intersects

        void intersects(Rectangle r,
                        TIntProcedure ip)
        Finds all rectangles that intersect the passed rectangle.
        Parameters:
        r - The rectangle for which this method finds intersecting rectangles.
        ip - The IntProcedure whose execute() method is is called for each intersecting rectangle.
      • contains

        void contains(Rectangle r,
                      TIntProcedure ip)
        Finds all rectangles contained by the passed rectangle.
        Parameters:
        r - The rectangle for which this method finds contained rectangles.
        ip - The procedure whose visit() method is is called for each contained rectangle.
      • size

        int size()
        Returns the number of entries in the spatial index
      • getBounds

        Rectangle getBounds()
        Returns the bounds of all the entries in the spatial index, or null if there are no entries.