common: mathlib: add VectorLengthSq

This commit is contained in:
Eric Wasylishen 2017-04-26 14:21:19 -06:00
parent 902c45c946
commit 03396787b2
1 changed files with 11 additions and 8 deletions

View File

@ -167,18 +167,21 @@ VectorMA(const vec3_t va, vec_t scale, const vec3_t vb, vec3_t vc)
void CrossProduct(const vec3_t v1, const vec3_t v2, vec3_t cross);
static inline double
VectorLengthSq(const vec3_t v)
{
double length = 0;
for (int i = 0; i < 3; i++)
length += v[i] * v[i];
return length;
}
static inline double
VectorLength(const vec3_t v)
{
int i;
double length;
length = 0;
for (i = 0; i < 3; i++)
length += v[i] * v[i];
double length = VectorLengthSq(v);
length = sqrt(length);
return length;
}