| 84 | } |
| 85 | |
| 86 | Size Mobilogram::findNearest(CoordinateType mb) const |
| 87 | { |
| 88 | // no peak => no search |
| 89 | if (empty()) |
| 90 | { |
| 91 | throw Exception::Precondition(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "There must be at least one peak to determine the nearest peak!"); |
| 92 | } |
| 93 | // search for position for inserting |
| 94 | ConstIterator it = MBBegin(mb); |
| 95 | // border cases |
| 96 | if (it == cbegin()) |
| 97 | { |
| 98 | return 0; |
| 99 | } |
| 100 | if (it == cend()) |
| 101 | { |
| 102 | return size() - 1; |
| 103 | } |
| 104 | // the peak before or the current peak are closest |
| 105 | auto it2 = it; |
| 106 | --it2; |
| 107 | if (std::fabs(it->getMobility() - mb) < std::fabs(it2->getMobility() - mb)) |
| 108 | { |
| 109 | return Size(it - cbegin()); |
| 110 | } |
| 111 | else |
| 112 | { |
| 113 | return Size(it2 - cbegin()); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | Int Mobilogram::findNearest(CoordinateType mb, CoordinateType tolerance) const |
| 118 | { |