normalize function

List<num> normalize(
  1. num x,
  2. num y
)

Implementation

List<num> normalize(num x, num y) {
  var l = distance(0, 0, x, y);
  if (l > 0.00001) {
    return [x / l, y / l];
  } else {
    return [0, 0];
  }
}