Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why isn't Position/TilePosition/WalkPosition wrapped? #5

Open
ratiotile opened this issue Sep 29, 2017 · 2 comments
Open

Why isn't Position/TilePosition/WalkPosition wrapped? #5

ratiotile opened this issue Sep 29, 2017 · 2 comments

Comments

@ratiotile
Copy link

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

@neumond
Copy link
Owner

neumond commented Sep 30, 2017

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.

@ratiotile
Copy link
Author

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);
    };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants