squaredDistanceFrom static method

double squaredDistanceFrom(
  1. Coordinate a,
  2. Coordinate b
)

Returns the squared distance between two coordinates. Squared distances can be used for comparisons when the actual value is not required.

Performance note: eliminating the square root is an optimization often used in lower-level languages, but the speed difference is not nearly as pronounced in JavaScript (only a few percent.)

@param {!goog.math.Coordinate} a A Coordinate. @param {!goog.math.Coordinate} b A Coordinate. @return {number} The squared distance between {@code a} and {@code b}.

Implementation

static double squaredDistanceFrom(Coordinate a, Coordinate b)
{
  double dx = a.x - b.x;
  double dy = a.y - b.y;
  return dx * dx + dy * dy;
}