|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.threerings.tudey.space.Space
com.threerings.tudey.space.HashSpace
public class HashSpace
A space that uses a hybrid spatial hashing/quadtree scheme to store elements.
| Nested Class Summary | |
|---|---|
protected class |
HashSpace.InternalNode<T extends SpaceObject>
An internal node with (up to) four children. |
protected class |
HashSpace.LeafNode<T extends SpaceObject>
A leaf node. |
protected class |
HashSpace.Node<T extends SpaceObject>
Represents a node in a quadtree. |
| Field Summary | |
|---|---|
protected Rect |
_bounds
The bounds of the roots (does not include the oversized objects). |
protected Coord |
_coord
A reusable coord object for queries. |
protected HashMap<Coord,HashSpace.Node<SpaceElement>> |
_elements
The top level element nodes. |
protected float |
_granularity
The size of the root nodes. |
protected List<HashSpace.InternalNode> |
_internalNodePool
A pool of internal nodes to reuse. |
protected List<HashSpace.LeafNode> |
_leafNodePool
A pool of leaf nodes to reuse. |
protected int |
_levels
The (maximum) number of tree levels. |
protected Coord |
_maxCoord
The maximum coordinate. |
protected Coord |
_minCoord
The minimum coordinate. |
protected ArrayList<SpaceElement> |
_oversizedElements
Oversized elements. |
protected Vector2f |
_pt
Reusable location vector. |
protected Rect |
_rect
A reusable rect. |
protected int |
_visit
The visit counter. |
| Fields inherited from class com.threerings.tudey.space.Space |
|---|
_disposed, _result |
| Constructor Summary | |
|---|---|
HashSpace(float granularity,
int levels)
Creates a new hash space. |
|
| Method Summary | ||
|---|---|---|
protected
|
add(HashMap<Coord,HashSpace.Node<T>> roots,
ArrayList<T> oversized,
T object)
Adds the specified object to the provided map. |
|
protected
|
addBounds(Coord coord,
HashSpace.Node<T> node)
Adds the bounds of the specified coordinate/node mapping. |
|
protected
|
addBounds(HashMap<Coord,HashSpace.Node<T>> roots)
Adds the bounds of the specified roots. |
|
protected void |
addToSpatial(SpaceElement element)
Adds an element to the space's spatial data structure. |
|
protected boolean |
areOversized(Rect bounds)
Determines whether the specified bounds qualify as "oversized" with respect to the scene granularity. |
|
void |
boundsDidChange(SpaceElement element)
Notes that the specified space element's bounds have changed. |
|
void |
boundsWillChange(SpaceElement element)
Notes that the specified space element's bounds are about to change. |
|
protected
|
createRoot(int x,
int y)
Creates a root node for the specified coordinates. |
|
void |
getElements(Rect bounds,
Collection<SpaceElement> results)
Retrieves all space elements whose bounds intersect the provided region. |
|
protected
|
getFromInternalNodePool(int levels)
Obtains an internal node through the pool. |
|
protected
|
getFromLeafNodePool()
Obtains a leaf node through the pool. |
|
protected
|
getFromNodePool(int levels)
Returns an internal or leaf node from the pool as appropriate for the number of remaining levels. |
|
protected
|
getIntersecting(HashMap<Coord,HashSpace.Node<T>> roots,
ArrayList<T> oversized,
Rect bounds,
Collection<T> results)
Adds all objects from the provided map that intersect the given bounds to the specified results list. |
|
void |
getIntersecting(Shape shape,
com.google.common.base.Predicate<? super SpaceElement> filter,
Collection<SpaceElement> results)
Retrieves all space elements that intersect the provided shape. |
|
SpaceElement |
getIntersection(Ray2D ray,
Vector2f location,
com.google.common.base.Predicate<? super SpaceElement> filter)
Checks for an intersection between the provided ray and the contents of the space. |
|
protected int |
getLevel(Rect bounds)
Returns the level for the supplied bounds. |
|
protected void |
recomputeBounds()
Recomputes the bounds of the roots. |
|
protected
|
remove(HashMap<Coord,HashSpace.Node<T>> roots,
ArrayList<T> oversized,
T object)
Removes the specified object from the provided map. |
|
protected void |
removeFromSpatial(SpaceElement element)
Removes an element from the space's spatial data structure. |
|
| Methods inherited from class com.threerings.tudey.space.Space |
|---|
add, dispose, getIntersecting, getIntersecting, getIntersecting, getIntersection, getIntersection, remove |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected float _granularity
protected int _levels
protected HashMap<Coord,HashSpace.Node<SpaceElement>> _elements
protected ArrayList<SpaceElement> _oversizedElements
protected Rect _bounds
protected Coord _minCoord
protected Coord _maxCoord
protected int _visit
protected Coord _coord
protected Rect _rect
protected Vector2f _pt
protected List<HashSpace.InternalNode> _internalNodePool
protected List<HashSpace.LeafNode> _leafNodePool
| Constructor Detail |
|---|
public HashSpace(float granularity,
int levels)
granularity - the size of the top-level cells.levels - the (maximum) number of quadtree levels.| Method Detail |
|---|
public SpaceElement getIntersection(Ray2D ray,
Vector2f location,
com.google.common.base.Predicate<? super SpaceElement> filter)
Space
getIntersection in class Spacelocation - a vector to populate with the location of the intersection, if any.filter - a predicate to use in filtering the results of the test.
null for
none.
public void getIntersecting(Shape shape,
com.google.common.base.Predicate<? super SpaceElement> filter,
Collection<SpaceElement> results)
Space
getIntersecting in class Spaceresults - a collection to hold the results of the search.
public void getElements(Rect bounds,
Collection<SpaceElement> results)
Space
getElements in class Spaceresults - a list to hold the results of the search.public void boundsWillChange(SpaceElement element)
SpaceSpace.boundsDidChange(SpaceElement) when the change has been effected.
boundsWillChange in class Spacepublic void boundsDidChange(SpaceElement element)
Space
boundsDidChange in class Spaceprotected void addToSpatial(SpaceElement element)
Space
addToSpatial in class Spaceprotected void removeFromSpatial(SpaceElement element)
Space
removeFromSpatial in class Space
protected <T extends SpaceObject> void add(HashMap<Coord,HashSpace.Node<T>> roots,
ArrayList<T> oversized,
T object)
protected <T extends SpaceObject> void remove(HashMap<Coord,HashSpace.Node<T>> roots,
ArrayList<T> oversized,
T object)
protected boolean areOversized(Rect bounds)
protected <T extends SpaceObject> void getIntersecting(HashMap<Coord,HashSpace.Node<T>> roots,
ArrayList<T> oversized,
Rect bounds,
Collection<T> results)
protected int getLevel(Rect bounds)
protected <T extends SpaceObject> HashSpace.Node<T> createRoot(int x,
int y)
protected void recomputeBounds()
protected <T extends SpaceObject> void addBounds(HashMap<Coord,HashSpace.Node<T>> roots)
protected <T extends SpaceObject> void addBounds(Coord coord,
HashSpace.Node<T> node)
protected <T extends SpaceObject> HashSpace.Node<T> getFromNodePool(int levels)
protected <T extends SpaceObject> HashSpace.InternalNode<T> getFromInternalNodePool(int levels)
protected <T extends SpaceObject> HashSpace.LeafNode<T> getFromLeafNodePool()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||