Coord.cc

00001 #include "Coord.h"
00002 
00003 // Workaround for C2864
00004 // If set to another value than 0.0 one has to check the
00005 // compliance with the overloaded operators
00006 const double Coord::UNDEFINED = 0.0;
00007 
00008 double Coord::sqrTorusDist(const Coord& b, const Coord& playgroundSize) const {
00009 
00010     double xDist = fabs(x - b.x);
00011     double yDist = fabs(y - b.y);
00012     double zDist = fabs(z - b.z);
00013 
00014     
00015     /*
00016      * on a torus the end and the begin of the axes are connected so you
00017      * get a circle. On a circle the distance between two points can't be greater
00018      * than half of the circumference.
00019      * If the normal distance between two points on one axis is bigger than
00020      * half of the playground there must be a "shorter way" over the playground
00021      * border on this axis
00022      */
00023     if(xDist * 2.0 > playgroundSize.x)
00024     {
00025         xDist = playgroundSize.x - xDist;
00026     }
00027     //same for y- and z-coordinate
00028     if(yDist * 2.0 > playgroundSize.y)
00029     {
00030       yDist = playgroundSize.y - yDist;
00031     }
00032     if(zDist * 2.0 > playgroundSize.z)
00033     {
00034       zDist = playgroundSize.z - zDist;
00035     }
00036     return xDist * xDist + yDist * yDist + zDist * zDist;
00037 }