MCPcopy Create free account
hub / github.com/CieNTi/serial_port_plotter / pickClosest

Method pickClosest

qcustomplot/qcustomplot.cpp:5796–5807  ·  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

5794 This method assumes \a candidates is not empty and sorted in ascending order.
5795*/
5796double QCPAxisTicker::pickClosest(double target, const QVector<double> &candidates) const
5797{
5798 if (candidates.size() == 1)
5799 return candidates.first();
5800 QVector<double>::const_iterator it = std::lower_bound(candidates.constBegin(), candidates.constEnd(), target);
5801 if (it == candidates.constEnd())
5802 return *(it-1);
5803 else if (it == candidates.constBegin())
5804 return *it;
5805 else
5806 return target-*(it-1) < *it-target ? *(it-1) : *it;
5807}
5808
5809/*! \internal
5810

Callers

nothing calls this directly

Calls 3

constBeginMethod · 0.80
constEndMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected