Class SwingThreadSpatial<T,​NT>

    • Constructor Detail

      • SwingThreadSpatial

        protected SwingThreadSpatial​(Spatial<T,​NT> delegate)
    • Method Detail

      • getSpatial

        public Spatial<T,​NT> getSpatial()
      • setActive

        public void setActive​(boolean active)
        Description copied from interface: Spatial
        a flag to suggest whether or not the spatial structure should be used
        Specified by:
        setActive in interface Spatial<T,​NT>
      • isActive

        public boolean isActive()
        Specified by:
        isActive in interface Spatial<T,​NT>
        Returns:
        a hint about whether the spatial structure should be used
      • getGrid

        public List<Shape> getGrid()
        Specified by:
        getGrid in interface Spatial<T,​NT>
        Returns:
        a geometic representation of the spatial structure
      • clear

        public void clear()
        Description copied from interface: Spatial
        destroy the current spatial structure
        Specified by:
        clear in interface Spatial<T,​NT>
      • recalculate

        public void recalculate()
        Description copied from interface: Spatial
        rebuild the data structure
        Specified by:
        recalculate in interface Spatial<T,​NT>
      • getLayoutArea

        public Rectangle2D getLayoutArea()
        Specified by:
        getLayoutArea in interface Spatial<T,​NT>
        Returns:
        the 2 dimensional area of interest for this class
      • setBounds

        public void setBounds​(Rectangle2D bounds)
        Specified by:
        setBounds in interface Spatial<T,​NT>
        Parameters:
        bounds - the new bounds for the data struture
      • getUnion

        public Rectangle2D getUnion​(Rectangle2D rect,
                                    Point2D p)
        Description copied from interface: Spatial
        expands the passed rectangle so that it includes the passed point
        Specified by:
        getUnion in interface Spatial<T,​NT>
        Parameters:
        rect - the area to consider
        p - the point that may be outside of the area
        Returns:
        a new rectangle
      • update

        public void update​(T element,
                           Point location)
        Description copied from interface: Spatial
        update the spatial structure with the (possibly new) location of the passed element
        Specified by:
        update in interface Spatial<T,​NT>
        Parameters:
        element - the element to consider
        location - the location of the element
      • getContainingLeafs

        public Set<? extends TreeNode> getContainingLeafs​(Point2D p)
        Specified by:
        getContainingLeafs in interface Spatial<T,​NT>
        Parameters:
        p - a point to search in the spatial structure
        Returns:
        all leaf nodes that contain the passed point
      • getContainingLeafs

        public Set<? extends TreeNode> getContainingLeafs​(double x,
                                                          double y)
        Specified by:
        getContainingLeafs in interface Spatial<T,​NT>
        Parameters:
        x - the x location to search for
        y - the y location to search for
        Returns:
        all leaf nodes that contain the passed coordinates
      • getContainingLeaf

        public TreeNode getContainingLeaf​(Object element)
        Specified by:
        getContainingLeaf in interface Spatial<T,​NT>
        Parameters:
        element - element to search for
        Returns:
        the leaf node that currently contains the element (not a spatial search)
      • getVisibleElements

        public Set<T> getVisibleElements​(Shape shape)
        Specified by:
        getVisibleElements in interface Spatial<T,​NT>
        Parameters:
        shape - a shape to filter the spatial structure's elements
        Returns:
        all elements that are contained in the passed shape
      • getClosestElement

        public T getClosestElement​(Point2D p)
        Specified by:
        getClosestElement in interface Spatial<T,​NT>
        Parameters:
        p - a point to search in the spatial structure
        Returns:
        the closest element to the passed point
      • getClosestElement

        public T getClosestElement​(double x,
                                   double y)
        Specified by:
        getClosestElement in interface Spatial<T,​NT>
        Parameters:
        x - coordinate of a point to search in the spatial structure
        y - coordinate of a point to search in the spatial structure
        Returns:
        the closest element to the passed coordinates