Example #1
0
const double getWrappingUnitDist(const StaticObject& obj1, const StaticObject& obj2) {

   pair<double,double> pos1 = obj1.getUnitPos();
   pair<double,double> pos2 = obj2.getUnitPos();

   double x = std::abs(pos1.first - pos2.first);
   if(x > .5)
      x = 1 - x;

   double y = std::abs(pos1.second - pos2.second);
   if(y > .5)
      y = 1 - y;

   return std::sqrt(x*x + y*y);
}
Example #2
0
const unsigned getWrappingDistSq(const StaticObject& obj1, const StaticObject& obj2) {

   pair<double,double> pos1 = obj1.getUnitPos();
   pair<double,double> pos2 = obj2.getUnitPos();

   double x = std::abs(pos1.first - pos2.first);
   if(x > .5)
      x = 1 - x;

   double y = std::abs(pos1.second - pos2.second);
   if(y > .5)
      y = 1 - y;

   x *= UNIVERSE_WIDTH * UNIVERSE_TOTAL_SCALE;
   y *= UNIVERSE_HEIGHT * UNIVERSE_TOTAL_SCALE;

   return static_cast<unsigned>(x*x + y*y);
}