|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.gicentre.utils.geom.HashGrid<E>
E
- Type of locatable objects stored in the hash grid.public class HashGrid<E extends Locatable>
Class to allow the division of a set of 2d spatial objects into a coarser grid for
efficient spatial indexing. The collection is a set, so will contain a unique set of
objects. Efficient retrieval is achieved by using the get()
method that
will return only those items that are within a fixed distance of a given location. That
fixed distance is determined by the radius of the hash grid. The radius should be
set to the maximum search distance that an application is likely to need when performing
a spatial query. Generally, the smaller the radius the quicker the retrieval.
Constructor Summary | |
---|---|
HashGrid(float maxX,
float maxY,
float radius)
Creates a hash grid capable of storing items located within a rectangle between (0,0) and ( maxX ,maxY ) with a grid resolution determined by the radius . |
|
HashGrid(float minX,
float minY,
float maxX,
float maxY,
float radius)
Creates a hash grid capable of storing items located within a rectangle between ( minX ,minY )
and (maxX ,maxY ) with a grid resolution determined by the radius . |
Method Summary | ||
---|---|---|
boolean |
add(E obj)
Adds a locatable object to the grid. |
|
boolean |
add(E obj,
Locatable loc)
Adds a locatable object to the grid. |
|
boolean |
addAll(java.util.Collection<? extends E> collection)
Adds a collection of locatable objects to the hash grid. |
|
void |
clear()
Clears out the contents of the grid. |
|
boolean |
contains(E obj,
processing.core.PVector location)
Reports whether the hash grid contains the given locatable object within the radius of the given location. |
|
boolean |
contains(java.lang.Object obj)
Reports whether the hash grid contains the given object. |
|
boolean |
containsAll(java.util.Collection<?> collection)
Reports whether the hash grid contains all of the objects contained in the given collection. |
|
boolean |
equals(java.lang.Object obj)
Reports whether this collection is equal to the given object. |
|
java.util.Set<E> |
get(processing.core.PVector location)
Returns a collection of the locatable objects that are within the radius of
the given location. |
|
java.util.Set<E> |
getAll()
Returns a set of all objects stored in the hash grid. |
|
processing.core.PVector |
getGridCoord(processing.core.PVector location)
Provides the hqshgrid coordinates of the given location. |
|
int |
hashCode()
Reports the hash code of the entire collection. |
|
boolean |
isEmpty()
Reports whether or not this hash grid contains any elements. |
|
java.util.Iterator<E> |
iterator()
Provides an iterator to iterate through all the items stored in this hash grid. |
|
boolean |
remove(java.lang.Object obj)
Removes the given object from the hash grid. |
|
boolean |
removeAll(java.util.Collection<?> collection)
Removes the objects in the given collection from the hash grid. |
|
boolean |
retainAll(java.util.Collection<?> collection)
Would strip all items from the hash grid apart from those contained in the given collection but is currently not supported by the hash grid. |
|
int |
size()
Reports the number of unique items stored in this hash grid. |
|
java.lang.Object[] |
toArray()
Provides an array representation of the items in this hash grid. |
|
|
toArray(T[] a)
Provides an array representation of the items in this hash grid. |
|
void |
update(E obj)
Updates the positions of the given item in the hash grid so that its gridded location reflects its new location. |
|
void |
updateAll()
Updates the positions of all items in the hash grid so that their gridded location reflects the location stored inside the Locatable objects. |
|
void |
updateAll(float newRadius)
Updates the positions of all items in the hash grid so that their gridded location reflects the location stored inside the Locatable objects. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HashGrid(float maxX, float maxY, float radius)
maxX
,maxY
) with a grid resolution determined by the radius
.
maxX
- Largest x coordinate of locatable objects.maxY
- Largest y coordinate of locatable objects.radius
- Size of 1 grid cell in the same units as the preceding min and max parameters. If 0 or negative
the HashGrid defaults to a radius of one tenth of the width of the grid. For optimum performance,
the radius should be set to the maximum search distance of any spatial object detection. If it
is set to be less than this, some adjacent neighbours may be missed when searching. If greater
than this, searching will return more neighbours than necessary and impede performance for
dense collections of locatable objects.public HashGrid(float minX, float minY, float maxX, float maxY, float radius)
minX
,minY
)
and (maxX
,maxY
) with a grid resolution determined by the radius
.
minX
- Smallest x coordinate of locatable objects.minY
- Smallest y coordinate of locatable objects.maxX
- Largest x coordinate of locatable objects.maxY
- Largest y coordinate of locatable objects.radius
- Size of 1 grid cell in the same units as the preceding min and max parameters. If 0 or negative
the HashGrid defaults to a radius of one tenth of the width of the grid. For optimum performance,
the radius should be set to the maximum search distance of any spatial object detection. If it
is set to be less than this, some adjacent neighbours may be missed when searching. If greater
than this, searching will return more neighbours than necessary and impede performance for
dense collections of locatable objects.Method Detail |
---|
public java.util.Set<E> get(processing.core.PVector location)
radius
of
the given location. radius
is that defined in the constructor or by the most
recent call to updateAll(radius)
.
location
- Location to query.
public boolean contains(E obj, processing.core.PVector location)
obj
- Object to search for.location
- Location to query.
public java.util.Set<E> getAll()
public void updateAll()
Locatable
objects. This method
is useful if all or many of the objects have changed location since being added to
the hash grid. If only one object has changed consider calling update(E obj)
.
public void updateAll(float newRadius)
Locatable
objects. This version
also sets a new grid resolution implied by the newRadius
value. This should
represent the maximum search distance used when calling get(PVector)
.
newRadius
- New grid cell radius corresponding to maximum search distance. No change
to the radius is made if the value is 0 or negative.public void update(E obj)
Locatable
object has
changed its position, but most of the other objects in the hash grid have not.
obj
- Locatable object to be updated.public boolean add(E obj)
Locatable
interface, otherwise a ClassCastException
will be thrown.
add
in interface java.util.Collection<E extends Locatable>
add
in interface java.util.Set<E extends Locatable>
obj
- Locatable object to add to the hash grid.
public boolean add(E obj, Locatable loc)
add(E)
this allows a locatable
object to be added at a location other than it's 'natural' one. Note that the object being
added must implement the Locatable
interface, otherwise a ClassCastException
will be thrown.
obj
- Locatable object to add to the hash grid.loc
- Location of the object to add to the grid.
public boolean addAll(java.util.Collection<? extends E> collection)
addAll
in interface java.util.Collection<E extends Locatable>
addAll
in interface java.util.Set<E extends Locatable>
collection
- Collection of objects to add to the collection.
public void clear()
clear
in interface java.util.Collection<E extends Locatable>
clear
in interface java.util.Set<E extends Locatable>
public boolean contains(java.lang.Object obj)
contains(obj,location)
instead to limit search to
within the search radius.
contains
in interface java.util.Collection<E extends Locatable>
contains
in interface java.util.Set<E extends Locatable>
obj
- Object to search for.
public boolean containsAll(java.util.Collection<?> collection)
get(location)
and search the returned collection.
containsAll
in interface java.util.Collection<E extends Locatable>
containsAll
in interface java.util.Set<E extends Locatable>
collection
- Collection of objects to search for.
public boolean equals(java.lang.Object obj)
HashGrid
the comparison is performed on the Set
s contained in the hash grids. In other words, it is independent
of the spatial locations of the objects stored in the hash grid. The only other type of object that could possibly
return true
would be a Set
.
equals
in interface java.util.Collection<E extends Locatable>
equals
in interface java.util.Set<E extends Locatable>
equals
in class java.lang.Object
obj
- Object to compare with this hash grid.
public int hashCode()
hashCode
in interface java.util.Collection<E extends Locatable>
hashCode
in interface java.util.Set<E extends Locatable>
hashCode
in class java.lang.Object
public boolean isEmpty()
isEmpty
in interface java.util.Collection<E extends Locatable>
isEmpty
in interface java.util.Set<E extends Locatable>
public java.util.Iterator<E> iterator()
get(location)
in some spatial order and then iterate though the resulting collections.
iterator
in interface java.lang.Iterable<E extends Locatable>
iterator
in interface java.util.Collection<E extends Locatable>
iterator
in interface java.util.Set<E extends Locatable>
public boolean remove(java.lang.Object obj)
remove
in interface java.util.Collection<E extends Locatable>
remove
in interface java.util.Set<E extends Locatable>
obj
- Object to remove.public boolean removeAll(java.util.Collection<?> collection)
removeAll
in interface java.util.Collection<E extends Locatable>
removeAll
in interface java.util.Set<E extends Locatable>
collection
- Collection of objects to remove.public boolean retainAll(java.util.Collection<?> collection)
get(location)
and perform the retainsAll()
on the returned collection.
retainAll
in interface java.util.Collection<E extends Locatable>
retainAll
in interface java.util.Set<E extends Locatable>
public int size()
size
in interface java.util.Collection<E extends Locatable>
size
in interface java.util.Set<E extends Locatable>
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection<E extends Locatable>
toArray
in interface java.util.Set<E extends Locatable>
public <T> T[] toArray(T[] a)
toArray
in interface java.util.Collection<E extends Locatable>
toArray
in interface java.util.Set<E extends Locatable>
public processing.core.PVector getGridCoord(processing.core.PVector location)
location
- The location to query.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |