distanceBetweenPoints static method

double distanceBetweenPoints(
  1. Offset a,
  2. Offset b
)

Approximates the distance between two points. The returned value can be up to 6% wrong in the worst case.

Implementation

static double distanceBetweenPoints(Offset a, Offset b) {
  double dx = a.dx - b.dx;
  double dy = a.dy - b.dy;
  if (dx < 0.0) dx = -dx;
  if (dy < 0.0) dy = -dy;
  if (dx > dy) {
    return dx + dy / 2.0;
  } else {
    return dy + dx / 2.0;
  }
}