Spec-Zone.ru › Dart 2

dart:math

Метод squaredDistanceTo

T squaredDistanceTo(
  1. Point<T> other
)

Возвращает квадрат расстояния между this и other.

Квадраты расстояний могут использоваться для сравнений, когда фактическое значение не требуется.

Пример:

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;
}

© 2012 the Dart project authors
Licensed under the BSD 3-Clause "New" or "Revised" License.
https://api.dart.dev/stable/2.18.5/dart-math/Point/squaredDistanceTo.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API