Package com.io7m.jspatial.implementation
Class QuadTreeL<T>
- java.lang.Object
-
- com.io7m.jspatial.implementation.QuadTreeL<T>
-
- Type Parameters:
T
- The precise type of tree objects
- All Implemented Interfaces:
QuadTreeLType<T>
,QuadTreeReadableLType<T>
,QuadTreeReadableType
public final class QuadTreeL<T> extends java.lang.Object implements QuadTreeLType<T>
Default implementation of theQuadTreeLType
interface.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
QuadTreeL.Quadrant
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description com.io7m.jregions.core.unparameterized.areas.AreaL
areaFor(T item)
com.io7m.jregions.core.unparameterized.areas.AreaL
bounds()
void
clear()
Remove all objects from the tree.void
containedBy(com.io7m.jregions.core.unparameterized.areas.AreaL area, java.util.Set<T> items)
Returns all objects in the tree that are completely contained withinarea
, saving the results toitems
.boolean
contains(T item)
Determine whether or not the object has already been inserted into the tree.static <T> QuadTreeLType<T>
create(QuadTreeConfigurationL config)
Create a new empty tree with the given bounds.boolean
equals(java.lang.Object o)
int
hashCode()
boolean
insert(T item, com.io7m.jregions.core.unparameterized.areas.AreaL item_bounds)
Insert the objectitem
into the quadtree.<C> void
iterateQuadrants(C context, QuadTreeQuadrantIterationLType<T,C> f)
Iterate over all quadrants within the tree.<U> QuadTreeLType<U>
map(java.util.function.BiFunction<T,com.io7m.jregions.core.unparameterized.areas.AreaL,U> f)
Applyf
to each element of the tree.void
overlappedBy(com.io7m.jregions.core.unparameterized.areas.AreaL area, java.util.Set<T> items)
Returns all objects in the tree that are overlappedarea
, saving the results toitems
.void
raycast(Ray2D ray, java.util.SortedSet<QuadTreeRaycastResultL<T>> items)
Returns all objects that are intersected by the given ray.boolean
remove(T item)
Remove the objectitem
from the quadtree.long
size()
void
trim()
Trim all empty quadrants from the tree.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.io7m.jspatial.api.quadtrees.QuadTreeReadableType
isEmpty
-
-
-
-
Method Detail
-
create
public static <T> QuadTreeLType<T> create(QuadTreeConfigurationL config)
Create a new empty tree with the given bounds.- Type Parameters:
T
- The type of objects contained within the tree- Parameters:
config
- The tree configuration- Returns:
- A new tree
-
trim
public void trim()
Description copied from interface:QuadTreeLType
Trim all empty quadrants from the tree.- Specified by:
trim
in interfaceQuadTreeLType<T>
-
size
public long size()
- Specified by:
size
in interfaceQuadTreeReadableType
- Returns:
- The number of elements in the tree
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
bounds
public com.io7m.jregions.core.unparameterized.areas.AreaL bounds()
- Specified by:
bounds
in interfaceQuadTreeReadableLType<T>
- Returns:
- The tree bounds
-
insert
public boolean insert(T item, com.io7m.jregions.core.unparameterized.areas.AreaL item_bounds)
Description copied from interface:QuadTreeLType
Insert the object
item
into the quadtree.The function returns
false
if the object could not be inserted for any reason (perhaps due to being too large).If the object is already in the tree, it is replaced. This can be used to update the bounds of an object within the tree.
- Specified by:
insert
in interfaceQuadTreeLType<T>
- Parameters:
item
- The object to insertitem_bounds
- The object's bounds- Returns:
true
if the object was inserted
-
contains
public boolean contains(T item)
Description copied from interface:QuadTreeReadableLType
Determine whether or not the object has already been inserted into the tree.- Specified by:
contains
in interfaceQuadTreeReadableLType<T>
- Parameters:
item
- The object- Returns:
true
iff the object is in the tree
-
remove
public boolean remove(T item)
Description copied from interface:QuadTreeLType
Remove the object
item
from the quadtree.The function returns
false
if the object could not be removed for any reason (perhaps due to not being in the tree in the first place).- Specified by:
remove
in interfaceQuadTreeLType<T>
- Parameters:
item
- The object to remove- Returns:
true
if the object was removed
-
clear
public void clear()
Description copied from interface:QuadTreeLType
Remove all objects from the tree.- Specified by:
clear
in interfaceQuadTreeLType<T>
-
map
public <U> QuadTreeLType<U> map(java.util.function.BiFunction<T,com.io7m.jregions.core.unparameterized.areas.AreaL,U> f)
Description copied from interface:QuadTreeLType
Applyf
to each element of the tree.- Specified by:
map
in interfaceQuadTreeLType<T>
- Specified by:
map
in interfaceQuadTreeReadableLType<T>
- Type Parameters:
U
- The type of result elements- Parameters:
f
- A mapping function- Returns:
- A new tree
-
iterateQuadrants
public <C> void iterateQuadrants(C context, QuadTreeQuadrantIterationLType<T,C> f)
Description copied from interface:QuadTreeReadableLType
Iterate over all quadrants within the tree.- Specified by:
iterateQuadrants
in interfaceQuadTreeReadableLType<T>
- Type Parameters:
C
- The type of context values- Parameters:
context
- A contextual value passed tof
f
- An iteration function
-
areaFor
public com.io7m.jregions.core.unparameterized.areas.AreaL areaFor(T item)
- Specified by:
areaFor
in interfaceQuadTreeReadableLType<T>
- Parameters:
item
- The item- Returns:
- The bounding area that was specified for
item
-
containedBy
public void containedBy(com.io7m.jregions.core.unparameterized.areas.AreaL area, java.util.Set<T> items)
Description copied from interface:QuadTreeReadableLType
Returns all objects in the tree that are completely contained withinarea
, saving the results toitems
.- Specified by:
containedBy
in interfaceQuadTreeReadableLType<T>
- Parameters:
area
- The area to examineitems
- The returned items
-
overlappedBy
public void overlappedBy(com.io7m.jregions.core.unparameterized.areas.AreaL area, java.util.Set<T> items)
Description copied from interface:QuadTreeReadableLType
Returns all objects in the tree that are overlappedarea
, saving the results toitems
.- Specified by:
overlappedBy
in interfaceQuadTreeReadableLType<T>
- Parameters:
area
- The area to examineitems
- The returned items
-
raycast
public void raycast(Ray2D ray, java.util.SortedSet<QuadTreeRaycastResultL<T>> items)
Description copied from interface:QuadTreeReadableLType
Returns all objects that are intersected by the given ray. The objects are returned in order of distance from the origin of the ray: The first object returned will be the object nearest to the origin.- Specified by:
raycast
in interfaceQuadTreeReadableLType<T>
- Parameters:
ray
- The rayitems
- The intersected items
-
-