Package de.extio.spacecraft.shared.world
Class QuadTree<T extends SpatialIndex2Capable>
- java.lang.Object
-
- de.extio.spacecraft.shared.world.QuadTree<T>
-
- All Implemented Interfaces:
SpatialIndex2D<T>,AutoCloseable,Iterable<T>
public final class QuadTree<T extends SpatialIndex2Capable> extends Object implements SpatialIndex2D<T>
This is the preferred SpatialIndex2D implementation to index bigger amounts of spatial data and query them efficiently. You can consider using GridIndex2D instead for small grids with one-dimensional objects only. A quadtree is a tree data structure in which each internal node has exactly four children. Quadtrees are the two-dimensional analog of octrees and are most often used to partition a two-dimensional space by recursively subdividing it into four quadrants or regions.
-
-
Field Summary
-
Fields inherited from interface de.extio.spacecraft.shared.world.SpatialIndex2D
SESSION
-
-
Constructor Summary
Constructors Constructor Description QuadTree()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(T obj)Adds an object to the indexvoidclear()Clears but keeps internal state allocated.voidclose()Clears and frees internal statevoidexecuteAt(CoordI2 position, Consumer<T> consumer, Predicate<T> filter)Executes a consumer for all objects at a given position.List<T>find(CoordI2 position, CoordI2 dimension, Predicate<T> filter)Queries all object intersecting with a given area.TfindFirstAt(CoordI2 position, Predicate<T> filter)Returns the first object at a given position.voidforEach(Consumer<? super T> action)booleanintersects(RectI2 rect0, RectI2 rect1)booleanintersects(de.extio.spacecraft.shared.world.QuadTree.Node<T> node, RectI2 rect)booleanintersects(T obj, RectI2 rect)Iterator<T>iterator()voidmove(T obj, CoordI2 oldPosition, CoordI2 oldDimension)Moves an indexed object to a new location.voidremove(T obj)Removes an object from the index-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
spliterator
-
Methods inherited from interface de.extio.spacecraft.shared.world.SpatialIndex2D
executeAt, find, find, find, findFirstAt
-
-
-
-
Method Detail
-
add
public void add(T obj)
Description copied from interface:SpatialIndex2DAdds an object to the index- Specified by:
addin interfaceSpatialIndex2D<T extends SpatialIndex2Capable>
-
remove
public void remove(T obj)
Description copied from interface:SpatialIndex2DRemoves an object from the index- Specified by:
removein interfaceSpatialIndex2D<T extends SpatialIndex2Capable>
-
move
public void move(T obj, CoordI2 oldPosition, CoordI2 oldDimension)
Description copied from interface:SpatialIndex2DMoves an indexed object to a new location. Implementations are usually faster than doing separate remove() and add() operations- Specified by:
movein interfaceSpatialIndex2D<T extends SpatialIndex2Capable>
-
find
public List<T> find(CoordI2 position, CoordI2 dimension, Predicate<T> filter)
Description copied from interface:SpatialIndex2DQueries all object intersecting with a given area. Objects can be pre-filtered which is usually faster than returning them first and then filter in your own code.- Specified by:
findin interfaceSpatialIndex2D<T extends SpatialIndex2Capable>
-
findFirstAt
public T findFirstAt(CoordI2 position, Predicate<T> filter)
Description copied from interface:SpatialIndex2DReturns the first object at a given position. Objects can be pre-filtered which is usually faster than returning them first and then filter in your own code.- Specified by:
findFirstAtin interfaceSpatialIndex2D<T extends SpatialIndex2Capable>
-
executeAt
public void executeAt(CoordI2 position, Consumer<T> consumer, Predicate<T> filter)
Description copied from interface:SpatialIndex2DExecutes a consumer for all objects at a given position. Objects can be pre-filtered which is usually faster than returning them first and then filter in your own code.- Specified by:
executeAtin interfaceSpatialIndex2D<T extends SpatialIndex2Capable>
-
iterator
public Iterator<T> iterator()
- Specified by:
iteratorin interfaceIterable<T extends SpatialIndex2Capable>
-
forEach
public void forEach(Consumer<? super T> action)
- Specified by:
forEachin interfaceIterable<T extends SpatialIndex2Capable>
-
close
public void close()
Description copied from interface:SpatialIndex2DClears and frees internal state- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceSpatialIndex2D<T extends SpatialIndex2Capable>
-
clear
public void clear()
Description copied from interface:SpatialIndex2DClears but keeps internal state allocated. Optimization for re-use.- Specified by:
clearin interfaceSpatialIndex2D<T extends SpatialIndex2Capable>
-
intersects
public boolean intersects(de.extio.spacecraft.shared.world.QuadTree.Node<T> node, RectI2 rect)
-
-