-
Notifications
You must be signed in to change notification settings - Fork 0
/
standard-of.c
65 lines (60 loc) · 1.55 KB
/
standard-of.c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "standard-of.h"
DeltaSet * delta_push(float begin, float end, float max){
DeltaSet * set = (DeltaSet *)malloc(sizeof(DeltaSet));
delta_zero(set);
set->to->begin = begin;
set->to->end = end;
set->to->mid = set->to->begin + ((set->to->end - set->to->begin) * .5);
set->max = max;
set->balance_max = set->to->mid * set->max;
set->balance_multiplied = set->to->mid * set->balance_max;
return set;
}
STATUS delta_next(DeltaSet ** set, DeltaSet * next){
if(!next)return Off;
if (*set) {
DeltaSet * update = *set;
while (update->next != NULL) {
update = update->next;
}
update->next = next;
return On;
}
*set = next;
return On;
}
void total_get(StandardDetour * to, DeltaSet * set, int sample){
if(!to || !set)return;
DeltaSet * update = set;
while(update){
to->balance_add += update->balance_max;
to->balance_multiplied += update->balance_multiplied;
to->max += update->max;
update = update->next;
}
to->balance = to->balance_multiplied / to->max;
/*
update = set;
while(update){
to->balance_total += update->max * pow(update->balance_max - to->balance, 2);
update = update->next;
}
*/
to->variance = to->balance - pow(to->balance_add / to->max ,2);
to->detour = sqrt(to->variance);
}
void delta_pop(DeltaSet * set){
if(!set)return;
free(set);
set = NULL;
}
void delta_zero(DeltaSet * set){
if(!set)return;
set->to->begin = 0;
set->to->mid = 0;
set->to->end = 0;
set->max = 1;
set->balance_max = 1;
set->balance_multiplied = 1;
set->next = NULL;
}