DistanceFunction<T> typedef Null safety

DistanceFunction<T> = num Function(T a, T b)

Computes the distance between two values.

The distance should be a metric in a metric space (see https://en.wikipedia.org/wiki/Metric_space). Specifically, if f is a distance function then the following conditions should hold:

  • f(a, b) >= 0
  • f(a, b) == 0 if and only if a == b
  • f(a, b) == f(b, a)
  • f(a, c) <= f(a, b) + f(b, c), known as triangle inequality

This makes it useful for comparing numbers, Colors, Offsets and other sets of value for which a metric space is defined.


typedef DistanceFunction<T> = num Function(T a, T b);