Package org.djutils.quadtree
Class QuadTree<T extends Envelope>
java.lang.Object
org.djutils.quadtree.QuadTree<T>
- Type Parameters:
T- Type of object stored in this quad tree
- All Implemented Interfaces:
Iterable<T>,Collection<T>
Quad tree for 2D objects. For now, this implementation needs an ultimate outer bounding box. No part of any 2D string object
may exceed that bounding box. A link to each stored 2D object will be stored in each sub-box that it intersects.
Copyright (c) 2019-2025 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See DJUTILS License.
- Author:
- Peter Knoppers
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) classQuadTree.SubTree<T extends Envelope>Sub tree of a quad tree. -
Constructor Summary
ConstructorsConstructorDescriptionQuadTree(int maximumLoad, double minimumSize, double left, double bottom, double right, double top) Create a new QuadTree object (or a sub-tree). -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanaddAll(Collection<? extends T> c) voidclear()booleanbooleancontainsAll(Collection<?> c) Dump a quad tree.intReturn the number of objects at which it is time to try to re-balance.doubleReturn the minimum sub-tree rectangle size.intReturn the total number of sub trees.(package private) voidIncrement the number of sub trees created.booleanisEmpty()iterator()Find all elements intersecting a given bounding box.booleanbooleanremoveAll(Collection<?> c) booleanretainAll(Collection<?> c) intsize()Object[]toArray()<T> T[]toArray(T[] a) toString()toString(int expandDepth) Make a textual description of this quad tree drilling down to the prescribed depth.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Constructor Details
-
QuadTree
public QuadTree(int maximumLoad, double minimumSize, double left, double bottom, double right, double top) Create a new QuadTree object (or a sub-tree).- Parameters:
maximumLoad- number of elements at any level that warrants investigating if the tree can be re-balancedminimumSize- minimum width or height of a sub tree Rectangle (smaller sub tree are never created)left- the lowest X-coordinate that is allowed (inclusive)bottom- the lowest Y-coordinate that is allowed (inclusive)right- the highest X-coordinate that is allowed (exclusive)top- the highest Y-coordinate that is allowed (exclusive)
-
-
Method Details
-
getMaxLoad
public int getMaxLoad()Return the number of objects at which it is time to try to re-balance.- Returns:
- the number of objects at which it is time to try to re-balance
-
getMinimumSize
public double getMinimumSize()Return the minimum sub-tree rectangle size.- Returns:
- the minimum sub-tree rectangle size
-
size
public int size()- Specified by:
sizein interfaceCollection<T extends Envelope>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<T extends Envelope>
-
contains
- Specified by:
containsin interfaceCollection<T extends Envelope>
-
iterator
-
iterator
Find all elements intersecting a given bounding box. This iterator cannot be used to remove elements, but the remove method can be safely called while the iterator is active.- Parameters:
searchArea- the bounding box- Returns:
- iterator that returns all elements that intersect the given bounding box
-
toArray
- Specified by:
toArrayin interfaceCollection<T extends Envelope>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArrayin interfaceCollection<T extends Envelope>
-
add
- Specified by:
addin interfaceCollection<T extends Envelope>
-
remove
- Specified by:
removein interfaceCollection<T extends Envelope>
-
containsAll
- Specified by:
containsAllin interfaceCollection<T extends Envelope>
-
addAll
- Specified by:
addAllin interfaceCollection<T extends Envelope>
-
removeAll
- Specified by:
removeAllin interfaceCollection<T extends Envelope>
-
retainAll
- Specified by:
retainAllin interfaceCollection<T extends Envelope>
-
clear
public void clear()- Specified by:
clearin interfaceCollection<T extends Envelope>
-
incrementSubTreeCount
void incrementSubTreeCount()Increment the number of sub trees created. -
getSubTreeCount
public int getSubTreeCount()Return the total number of sub trees.- Returns:
- the total number of sub trees
-
toString
-
toString
Make a textual description of this quad tree drilling down to the prescribed depth.- Parameters:
expandDepth- maximum depth to descend- Returns:
- textual description of this quad tree
-
dump
Dump a quad tree.- Parameters:
indent- prefix for each output line- Returns:
- textual description of this quad tree.
-