// Find the iterators representing the lower bound of startRT and the upper bound of endRT,
// i.e. the first point in rt vector >= startRT and first point > endRT.
// If interpolate is true: extend the range before the startRT to previous data point
// unless it's an exact match.
// No interpolation is happening here (with rt vector), but the same interface is used to obtain
// signal and baseline vectors where the interpolation at those additional points will happen.
// Returns true if the extension of start_lb took place, and false otherwise.
// The corresponding iterator positions are returned through start_lb and end_ub references.
// The *end_ub will always have higher value than endRT, unless it's file->rt.cend().
// Therefore, if interpolation is used, this data point can be substituted by endRT.
// This function assumes that this.file is present. It will not crash, but wouldn't work either;
// the iterators will be left unchanged.
bool ChromTreeItem::getRTRangeIterators(double startRT, double endRT, bool interpolate,
QList<double>::const_iterator &start_lb, QList<double>::const_iterator &end_ub) {
bool set_before = false; // add point before lower_bound
if(!file) return false;
// Find the point at or larger than startRT
start_lb = std::lower_bound(file->rt.cbegin(), file->rt.cend(), startRT);
// Find first point larger than endRT
end_ub = std::upper_bound(file->rt.cbegin(), file->rt.cend(), endRT);
if(start_lb == end_ub) {
// Iterators are the same - requested range doesn't intersect the rt vector
// This should construct an empty QVector
} else {
if(end_ub != file->rt.cend()) {
// The QVector constructor doesn't include the final position.
// We want it to be included.
++end_ub;
}
// If interpolation is active and the value at start_lb is > startRT, then, if possible, extend the range
// by one element before start_lb (will not extend if start_lb == startRT).
if(interpolate && start_lb != file->rt.cbegin() && *start_lb > startRT) {
--start_lb;
set_before = true;
}
}
return set_before;
}