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