question: public final double squaredDistance ( final int x , final int y ) { final double otherMiddleX = x + 0.5 ; final double otherMiddleY = y + 0.5 ; final Rectangle2D thisArea = getArea ( ) ; final double thisMiddleX = thisArea . getCenterX ( ) ; final double thisMiddleY = thisArea . getCenterY ( ) ; double xDistance = Math . abs ( otherMiddleX - thisMiddleX ) - ( area . getWidth ( ) + 1 ) / 2 ; double yDistance = Math . abs ( otherMiddleY - thisMiddleY ) - ( area . getHeight ( ) + 1 ) / 2 ; if ( xDistance < 0 ) { xDistance = 0 ; } if ( yDistance < 0 ) { yDistance = 0 ; } return xDistance * xDistance + yDistance * yDistance ; }
target:  This returns square of the distance from this entity to a specific point. We're calculating the square because the square root operation would be expensive. As long as we only need to compare distances, it doesn't matter if we compare the distances or the squares of the distances (the square operation is strictly monotonous for positive numbers).