-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateTrickle.cpp
More file actions
97 lines (94 loc) · 3.14 KB
/
updateTrickle.cpp
File metadata and controls
97 lines (94 loc) · 3.14 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
#include <vector>
#include "updateTricle.h"
using namespace std;
int updateTricle(int neighbors, double volumn, double** tricleMat, int r, int c) {
// 1. Compute whether divide;
// 2. Compute neighbor traget;
// 3. Update tricleMat;
int divid = neighbors / 4;
int remain = neighbors % 4;
switch (divid) {
case 0:
if (remain == 0) {
tricleMat[r][c] += volumn;
} else if (remain == 2) {
tricleMat[r-1][c] += volumn / 2;
tricleMat[r+1][c] += volumn / 2;
} else if (remain == 3) {
tricleMat[r][c-1] += volumn / 2;
tricleMat[r][c+1] += volumn / 2;
}
break;
case 1:
switch (remain) {
case 0:
tricleMat[r-1][c] += volumn;
break;
case 1:
tricleMat[r][c+1] += volumn;
break;
case 2:
tricleMat[r+1][c] += volumn;
break;
case 3:
tricleMat[r][c-1] += volumn;
break;
default: break;
}
break;
case 2:
switch (remain) {
case 0:
tricleMat[r-1][c] += volumn / 2;
tricleMat[r][c+1] += volumn / 2;
break;
case 1:
tricleMat[r][c+1] += volumn / 2;
tricleMat[r+1][c] += volumn / 2;
break;
case 2:
tricleMat[r+1][c] += volumn / 2;
tricleMat[r][c-1] += volumn / 2;
break;
case 3:
tricleMat[r-1][c] += volumn / 2;
tricleMat[r][c-1] += volumn / 2;
break;
default: break;
}
break;
case 3:
switch (remain) {
case 0:
tricleMat[r][c+1] += volumn / 3;
tricleMat[r][c-1] += volumn / 3;
tricleMat[r+1][c] += volumn / 3;
break;
case 1:
tricleMat[r-1][c] += volumn / 3;
tricleMat[r+1][c] += volumn / 3;
tricleMat[r][c-1] += volumn / 3;
break;
case 2:
tricleMat[r][c+1] += volumn / 3;
tricleMat[r][c-1] += volumn / 3;
tricleMat[r-1][c] += volumn / 3;
break;
case 3:
tricleMat[r-1][c] += volumn / 3;
tricleMat[r+1][c] += volumn / 3;
tricleMat[r][c+1] += volumn / 3;
break;
default: break;
}
break;
case 4:
tricleMat[r-1][c] += volumn / 4;
tricleMat[r+1][c] += volumn / 4;
tricleMat[r][c+1] += volumn / 4;
tricleMat[r][c-1] += volumn / 4;
default: break;
}
return 0;
}