! \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. */
| 6421 | This method assumes \a candidates is not empty and sorted in ascending order. |
| 6422 | */ |
| 6423 | double 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 |
nothing calls this directly
no test coverage detected