Retrieves the approximate distance using an algorithm from Starcraft: Broodwar. @note This is a direct distance calculation that ignores all collision. @note This function is desired because it uses the same "imperfect" algorithm used in Broodwar, so that calculations will be consistent with the game. It is also optimized for performance. The target po
| 302 | /// @returns An integer representing the distance between this point and \p position. |
| 303 | /// @see getDistance |
| 304 | int getApproxDistance(const Point<T,Scale> &position) const |
| 305 | { |
| 306 | unsigned int max = abs((int)(this->x - position.x)); |
| 307 | unsigned int min = abs((int)(this->y - position.y)); |
| 308 | if ( max < min ) |
| 309 | std::swap(min, max); |
| 310 | |
| 311 | if ( min <= (max >> 2) ) |
| 312 | return max; |
| 313 | |
| 314 | unsigned int minCalc = (3*min) >> 3; |
| 315 | return (minCalc >> 5) + minCalc + max - (max >> 4) - (max >> 6); |
| 316 | }; |
| 317 | |
| 318 | /// <summary>Sets the maximum x and y values.</summary> If the current x or y values exceed |
| 319 | /// the given maximum, then values are set to the maximum. |
no outgoing calls
no test coverage detected