/* * Box.cpp * * Created on: Jun 30, 2010 * Author: crueger */ //#include "Helpers/MemDebug.hpp" #include "Box.hpp" #include #include "Matrix.hpp" #include "vector.hpp" #include "Plane.hpp" #include "Helpers/Assert.hpp" Box::Box() { M= new Matrix(); M->one(); Minv = new Matrix(); Minv->one(); conditions.resize(3); conditions[0] = conditions[1] = conditions[2] = Wrap; } Box::Box(const Box& src){ M=new Matrix(*src.M); Minv = new Matrix(*src.Minv); conditions = src.conditions; } Box::~Box() { delete M; delete Minv; } const Matrix &Box::getM() const{ return *M; } const Matrix &Box::getMinv() const{ return *Minv; } void Box::setM(Matrix _M){ ASSERT(_M.determinant()!=0,"Matrix in Box construction was not invertible"); *M =_M; *Minv = M->invert(); } Vector Box::translateIn(const Vector &point) const{ return (*M) * point; } Vector Box::translateOut(const Vector &point) const{ return (*Minv) * point; } Vector Box::WrapPeriodically(const Vector &point) const{ Vector helper = translateOut(point); for(int i=NDIM;i--;){ switch(conditions[i]){ case Wrap: helper.at(i)=fmod(helper.at(i),1); helper.at(i)+=(helper.at(i)>0)?0:1; break; case Bounce: { // there probably is a better way to handle this... // all the fabs and fmod modf probably makes it very slow double intpart,fracpart; fracpart = modf(fabs(helper.at(i)),&intpart); helper.at(i) = fabs(fracpart-fmod(intpart,2)); } break; case Ignore: break; default: ASSERT(0,"No default case for this"); } } return translateIn(helper); } bool Box::isInside(const Vector &point) const { bool result = true; Vector tester = translateOut(point); for(int i=0;i= -MYEPSILON) && ((tester[i] - 1.) < MYEPSILON)); return result; } VECTORSET(std::list) Box::explode(const Vector &point,int n) const{ VECTORSET(std::list) res; // translate the Vector into each of the 27 neighbourhoods // first create all translation Vectors // there are (n*2+1)^3 such vectors int max_dim = (n*2+1); int max_dim2 = max_dim*max_dim; int max = max_dim2*max_dim; // only one loop to avoid unneccessary jumps for(int i = 0;i > Box::getBoundingPlanes(){ vector > res; for(int i=0;i