Commit bf23ee36ba94f2b29d1ae781c39d516c6306e4cc

Authored by Pavel Govyadinov
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,9 +28,11 @@ class cylinder
28 pos = inP; 28 pos = inP;
29 mags = inM; 29 mags = inM;
30 L.resize(pos.size()-1); 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,7 +48,8 @@ class cylinder
46 { 48 {
47 for(int i = 0; i < j-1; ++i) 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,7 +57,7 @@ class cylinder
54 findIdx(T l) 57 findIdx(T l)
55 { 58 {
56 int i = pos.size()/2; 59 int i = pos.size()/2;
57 - while(1) 60 + while(i > 0 && i < pos.size())
58 { 61 {
59 if(L[i] < l) 62 if(L[i] < l)
60 { 63 {
@@ -92,6 +95,8 @@ class cylinder @@ -92,6 +95,8 @@ class cylinder
92 stim::vec<T> 95 stim::vec<T>
93 p(T pvalue) 96 p(T pvalue)
94 { 97 {
  98 + if(pvalue < 0.0 || pvalue > 1.0)
  99 + return;
95 T l = pvalue*L[L.size()-1]; 100 T l = pvalue*L[L.size()-1];
96 int idx = findIdx(l); 101 int idx = findIdx(l);
97 return (pos[idx] + (pos[idx+1]-pos[idx])*((l-L[idx])/(L[idx+1]- L[idx]))); 102 return (pos[idx] + (pos[idx+1]-pos[idx])*((l-L[idx])/(L[idx+1]- L[idx])));
@@ -107,6 +112,8 @@ class cylinder @@ -107,6 +112,8 @@ class cylinder
107 T 112 T
108 r(T pvalue) 113 r(T pvalue)
109 { 114 {
  115 + if(pvalue < 0.0 || pvalue > 1.0)
  116 + return;
110 T l = pvalue*L[L.size()-1]; 117 T l = pvalue*L[L.size()-1];
111 int idx = findIdx(l); 118 int idx = findIdx(l);
112 return (mags[idx] + (mags[idx+1]-mags[idx])*((l-L[idx])/(L[idx+1]- L[idx]))); 119 return (mags[idx] + (mags[idx+1]-mags[idx])*((l-L[idx])/(L[idx+1]- L[idx])));
@@ -124,6 +131,8 @@ class cylinder @@ -124,6 +131,8 @@ class cylinder
124 stim::vec<T> 131 stim::vec<T>
125 surf(T pvalue, T theta) 132 surf(T pvalue, T theta)
126 { 133 {
  134 + if(pvalue < 0.0 || pvalue > 1.0)
  135 + return;
127 T l = pvalue*L[L.size()-1]; 136 T l = pvalue*L[L.size()-1];
128 int idx = findIdx(l); 137 int idx = findIdx(l);
129 stim::vec<T> ps = p(l, idx); 138 stim::vec<T> ps = p(l, idx);