]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/Mean.qh
19d9f384d2d8d68c601fafb1d3dbe419fba999b8
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / Mean.qh
1 #ifndef MEAN_H
2 #define MEAN_H
3
4 void mean_accumulate(entity e, .float a, .float c, float mean, float value, float weight)
5 {
6         if (weight == 0)
7                 return;
8         if (mean == 0)
9                 e.(a) *= pow(value, weight);
10         else
11                 e.(a) += pow(value, mean) * weight;
12         e.(c) += weight;
13 }
14
15 float mean_evaluate(entity e, .float a, .float c, float mean)
16 {
17         if (e.(c) == 0)
18                 return 0;
19         if (mean == 0)
20                 return pow(e.(a), 1.0 / e.(c));
21         else
22                 return pow(e.(a) / e.(c), 1.0 / mean);
23 }
24
25 #define MEAN_ACCUMULATE(prefix,v,w) mean_accumulate(self,prefix##_accumulator,prefix##_count,prefix##_mean,v,w)
26 #define MEAN_EVALUATE(prefix) mean_evaluate(self,prefix##_accumulator,prefix##_count,prefix##_mean)
27 #define MEAN_DECLARE(prefix,m) float prefix##_mean = m; .float prefix##_count, prefix##_accumulator
28
29 #endif