-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
84 lines (65 loc) · 1.82 KB
/
main.cpp
File metadata and controls
84 lines (65 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "QuadTree.h"
#include <stdio.h>
#include <math.h>
#include <conio.h>
#include <vector>
struct TreeVisitor
{
QuadTree* tree;
void operator()(const QuadIterator& it)
{
printf("visiting adress: %u, absolute: %u\n", it.my_adress, uint32(it.current() - tree->Nodes()));
}
};
#define check(expr)\
if ((bool)(expr) == false)\
printf("expression " #expr " failed\n");
void QuadTree::debugSelf()
{
uint8 depth = 10;
check( QuadTree::NodesPerLevelAmount(depth) == (uint64)pow(2.f, (int)(2*depth)) );
check( QuadTree::NodesAmount(depth) == (uint64) ((pow(2.f,(int)(2*depth+2))) -1u) / 3u );
Node * end = this->nodes + NodesAmount(this->m_depth);
for (Node * i = this->nodes; i != end; ++i)
check(i->xDiv != DBG_WORD);
std::vector<QuadTree::Node> array(this->nodes, end);
}
void testDivision()
{
SpaceDivision div = {100, 100};
Circle c = {99, 99, 2};
AABox2d box = AABox2d::create(c);
check( div.intersectionQuadrants(box) == div.intersection(box));
}
class Timer
{
public:
typedef unsigned __int64 rt_time;
explicit Timer() { reset();}
rt_time passed() const { return now() - start;}
void reset() { start = now();}
private:
static rt_time now()
{
__asm rdtsc;
}
rt_time start;
};
int main()
{
testDivision();
length_type MAP_SIZE = length_type(64.f * 533.333f);
Point center = {MAP_SIZE/2, MAP_SIZE/2};
QuadTree * tree = QuadTree::create(8, center, MAP_SIZE);
if (!tree)
return 0;
tree->debugSelf();
Circle c = {MAP_SIZE/2, MAP_SIZE/2, 1};
TreeVisitor visitor = {tree};
AABox2d box(AABox2d::create(c));
tree->intersectRecursive(box, visitor);
tree->intersect(box, visitor);
QuadIterator it = tree->deepestContaining(AABox2d::create(c));
_getch();
return 0;
}