MCPcopy Create free account
hub / github.com/bwapi/bwapi / getApproxDistance

Method getApproxDistance

bwapi/include/BWAPI/Position.h:304–316  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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.

Callers 6

UpdateRegionRelationsMethod · 0.80
getAirDistanceMethod · 0.80
getBuildLocationMethod · 0.80
getDistanceMethod · 0.80
getDistanceMethod · 0.80
setNeighborsMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected