Commit bf23ee36ba94f2b29d1ae781c39d516c6306e4cc
1 parent
66fe63f3
more minor bug fixes in unused methods, as well as a safety checks
Showing
1 changed file
with
13 additions
and
4 deletions
Show diff stats
stim/visualization/cylinder.h
... | ... | @@ -28,9 +28,11 @@ class cylinder |
28 | 28 | pos = inP; |
29 | 29 | mags = inM; |
30 | 30 | L.resize(pos.size()-1); |
31 | - for(int i = 0; i < L.size(); i++) | |
31 | + T temp = (T)0; | |
32 | + for(int i = 0; i < L.size()-1; i++) | |
32 | 33 | { |
33 | - L[i] += (pos[i] - pos[i+1]).len(); | |
34 | + temp += (pos[i] - pos[i+1]).len(); | |
35 | + L[i] = temp; | |
34 | 36 | } |
35 | 37 | } |
36 | 38 | |
... | ... | @@ -46,7 +48,8 @@ class cylinder |
46 | 48 | { |
47 | 49 | for(int i = 0; i < j-1; ++i) |
48 | 50 | { |
49 | - L += (pos[i] -pos[i+1]).len(); | |
51 | + temp += (pos[i] - pos[i+1]).len(); | |
52 | + L[i] = temp; | |
50 | 53 | } |
51 | 54 | } |
52 | 55 | |
... | ... | @@ -54,7 +57,7 @@ class cylinder |
54 | 57 | findIdx(T l) |
55 | 58 | { |
56 | 59 | int i = pos.size()/2; |
57 | - while(1) | |
60 | + while(i > 0 && i < pos.size()) | |
58 | 61 | { |
59 | 62 | if(L[i] < l) |
60 | 63 | { |
... | ... | @@ -92,6 +95,8 @@ class cylinder |
92 | 95 | stim::vec<T> |
93 | 96 | p(T pvalue) |
94 | 97 | { |
98 | + if(pvalue < 0.0 || pvalue > 1.0) | |
99 | + return; | |
95 | 100 | T l = pvalue*L[L.size()-1]; |
96 | 101 | int idx = findIdx(l); |
97 | 102 | return (pos[idx] + (pos[idx+1]-pos[idx])*((l-L[idx])/(L[idx+1]- L[idx]))); |
... | ... | @@ -107,6 +112,8 @@ class cylinder |
107 | 112 | T |
108 | 113 | r(T pvalue) |
109 | 114 | { |
115 | + if(pvalue < 0.0 || pvalue > 1.0) | |
116 | + return; | |
110 | 117 | T l = pvalue*L[L.size()-1]; |
111 | 118 | int idx = findIdx(l); |
112 | 119 | return (mags[idx] + (mags[idx+1]-mags[idx])*((l-L[idx])/(L[idx+1]- L[idx]))); |
... | ... | @@ -124,6 +131,8 @@ class cylinder |
124 | 131 | stim::vec<T> |
125 | 132 | surf(T pvalue, T theta) |
126 | 133 | { |
134 | + if(pvalue < 0.0 || pvalue > 1.0) | |
135 | + return; | |
127 | 136 | T l = pvalue*L[L.size()-1]; |
128 | 137 | int idx = findIdx(l); |
129 | 138 | stim::vec<T> ps = p(l, idx); | ... | ... |