A* Pathfinding Project  4.0.6
The A* Pathfinding Project for Unity 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Events Macros Groups Pages
GridLookup< T > Class Template Reference

Holds a lookup datastructure to quickly find objects inside rectangles. More...

Detailed Description

Holds a lookup datastructure to quickly find objects inside rectangles.

Objects of type T occupy an integer rectangle in the grid and they can be moved efficiently. You can query for all objects that touch a specified rectangle that runs in O(m*k) time where m is the number of objects that the query returns and k is the average number of cells that an object occupies.

All objects must be contained within a rectangle with one point at the origin (inclusive) and one at size (exclusive) that is specified in the constructor.

Type Constraints
T :class 

Classes

class  Item
 
class  Root
 

Public Member Functions

 GridLookup (Int2 size)
 
Root Add (T item, IntRect bounds)
 Add an object to the lookup data structure.
 
Root GetRoot (T item)
 
void Move (T item, IntRect bounds)
 Move an object to occupy a new set of cells.
 
List< U > QueryRect< U > (IntRect r)
 Returns all objects of a specific type inside the cells marked by the rectangle.
 
void Remove (T item)
 Removes an item from the lookup data structure.
 

Properties

Root AllItems [get]
 Linked list of all items.
 

Private Attributes

Root all = new Root()
 Linked list of all items.
 
Item[] cells
 
Stack< Item > itemPool = new Stack<Item>()
 
Dictionary< T, Root > rootLookup = new Dictionary<T, Root>()
 
Int2 size
 

Constructor & Destructor Documentation

GridLookup ( Int2  size)

Member Function Documentation

Root Add ( item,
IntRect  bounds 
)

Add an object to the lookup data structure.

Returns
A handle which can be used for Move operations
Root GetRoot ( item)
void Move ( item,
IntRect  bounds 
)

Move an object to occupy a new set of cells.

List<U> QueryRect< U > ( IntRect  r)

Returns all objects of a specific type inside the cells marked by the rectangle.

Note
For better memory usage, consider pooling the list using Pathfinding.Util.ListPool after you are done with it
Type Constraints
U :class 
U :T 
void Remove ( item)

Removes an item from the lookup data structure.

Member Data Documentation

Root all = new Root()
private

Linked list of all items.

Note that the first item in the list is a dummy item and does not contain any data.

Item [] cells
private
Stack<Item> itemPool = new Stack<Item>()
private
Dictionary<T, Root> rootLookup = new Dictionary<T, Root>()
private
Int2 size
private

Property Documentation

Root AllItems
get

Linked list of all items.


The documentation for this class was generated from the following file: