Class MapElementGridSet<P extends MapElement>

    • Constructor Detail

      • MapElementGridSet

        public MapElementGridSet​(int nRows,
                                 int nColumns,
                                 double boundsX,
                                 double boundsY,
                                 double boundsWidth,
                                 double boundsHeight)
        Constructor.
        Parameters:
        nRows - numbers of rows in the grid
        nColumns - numbers of columns in the grid
        boundsX - is the bounds of the scene.
        boundsY - is the bounds of the scene.
        boundsWidth - is the bounds of the scene.
        boundsHeight - is the bounds of the scene.
      • MapElementGridSet

        public MapElementGridSet​(int nRows,
                                 int nColumns,
                                 Rectangle2d bounds)
        Constructor.
        Parameters:
        nRows - numbers of rows in the grid
        nColumns - numbers of columns in the grid
        bounds - are the bounds of the scene stored inside this tree.
    • Method Detail

      • getNearest

        @Pure
        public final P getNearest​(double x,
                                  double y)
        Description copied from interface: GISElementSet
        Replies the nearest object from the specified point.
        Specified by:
        getNearest in interface GISElementSet<P extends MapElement>
        Parameters:
        x - is the position from which the nearest primitive must be replied.
        y - is the position from which the nearest primitive must be replied.
        Returns:
        the nearest element or null if none.
        See Also:
        GISElementSet.getNearestData(double, double)
      • getNearestData

        @Pure
        public final org.eclipse.xtext.xbase.lib.Pair<P,​Double> getNearestData​(double x,
                                                                                     double y)
        Description copied from interface: GISElementSet
        Replies the nearest object from the specified point, and its distance to the point.

        The nearest neighbor (NN) algorithm, to find the NN to a given target point not in the tree, relies on the ability to discard large portions of the tree by performing a simple test. To perform the NN calculation, the tree is searched in a depth-first fashion, refining the nearest distance. First the root node is examined with an initial assumption that the smallest distance to the next point is infinite. The subdomain (right or left), which is a hyperrectangle, containing the target point is searched. This is done recursively until a final minimum region containing the node is found. The algorithm then (through recursion) examines each parent node, seeing if it is possible for the other domain to contain a point that is closer. This is performed by testing for the possibility of intersection between the hyperrectangle and the hypersphere (formed by target node and current minimum radius). If the rectangle that has not been recursively examined yet does not intersect this sphere, then there is no way that the rectangle can contain a point that is a better nearest neighbour. This is repeated until all domains are either searched or discarded, thus leaving the nearest neighbour as the final result. In addition to this one also has the distance to the nearest neighbour on hand as well. Finding the nearest point is an O(logN) operation.

        Specified by:
        getNearestData in interface GISElementSet<P extends MapElement>
        Parameters:
        x - is the position from which the nearest primitive must be replied.
        y - is the position from which the nearest primitive must be replied.
        Returns:
        the nearest element and its distance to the given coordinates; or null if none.
        See Also:
        GISElementSet.getNearest(double, double)
      • getNearestData

        @Pure
        public org.eclipse.xtext.xbase.lib.Pair<P,​Double> getNearestData​(Point2D<?,​?> position)
        Description copied from interface: GISElementSet
        Replies the nearest object from the specified point, and its distance to the point.
        Specified by:
        getNearestData in interface GISElementSet<P extends MapElement>
        Parameters:
        position - is the position from which the nearest primitive must be replied.
        Returns:
        the nearest element and its distance to the given coordinates; or null if none.
        See Also:
        GISElementSet.getNearest(Point2D)