forked from ocuadrosl/ParticlePhysics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtil.h
49 lines (30 loc) · 705 Bytes
/
Util.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#ifndef UTIL_H
#define UTIL_H
#include <vector>
#include <cmath>
#include <iostream>
#include <fstream>
namespace util
{
inline float squaredLength( const std::vector<float>& input)
{
float lengh=0.f;
for(auto it=input.begin(); it!= input.end(); ++it)
{
lengh += (*it) * (*it);
}
return lengh;
}
inline void normalize(const std::vector<float>& input, std::vector<float>& output)
{
float length = std::sqrt(squaredLength(input));
output = input;
if(length == 1.f || length == 0.f) { return; }
float scaleFactor = 1.f/length;
for(auto it=output.begin(); it!= output.end(); ++it)
{
*it *= scaleFactor;
}
}
}
#endif // UTIL_H