MCPcopy Index your code
hub / github.com/Audio4Linux/JDSP4Linux / pickClosest

Method pickClosest

3rdparty/qcustomplot/qcustomplot.cpp:6423–6434  ·  view source on GitHub ↗

! \internal Returns the coordinate contained in \a candidates which is closest to the provided \a target. This method assumes \a candidates is not empty and sorted in ascending order. */

Source from the content-addressed store, hash-verified

6421 This method assumes \a candidates is not empty and sorted in ascending order.
6422*/
6423double QCPAxisTicker::pickClosest(double target, const QVector<double> &candidates) const
6424{
6425 if (candidates.size() == 1)
6426 return candidates.first();
6427 QVector<double>::const_iterator it = std::lower_bound(candidates.constBegin(), candidates.constEnd(), target);
6428 if (it == candidates.constEnd())
6429 return *(it-1);
6430 else if (it == candidates.constBegin())
6431 return *it;
6432 else
6433 return target-*(it-1) < *it-target ? *(it-1) : *it;
6434}
6435
6436/*! \internal
6437

Callers

nothing calls this directly

Calls 4

constBeginMethod · 0.80
constEndMethod · 0.80
lower_boundFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected