com.threerings.tudey.space
Class Space

java.lang.Object
  extended by com.threerings.tudey.space.Space
Direct Known Subclasses:
HashSpace, SimpleSpace

public abstract class Space
extends Object

Base class for spaces.


Field Summary
protected  boolean _disposed
          Set when we've been disposed.
protected  Vector2f _result
          Result vector for intersection testing.
 
Constructor Summary
Space()
           
 
Method Summary
 void add(SpaceElement element)
          Adds an element to this space.
protected abstract  void addToSpatial(SpaceElement element)
          Adds an element to the space's spatial data structure.
 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.
 void dispose()
          Flags this space as having been disposed.
abstract  void getElements(Rect bounds, Collection<SpaceElement> results)
          Retrieves all space elements whose bounds intersect the provided region.
protected static void getIntersecting(ArrayList<SpaceElement> elements, Shape shape, com.google.common.base.Predicate<? super SpaceElement> filter, Collection<SpaceElement> results)
          Adds all elements from the provided list that intersect the given shape to the specified results collection.
protected static
<T extends SpaceObject>
void
getIntersecting(ArrayList<T> objects, Rect bounds, Collection<T> results)
          Adds all objects from the provided list that intersect the given bounds to the specified results list.
 void getIntersecting(Shape shape, Collection<SpaceElement> results)
          Retrieves all space elements that intersect the provided shape.
abstract  void getIntersecting(Shape shape, com.google.common.base.Predicate<? super SpaceElement> filter, Collection<SpaceElement> results)
          Retrieves all space elements that intersect the provided shape.
protected  SpaceElement getIntersection(ArrayList<SpaceElement> elements, Ray2D ray, Vector2f location, com.google.common.base.Predicate<? super SpaceElement> filter)
          Searches for an intersection with the supplied elements.
 SpaceElement getIntersection(Ray2D ray, Vector2f location)
          Checks for an intersection between the provided ray and the contents of the space.
abstract  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.
 void remove(SpaceElement element)
          Removes an element from the space.
protected abstract  void removeFromSpatial(SpaceElement element)
          Removes an element from the space's spatial data structure.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_disposed

protected boolean _disposed
Set when we've been disposed.


_result

protected Vector2f _result
Result vector for intersection testing.

Constructor Detail

Space

public Space()
Method Detail

add

public void add(SpaceElement element)
Adds an element to this space.


remove

public void remove(SpaceElement element)
Removes an element from the space.


getIntersection

public SpaceElement getIntersection(Ray2D ray,
                                    Vector2f location)
Checks for an intersection between the provided ray and the contents of the space.

Parameters:
location - a vector to populate with the location of the intersection, if any.
Returns:
a reference to the first element intersected by the ray, or null for none.

getIntersection

public abstract 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.

Parameters:
filter - a predicate to use in filtering the results of the test.
location - a vector to populate with the location of the intersection, if any.
Returns:
a reference to the first element intersected by the ray, or null for none.

getIntersecting

public void getIntersecting(Shape shape,
                            Collection<SpaceElement> results)
Retrieves all space elements that intersect the provided shape.

Parameters:
results - a collection to hold the results of the search.

getIntersecting

public abstract void getIntersecting(Shape shape,
                                     com.google.common.base.Predicate<? super SpaceElement> filter,
                                     Collection<SpaceElement> results)
Retrieves all space elements that intersect the provided shape.

Parameters:
results - a collection to hold the results of the search.

getElements

public abstract void getElements(Rect bounds,
                                 Collection<SpaceElement> results)
Retrieves all space elements whose bounds intersect the provided region.

Parameters:
results - a list to hold the results of the search.

boundsWillChange

public void boundsWillChange(SpaceElement element)
Notes that the specified space element's bounds are about to change. Will be followed by a call to boundsDidChange(SpaceElement) when the change has been effected.


boundsDidChange

public void boundsDidChange(SpaceElement element)
Notes that the specified space element's bounds have changed.


dispose

public void dispose()
Flags this space as having been disposed.


addToSpatial

protected abstract void addToSpatial(SpaceElement element)
Adds an element to the space's spatial data structure.


removeFromSpatial

protected abstract void removeFromSpatial(SpaceElement element)
Removes an element from the space's spatial data structure.


getIntersection

protected SpaceElement getIntersection(ArrayList<SpaceElement> elements,
                                       Ray2D ray,
                                       Vector2f location,
                                       com.google.common.base.Predicate<? super SpaceElement> filter)
Searches for an intersection with the supplied elements.


getIntersecting

protected static void getIntersecting(ArrayList<SpaceElement> elements,
                                      Shape shape,
                                      com.google.common.base.Predicate<? super SpaceElement> filter,
                                      Collection<SpaceElement> results)
Adds all elements from the provided list that intersect the given shape to the specified results collection.


getIntersecting

protected static <T extends SpaceObject> void getIntersecting(ArrayList<T> objects,
                                                              Rect bounds,
                                                              Collection<T> results)
Adds all objects from the provided list that intersect the given bounds to the specified results list.