distanceTo 方法

double distanceTo(
  1. Point<T> other
)

返回当前对象与 other 之间的距离。

var distanceTo = const Point(0, 0).distanceTo(const Point(0, 0)); // 0.0
distanceTo = const Point(0, 0).distanceTo(const Point(10, 0)); // 10.0
distanceTo = const Point(0, 0).distanceTo(const Point(0, -10)); // 10.0
distanceTo = const Point(-10, 0).distanceTo(const Point(100, 0)); // 110.0

实现

double distanceTo(Point<T> other) {
  var dx = x - other.x;
  var dy = y - other.y;
  return sqrt(dx * dx + dy * dy);
}