[Kst] kdeextragear-2/kst/kst
Barth Netterfield
netterfield at astro.utoronto.ca
Wed Jul 16 03:34:34 CEST 2003
CVS commit by netterfield:
Stick with ~clean interpolation with bounds checking.
M +17 -20 kstvector.cpp 1.37
--- kdeextragear-2/kst/kst/kstvector.cpp #1.36:1.37
@@ -88,28 +88,21 @@ double KstVector::interpolate(int in_i,
int j;
- assert(in_i >= 0);
+ /** Limits checks - optional? **/
+ if (in_i<0)
+ return _v[0];
+
+ if (in_i >= ns_i-1)
+ return _v[_size-1];
+ /** speedup check **/
if (ns_i == _size) { /* no extrapolating or decimating needed */
- assert(in_i < _size);
return _v[in_i];
}
- if (ns_i == 1) { // can't interpolate if there is only one point
- return _v[0];
- }
-
- fj = in_i * double(_size - 1) / double(ns_i - 1); //scaled index
+ fj = in_i * double(_size-1) / double(ns_i-1); //scaled index
j = int(floor(fj)); // index of sample one lower
- if (j >= _size) { // asking past end of vector
- return 0;
- }
-
- if (j == _size - 1) {// asking for last element of vector
- return _v[j];
- }
-
- if (isnan(_v[j + 1]) || isnan(_v[j])) {
+ if (isnan(_v[j+1]) || isnan(_v[j])) {
return KST::NOPOINT;
}
@@ -120,6 +113,13 @@ double KstVector::interpolate(int in_i,
}
+
double KstVector::value(int i) {
- assert(i >= 0 && i < _size);
+ if (i < 0) {//can't look before begining
+ return 0.0;
+ }
+
+ if (i >= _size) {// can't look past end
+ return 0.0;
+ }
return _v[i];
}
@@ -214,7 +214,4 @@ KstObject::UpdateType KstVector::update(
else
minpos = 1.0E300;
-
- //_scalars["max"]->setValue(_v[i]);
- //_scalars["min"]->setValue(_v[i]);
for (; i < _size; i++) {
More information about the Kst
mailing list