ForgeDocs
Documentation for the forge framework
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
Forge.Collections.QuadTree< TItem > Class Template Reference

Implements a QuadTree, which supports spatial monitoring and spatial querying of positionable objects. The objects can be positioned anywhere, even at negative coordinates. More...

Public Member Functions

 QuadTree (int worldScale=100)
 Constructs a new QuadTree that is empty. More...
 
void AddItem (TItem item, Vector2r position)
 Add a new item to the QuadTree at the given position. More...
 
void UpdateItem (TItem item, Vector2r previous, Vector2r current)
 Update the position of an item. This will notify monitors of position updates. More...
 
void RemoveItem (TItem item, Vector2r position)
 Remove an item from the QuadTree. More...
 
TCollection CollectItems< TCollection > (Bound region, TCollection storage=null)
 Collect all items that are stored inside of the given region. More...
 
void AddMonitor (IQuadTreeMonitor< TItem > monitor, Bound monitoredRegion)
 Inserts the given monitor into the QuadTree. The monitor will be notified of any entities that enter or leave it. The monitor can be updated or removed. More...
 
void RemoveMonitor (IQuadTreeMonitor< TItem > monitor, Bound monitoredRegion)
 Removes the given monitor from the quad tree. It will receive a series of OnExit calls during this Remove call. More...
 
void UpdateMonitor (IQuadTreeMonitor< TItem > monitor, Bound previousRegion, Bound currentRegion)
 Update the position of a monitor. More...
 

Properties

IEnumerable< IQuadTreeMonitor
< TItem > > 
Monitors [get]
 Returns all monitors that are stored in the tree. More...
 
IEnumerable< TItem > Items [get]
 Returns all items that are stored in the tree. More...
 

Detailed Description

Implements a QuadTree, which supports spatial monitoring and spatial querying of positionable objects. The objects can be positioned anywhere, even at negative coordinates.

In regards to implementation details, this is not currently a recursive QuadTree. Instead, the world is divided into a set of chunks which can be queried directly. The size of these chunks can be controlled by the constructor parameter.

Template Parameters
TThe type of object stored in the QuadTree

Constructor & Destructor Documentation

Forge.Collections.QuadTree< TItem >.QuadTree ( int  worldScale = 100)

Constructs a new QuadTree that is empty.

Parameters
worldScaleThe size of each node inside of the tree. A larger value will result in faster queries over large areas, but a smaller value will result in faster queries over a smaller area. In general, this should be close to your typical query size.

Member Function Documentation

void Forge.Collections.QuadTree< TItem >.AddItem ( TItem  item,
Vector2r  position 
)

Add a new item to the QuadTree at the given position.

Parameters
itemThe item to add.
positionThe position of the item.
void Forge.Collections.QuadTree< TItem >.AddMonitor ( IQuadTreeMonitor< TItem >  monitor,
Bound  monitoredRegion 
)

Inserts the given monitor into the QuadTree. The monitor will be notified of any entities that enter or leave it. The monitor can be updated or removed.

Parameters
monitorThe monitor.
monitoredRegionThe area that the monitor is viewing.
TCollection Forge.Collections.QuadTree< TItem >.CollectItems< TCollection > ( Bound  region,
TCollection  storage = null 
)

Collect all items that are stored inside of the given region.

Parameters
regionThe area to collect entities from.
storageWhere to store the collected entities.
Template Parameters
TCollectionThe type of collection to store items in.
Returns
All entities that are contained in or intersecting with the given region.
Type Constraints
TCollection :class 
TCollection :ICollection<TItem> 
TCollection :new() 
void Forge.Collections.QuadTree< TItem >.RemoveItem ( TItem  item,
Vector2r  position 
)

Remove an item from the QuadTree.

Parameters
itemThe item to remove.
positionThe position of the item.
void Forge.Collections.QuadTree< TItem >.RemoveMonitor ( IQuadTreeMonitor< TItem >  monitor,
Bound  monitoredRegion 
)

Removes the given monitor from the quad tree. It will receive a series of OnExit calls during this Remove call.

Parameters
monitorThe monitor to remove.
monitoredRegionThe region that the monitor was monitoring.
void Forge.Collections.QuadTree< TItem >.UpdateItem ( TItem  item,
Vector2r  previous,
Vector2r  current 
)

Update the position of an item. This will notify monitors of position updates.

Parameters
itemThe item to update the position of.
previousThe old position of the item.
currentThe updated position of the item.
void Forge.Collections.QuadTree< TItem >.UpdateMonitor ( IQuadTreeMonitor< TItem >  monitor,
Bound  previousRegion,
Bound  currentRegion 
)

Update the position of a monitor.

Parameters
monitorThe monitor whose position has changed.
previousRegionThe previous area that the monitor was watching.
currentRegionThe new area that the monitor is watching.

Property Documentation

IEnumerable<TItem> Forge.Collections.QuadTree< TItem >.Items
get

Returns all items that are stored in the tree.

IEnumerable<IQuadTreeMonitor<TItem> > Forge.Collections.QuadTree< TItem >.Monitors
get

Returns all monitors that are stored in the tree.


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