Newer
Older
namespace nbody {
using namespace std;
for (int i = 0; i < 3; i++) {
this->bb.setMin(i, 1.0);
this->bb.setMax(i, -1.0);
this->prevSibling = NULL;
this->nextSibling = NULL;
this->parent = NULL;
void Node::setBB(Box bb) {
this->bb = bb;
}
if (this->bodies.size() < this->tree->maxLeafBodies + 1) {
node->next = this;
node->prev = this->prev;
this->prev->next = node;
this->prev = node;
}
this->next->prev = this->prev;
this->prev->next = this->next;
this->next = this;
this->prev = this;
}
if (this->afterSubtree == NULL) {
cout << "after subtree null" << endl;
return false;
}
if (!this->bb.isCorrect()) {
cout << "bb wrong" << endl;
return false;
}
if (this->bb.getMin(i) > this->bb.getMax(i)) {
cout << "bb " << i << " min " << this->bb.getMin(i) << " " << this->bb.getMax(i) << endl;
return false;
}
}
for (vector<Body>::iterator it = this->bodies.begin(); it != this->bodies.end(); it++) {
if (!this->bb.isContained(*it)) {
cout << "bb out of bounds" << endl;
return false;
}
}
while (current != NULL && current != this->afterSubtree) {
current = current->afterSubtree;
children++;
}
if (current == NULL) {
cout << "afterSubtree null" << endl;
return false;
}
if (children != this->tree->numberOfChildren()) {
cout << "wrong number of children " << children << endl;
return false;
}
current = this->next;
for (int i = 0; i < this->tree->numberOfChildren(); i++) {
current = current->afterSubtree;
}
if (current != this->afterSubtree) {
cout << "last sibling afterSubtree inconsistent" << endl;
return false;
}
}
if (!this->leaf && this->bodies.size() > 0) {
void Node::update() {
double position[3] = {0.0, 0.0, 0.0};
double mass = 0.0;
for (vector<Body>::iterator it = this->bodies.begin(); it != this->bodies.end(); it++) {
position[i] += it->position[i] * it->mass;
}
}
} else {
for (Node* node = this->next; node != this->tree->nodes && node != NULL; node = node->afterSubtree) {
mass += node->representative.mass;
this->representative.position[i] = position[i] / mass;
}
double Node::getL() {
return this->bb.maxSidelength();
this->bb.print();
for (vector<Body>::iterator it = this->bodies.begin(); it != this->bodies.end(); it++) {
cout << " ";
it->print();
}
}
bool Node::sufficientForBody(Body body) {
double distance = 0.0;
for (int i = 0; i < 3; i++) {
distance += (this->representative.position[i] - body.position[i]) * (this->representative.position[i] - body.position[i]);
}
return sqrt(distance) > this->getL();
}
bool Node::sufficientForBox(Box box) {
return this->bb.distanceToBox(box) > this->getL();
}
void Node::setBodies(vector<Body> bodies) {
this->bodies = bodies;
}