MCPcopy Create free account
hub / github.com/PlotJuggler/PlotJuggler / curvePointAt

Function curvePointAt

pj_plotting/widget/src/CurveTracker.cpp:233–263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231}
232
233std::optional<QPointF> curvePointAt(const QwtPlotCurve* curve, double x) {
234 if (curve == nullptr || curve->dataSize() == 0) {
235 return std::nullopt;
236 }
237 if (curve->dataSize() == 1) {
238 return curve->sample(0);
239 }
240
241 std::size_t low = 0;
242 std::size_t high = curve->dataSize();
243 while (low < high) {
244 const std::size_t mid = low + (high - low) / 2;
245 if (curve->sample(mid).x() <= x) {
246 low = mid + 1;
247 } else {
248 high = mid;
249 }
250 }
251
252 if (low == 0) {
253 return curve->sample(0);
254 }
255 if (low >= curve->dataSize()) {
256 return curve->sample(curve->dataSize() - 1);
257 }
258
259 const QPointF left = curve->sample(low - 1);
260 const QPointF right = curve->sample(low);
261 const double middle_x = (left.x() + right.x()) * 0.5;
262 return x < middle_x ? left : right;
263}
264
265} // namespace PJ

Callers 3

showPointValuesMethod · 0.85
referencePointAtFunction · 0.85
setPositionMethod · 0.85

Calls 3

dataSizeMethod · 0.45
sampleMethod · 0.45
xMethod · 0.45

Tested by

no test coverage detected