unit method

Vec3 unit([
  1. Vec3? target
])

Get the version of this vector that is of length 1. @param target Optional target to save in @return Returns the unit vector

Implementation

Vec3 unit([Vec3? target]) {
  target ??= Vec3();
  double ninv = math.sqrt(x * x + y * y + z * z);
  if (ninv > 0.0) {
    ninv = 1.0 / ninv;
    target.x = x * ninv;
    target.y = y * ninv;
    target.z = z * ninv;
  } else {
    target.x = 1;
    target.y = 0;
    target.z = 0;
  }
  return target;
}