MCPcopy Create free account
hub / github.com/analogdevicesinc/scopy / getValueAt

Method getValueAt

gui/src/plotchannel.cpp:264–326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

262}
263
264double PlotChannel::getValueAt(double pos)
265{
266 auto tmp = this;
267 QwtSeriesData<QPointF> *curve_data = tmp->curve()->data();
268 int n = curve_data->size();
269
270 if(n == 0) {
271 return -1;
272 } else {
273 double leftTime, rightTime, leftCustom, rightCustom;
274 int rightIndex = -1;
275 int leftIndex = -1;
276 int left = 0;
277 int right = n - 1;
278
279 double right_s = curve_data->sample(right).x();
280 double left_s = curve_data->sample(left).x();
281 if(pos < std::min(right_s, left_s) || pos > std::max(right_s, left_s)) {
282 return -1;
283 }
284
285 // this is used in Frequency complex mode
286 bool reversed = false;
287 if(right_s < left_s) {
288 reversed = true;
289 }
290
291 while(left <= right) {
292 int mid = (left + right) / 2;
293 double xData = curve_data->sample(mid).x();
294
295 if(xData == pos) {
296 if(mid > 0) {
297 leftIndex = mid - 1;
298 rightIndex = mid;
299 }
300 break;
301 } else if((xData < pos) ^ reversed) {
302 left = mid + 1;
303 } else {
304 right = mid - 1;
305 }
306 }
307
308 if((leftIndex == -1 || rightIndex == -1) && left > 0) {
309 leftIndex = left - 1;
310 rightIndex = left;
311 }
312 if(leftIndex == -1 || rightIndex == -1) {
313 return -1;
314 }
315
316 leftTime = curve_data->sample(leftIndex).x();
317 rightTime = curve_data->sample(rightIndex).x();
318
319 leftCustom = curve_data->sample(leftIndex).y();
320 rightCustom = curve_data->sample(rightIndex).y();
321

Callers 2

displayIntersectionMethod · 0.80

Calls 3

sampleMethod · 0.80
dataMethod · 0.45
curveMethod · 0.45

Tested by

no test coverage detected