GoogleMap Utils quadTree - what is a usecase?

696 views Asked by At

I seen google has a quad tree implemenation that can be used to search if a given point is close to another point efficiently. but i do not understand how to use . take a look here . i also found this info very valuable:

By definition, a quadtree is a tree in which each node has at most four children

google's example is using points but i assume i could just swap that for lat long. but lets talk about the example shown above in the link.

i see they are adding four points like this:

// Add 4 points to the tree.
tree.add(QuadTreeItem(point: GQTPoint(x: -1, y: -1)))
tree.add(QuadTreeItem(point: GQTPoint(x: -1, y: 1)))
tree.add(QuadTreeItem(point: GQTPoint(x: 1, y: 1)))
tree.add(QuadTreeItem(point: GQTPoint(x: 1, y: -1)))

then they start searching for bounds in bounds like this:

// Search for items within the rectangle with lower corner of (-1.5, -1.5)
// and upper corner of (1.5, 1.5).

does it mean, they are searching only the four points i put in above to find which ones are inside these bounds ?

Update: should i understand that that this quadTree google implemented will automatically re-arrange itself when i add points to it such that each node will have at most 4 points as children that are near to it ? does it do this for me automatically ?

0

There are 0 answers