normalized method

Vector3 normalized()

Return a normalised copy without mutating this.

A (near-)zero vector has no direction; it gives the unit x axis (1, 0, 0), unlike normalize, which leaves it at zero.

Implementation

Vector3 normalized() {
  final len = length;
  if (len > 1e-9) {
    final inv = 1.0 / len;
    return Vector3(x * inv, y * inv, z * inv);
  }
  return Vector3(1, 0, 0);
}