Space Comps
 All Classes Files Functions Variables
Public Member Functions | List of all members
Quadtree Class Reference

The Quadtree data structure used in QuadtreeAlgorithm. More...

#include <quadtree.h>

Public Member Functions

 Quadtree (int levelIn, double nwXIn, double nwYIn, double seXIn, double seYIn)
 Constructs a Quadtree object. More...
 
void clear ()
 Clears the Quadtree. More...
 
void split ()
 Splits the Quadtree into 4 quadrants. More...
 
int getIndex (Particle *particle)
 Gets the index of a given Particle within a Quadtree. More...
 
void insertToTree (Particle *particle)
 Inserts a given Particle into a Quadtree. More...
 
std::vector< Particle * > * getPossibleColliders (std::vector< Particle * > *colliders, Particle *p)
 Returns a vector of Particles that may be colliding with a given Particle. More...
 

Detailed Description

The Quadtree data structure used in QuadtreeAlgorithm.

A Quadtree represents a rectangular section of space defined in the X,Y coordinate system.

Constructor & Destructor Documentation

Quadtree::Quadtree ( int  levelIn,
double  nwXIn,
double  nwYIn,
double  seXIn,
double  seYIn 
)

Constructs a Quadtree object.

Constructs a Quadtree object based on the given parameters.

Parameters
levelInthe level of the Quadtree object within the larger tree. The head of the tree is 0 and increases from there.
nwXInthe X coordinate of the upper left corner of the space represented by this level of the tree.
nwYInthe Y coordinate of the upper left corner of the space represented by this level of the tree.
seXInthe X coordinate of the bottom right corner of the space represented by this level of the tree.
seYInthe Y coordinate of the bottom right corner of the space represented by this level of the tree.

Member Function Documentation

void Quadtree::clear ( )

Clears the Quadtree.

Clears the Quadtree by recursively clearing nodeParticles at each level of the tree.

int Quadtree::getIndex ( Particle particle)

Gets the index of a given Particle within a Quadtree.

Gets the index of a given Particle within a Quadtree. An index of -1 means the Particle cannot fit completely within any of the 4 nodes. An index of 0, 1, 2, or 3 means the Particle fits completely within the cooresponding node.

Parameters
particlepointer to the Particle to get an index of.
Returns
index of a given Particle.
std::vector< Particle * > * Quadtree::getPossibleColliders ( std::vector< Particle * > *  colliders,
Particle p 
)

Returns a vector of Particles that may be colliding with a given Particle.

Returns a pointer to a vector of pointers to Particles that may be colliding with a given Particle.

Parameters
colliderspointer to the vector of Particles that may be colliding with a given Particle.
ppointer to the given Particle to check against.
Returns
pointer to the vector of pointers to Particles.
void Quadtree::insertToTree ( Particle particle)

Inserts a given Particle into a Quadtree.

Inserts a given Particle into a Quadtree. If the Particle is inserted into a level of the Quadtree that has more Particles than is allowed by MAX_PARTICLES_PER_LEVEL, Split() will be called on the node.

Parameters
particlepointer to the Particle to insert into a Quadtree.
void Quadtree::split ( )

Splits the Quadtree into 4 quadrants.

Splits the Quadtree into 4 quadrants and creates a new Quadtree for each quadrant.


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