Clamps vector to at most maxLength, in place, and returns it.
Shorter vectors are left bit-identical and unwritten (no round-trip
through a normalize, no change hook), so truncate is a no-op exactly when it
should be. A non-positive maxLength zeroes the vector: 0 because that is
the limit, and negative because scaling by a negative limit would reverse the
direction, which is never what a caller means.
The common case costs one squared-length comparison and no square root.
This is the public form of the clamp every behaviour applies. The behaviours
do not call it: they clamp the scalars they are about to write, which keeps
out to a single write (see the module note on allocation), and
writeTruncated is that shared scalar form.
Clamps
vectorto at mostmaxLength, in place, and returns it.Shorter vectors are left bit-identical and unwritten (no round-trip through a normalize, no change hook), so
truncateis a no-op exactly when it should be. A non-positivemaxLengthzeroes the vector:0because that is the limit, and negative because scaling by a negative limit would reverse the direction, which is never what a caller means.The common case costs one squared-length comparison and no square root.
This is the public form of the clamp every behaviour applies. The behaviours do not call it: they clamp the scalars they are about to write, which keeps
outto a single write (see the module note on allocation), andwriteTruncatedis that shared scalar form.