diff --git a/bwapi/Backend/1.16.1/BWAPIBackend_1161/Source/BWAPI/UnitImpl.cpp b/bwapi/Backend/1.16.1/BWAPIBackend_1161/Source/BWAPI/UnitImpl.cpp index fe1c52e09..bbbe1663d 100755 --- a/bwapi/Backend/1.16.1/BWAPIBackend_1161/Source/BWAPI/UnitImpl.cpp +++ b/bwapi/Backend/1.16.1/BWAPIBackend_1161/Source/BWAPI/UnitImpl.cpp @@ -1308,26 +1308,20 @@ namespace BWAPI4 /////// Compute distance - // retrieve left/top/right/bottom values for calculations - int left = target.x - 1; - int top = target.y - 1; - int right = target.x + 1; - int bottom = target.y + 1; - // compute x distance - int xDist = this->getLeft() - right; + int xDist = this->getLeft() - target.x; if (xDist < 0) { - xDist = left - this->getRight(); + xDist = target.x - (this->getRight() + 1); if (xDist < 0) xDist = 0; } // compute y distance - int yDist = this->getTop() - bottom; + int yDist = this->getTop() - target.y; if (yDist < 0) { - yDist = top - this->getBottom(); + yDist = target.y - (this->getBottom() + 1); if (yDist < 0) yDist = 0; } diff --git a/bwapi/Frontend/BWAPILIB/Source/Unit.cpp b/bwapi/Frontend/BWAPILIB/Source/Unit.cpp index f724678fb..b695fb7f8 100755 --- a/bwapi/Frontend/BWAPILIB/Source/Unit.cpp +++ b/bwapi/Frontend/BWAPILIB/Source/Unit.cpp @@ -182,26 +182,20 @@ int Unit::getDistance(Position target) const /////// Compute distance - // retrieve left/top/right/bottom values for calculations - int left = target.x - 1; - int top = target.y - 1; - int right = target.x + 1; - int bottom = target.y + 1; - // compute x distance - int xDist = this->getLeft() - right; + int xDist = this->getLeft() - target.x; if (xDist < 0) { - xDist = left - this->getRight(); + xDist = target.x - (this->getRight() + 1); if (xDist < 0) xDist = 0; } // compute y distance - int yDist = this->getTop() - bottom; + int yDist = this->getTop() - target.y; if (yDist < 0) { - yDist = top - this->getBottom(); + yDist = target.y - (this->getBottom() + 1); if (yDist < 0) yDist = 0; } diff --git a/bwapi/include/BWAPI/Position.h b/bwapi/include/BWAPI/Position.h index 8e4449bfe..1e788c0c6 100755 --- a/bwapi/include/BWAPI/Position.h +++ b/bwapi/include/BWAPI/Position.h @@ -275,12 +275,12 @@ namespace BWAPI /// @see getDistance int getApproxDistance(const Point &position) const { - unsigned int min = abs((int)(this->x - position.x)); - unsigned int max = abs((int)(this->y - position.y)); + unsigned int max = abs((int)(this->x - position.x)); + unsigned int min = abs((int)(this->y - position.y)); if ( max < min ) std::swap(min, max); - if ( min < (max >> 2) ) + if ( min <= (max >> 2) ) return max; unsigned int minCalc = (3*min) >> 3;