normalizeDirection method

Ray normalizeDirection()

Normalizes direction in place and returns this ray.

In place, not via normalized(): that returns a new vector and leaves the original untouched, and a caller that reads its own field afterwards gets the un-normalized value. The renderer already lost an afternoon to exactly that shape of bug with light directions.

Implementation

Ray normalizeDirection() {
  if (direction.length2 > 0.0) direction.normalize();
  return this;
}