squaredDistance method

double squaredDistance(
  1. Coordinate point
)

@param {!goog.math.Coordinate} point A coordinate. @return {number} The squared distance between the point and the closest point inside the rectangle. Returns 0 if the point is inside the rectangle.

Implementation

double squaredDistance(Coordinate point)
{
  double dx = point.x < this.left ?
           this.left - point.x :
           Math.max(point.x - (this.left + this.width), 0.0);

  double dy = point.y < this.top ? this.top - point.y :
                                Math.max(point.y - (this.top + this.height), 0.0);
  return dx * dx + dy * dy;
}