AP_Math: make rand_vec a little more efficient

This commit is contained in:
Peter Barker 2022-11-16 10:32:13 +11:00 committed by Peter Barker
parent dd8fbad653
commit 406119ed41
1 changed files with 6 additions and 4 deletions

View File

@ -350,10 +350,12 @@ float rand_float(void)
Vector3f rand_vec3f(void)
{
Vector3f v = Vector3f(rand_float(),
rand_float(),
rand_float());
if (!is_zero(v.length())) {
Vector3f v {
rand_float(),
rand_float(),
rand_float()
};
if (!v.is_zero()) {
v.normalize();
}
return v;