From bf23ee36ba94f2b29d1ae781c39d516c6306e4cc Mon Sep 17 00:00:00 2001 From: pgovyadi Date: Wed, 3 Feb 2016 13:52:34 -0600 Subject: [PATCH] more minor bug fixes in unused methods, as well as a safety checks --- stim/visualization/cylinder.h | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/stim/visualization/cylinder.h b/stim/visualization/cylinder.h index 18f2c6e..31524d2 100644 --- a/stim/visualization/cylinder.h +++ b/stim/visualization/cylinder.h @@ -28,9 +28,11 @@ class cylinder pos = inP; mags = inM; L.resize(pos.size()-1); - for(int i = 0; i < L.size(); i++) + T temp = (T)0; + for(int i = 0; i < L.size()-1; i++) { - L[i] += (pos[i] - pos[i+1]).len(); + temp += (pos[i] - pos[i+1]).len(); + L[i] = temp; } } @@ -46,7 +48,8 @@ class cylinder { for(int i = 0; i < j-1; ++i) { - L += (pos[i] -pos[i+1]).len(); + temp += (pos[i] - pos[i+1]).len(); + L[i] = temp; } } @@ -54,7 +57,7 @@ class cylinder findIdx(T l) { int i = pos.size()/2; - while(1) + while(i > 0 && i < pos.size()) { if(L[i] < l) { @@ -92,6 +95,8 @@ class cylinder stim::vec p(T pvalue) { + if(pvalue < 0.0 || pvalue > 1.0) + return; T l = pvalue*L[L.size()-1]; int idx = findIdx(l); return (pos[idx] + (pos[idx+1]-pos[idx])*((l-L[idx])/(L[idx+1]- L[idx]))); @@ -107,6 +112,8 @@ class cylinder T r(T pvalue) { + if(pvalue < 0.0 || pvalue > 1.0) + return; T l = pvalue*L[L.size()-1]; int idx = findIdx(l); return (mags[idx] + (mags[idx+1]-mags[idx])*((l-L[idx])/(L[idx+1]- L[idx]))); @@ -124,6 +131,8 @@ class cylinder stim::vec surf(T pvalue, T theta) { + if(pvalue < 0.0 || pvalue > 1.0) + return; T l = pvalue*L[L.size()-1]; int idx = findIdx(l); stim::vec ps = p(l, idx); -- libgit2 0.21.4