forked from PWhiddy/Nbody-Gravity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOctant.cpp
91 lines (74 loc) · 1.59 KB
/
Octant.cpp
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
85
86
87
88
89
90
/*
* Octant.cpp
*
* Created on: Feb 3, 2016
* Author: peterwhidden
*/
#include "Constants.h"
class Octant
{
private:
vec3 mid;
double length;
public:
Octant(double x, double y, double z, double l): mid(x, y, z)
{
length = l;
}
Octant(Octant&& o): mid(std::move(o.mid)), length(std::move(o.length))
{
}
Octant(const Octant& o): mid(o.mid), length(o.length)
{
}
double getLength() const
{
return length;
}
inline bool contains(const vec3& p) const
{
return p.x<=mid.x+length/2.0 && p.x>=mid.x-length/2.0 &&
p.y<=mid.y+length/2.0 && p.y>=mid.y-length/2.0 &&
p.z<=mid.z+length/2.0 && p.z>=mid.z-length/2.0;
}
Octant mUNW() const
{
double newL = length/4.0;
return Octant(mid.x-newL, mid.y+newL, mid.z+newL, length/2.0);
}
Octant mUNE() const
{
double newL = length/4.0;
return Octant(mid.x+newL, mid.y+newL, mid.z+newL, length/2.0);
}
Octant mUSW() const
{
double newL = length/4.0;
return Octant(mid.x-newL, mid.y-newL, mid.z+newL, length/2.0);
}
Octant mUSE() const
{
double newL = length/4.0;
return Octant(mid.x+newL, mid.y-newL, mid.z+newL, length/2.0);
}
Octant mDNW() const
{
double newL = length/4.0;
return Octant(mid.x-newL, mid.y+newL, mid.z-newL, length/2.0);
}
Octant mDNE() const
{
double newL = length/4.0;
return Octant(mid.x+newL, mid.y+newL, mid.z-newL, length/2.0);
}
Octant mDSW() const
{
double newL = length/4.0;
return Octant(mid.x-newL, mid.y-newL, mid.z-newL, length/2.0);
}
Octant mDSE() const
{
double newL = length/4.0;
return Octant(mid.x+newL, mid.y-newL, mid.z-newL, length/2.0);
}
};