四叉树QuadTree源码
QuadTree.h源码
#include "stdafx.h"
#include <list>
using namespace std ;
struct QuadAABB
{
public :
int left;
int top;
int width;
int height;
int right;
int bottom;
QuadAABB()
{
left = right = top = bottom = width = height =0 ;
}
QuadAABB(int left, int top, int width, int height)
{
this ->left = left;
this ->top = top;
this ->width = width;
this ->height = height;
this ->right = left + width;
this ->bottom = top + height;
}
bool isContain(QuadAABB aabb)
{
return aabb.left >= left && aabb.right <=right && aabb.top>=top && aabb.bottom <= bottom;
}
bool isEqual(QuadAABB aabb)
{
return aabb.left == left && aabb.right ==right && aabb.top==top && aabb.bottom == bottom;
}
bool isIntersect(QuadAABB aabb)
{
int nleft = aabb.left > left ?aabb.left:left;
int nright = aabb.right < right ? aabb.right : right;
int ntop = aabb.top > top ? aabb.top:top;
int nbottom = aabb.bottom < bottom ? aabb.bottom:bottom;
return nleft < nright && ntop < nbottom;
}
};
template <typename T> class QuadTreeNode
{
public :
static