normalize method

double normalize()

Normalize the vector. Note that this changes the values in the vector. @return Returns the norm of the vector

Implementation

double normalize() {
  final x = this.x;
  final y = this.y;
  final z = this.z;
  final n = math.sqrt(x * x + y * y + z * z);
  if (n > 0.0) {
    final invN = 1 / n;
    this.x *= invN;
    this.y *= invN;
    this.z *= invN;
  } else {
    // Make something up
    this.x = 0;
    this.y = 0;
    this.z = 0;
  }
  return n;
}