squaredDistanceTo 方法

T squaredDistanceTo(
  1. Point<T> other
)

返回当前对象 thisother 之间的平方距离。

平方距离可以用于比较,当不需要实际值时。

示例

var squaredDistance =
    const Point(0, 0).squaredDistanceTo(const Point(0, 0)); // 0.0
squaredDistance =
    const Point(0, 0).squaredDistanceTo(const Point(10, 0)); // 100
squaredDistance =
    const Point(0, 0).squaredDistanceTo(const Point(0, -10)); // 100
squaredDistance =
    const Point(-10, 0).squaredDistanceTo(const Point(100, 0)); // 12100

实现

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