pybrood icon indicating copy to clipboard operation
pybrood copied to clipboard

Why isn't Position/TilePosition/WalkPosition wrapped?

Open ratiotile opened this issue 8 years ago • 2 comments

I'm trying to understand the decision to convert all Positions into integer arrays. You lose type safety and methods like getDistance().

ratiotile avatar Sep 29 '17 16:09 ratiotile

It was intended for wrapping on python side to avoid round-tripping C++ bridge for small scalar types. Isn't getDistance just euclidean metric? Some experiments needed to figure out what will be more efficient.

neumond avatar Sep 30 '17 00:09 neumond

I agree that it needs measurement, just be aware that getApproxDistance uses an optimized algorithm that matches the one used in-game:

int getApproxDistance(const Point<T,Scale> &position) const
    {
      unsigned int min = abs((int)(this->x - position.x));
      unsigned int max = abs((int)(this->y - position.y));
      if ( max < min )
        std::swap(min, max);

      if ( min < (max >> 2) )
        return max;

      unsigned int minCalc = (3*min) >> 3;
      return (minCalc >> 5) + minCalc + max - (max >> 4) - (max >> 6);
    };

ratiotile avatar Sep 30 '17 15:09 ratiotile