cmp method

double cmp(
  1. List temp,
  2. List cand,
  3. int q
)

Implementation

double cmp(List<dynamic> temp, List<dynamic> cand, int q) {
  double dist = 0.0;
  double diff = 0.0;
  for (int i = 0; i < temp.length; i++) {
    diff = (temp[i] - cand[i]).abs();
    if (q == 1)
      dist += diff;
    else if (q == 2)
      dist += diff * diff;
    else if (q == INFINITY && diff > dist)
      dist = diff;
    else
      dist += pow(diff, q);
  }
  if (q == 1 || q == INFINITY)
    return dist;
  else if (q == 2) return sqrt(dist);
  return pow(dist, 1.0 / q).toDouble();
}