37 #include <OpenMS/config.h>
102 return (min_ <= value) & (value <= max_);
149 min_ = std::min(min_, other.
min_);
150 max_ = std::max(max_, other.
max_);
156 min_ = std::min(min_, value);
157 max_ = std::max(max_, value);
165 if (isEmpty())
return;
177 if (min_ == max_) extendLeftRight(min_span / 2);
188 if (isEmpty())
return;
191 min_ = std::max(min_, other.
min_);
192 max_ = std::min(max_, other.
max_);
202 if (isEmpty())
return;
207 if (getSpan() > sandbox.
getSpan())
209 max_ = min_ + sandbox.
getSpan();
211 if (min_ < sandbox.
min_)
213 shift(sandbox.
min_ - min_);
215 else if (max_ > sandbox.
max_)
217 shift(sandbox.
max_ - max_);
236 if (isEmpty())
return;
237 const double dist = max_ - min_;
238 const double extension = dist * (factor - 1) / 2;
247 if (isEmpty())
return;
256 if (isEmpty())
return nan(
"");
257 return min_ + (max_ - min_) / 2.0;
264 if (isEmpty())
return nan(
"");
270 return min_ == rhs.
min_ && max_ == rhs.
max_;
280 if (isEmpty())
return {std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max()};
281 else return {min_, max_};
286 double min_ = std::numeric_limits<double>::max();
287 double max_ = std::numeric_limits<double>::lowest();
587 template<
typename... RangeBases>
599 using T_BASE = std::decay_t<decltype(*base)>;
600 equal &= ((T_BASE&) rhs == (T_BASE&) *
this);
614 template <
typename... RangeBasesOther>
619 using T_BASE = std::decay_t<decltype(*base)>;
622 base->operator=((T_BASE&) rhs);
634 template<
typename... RangeBasesOther>
639 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION ,
"No assignment took place (no dimensions in common!);");
648 template<
typename... RangeBasesOther>
653 using T_BASE = std::decay_t<decltype(*base)>;
656 base->extend((T_BASE&) rhs);
667 template<
typename... RangeBasesOther>
672 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"No assignment took place (no dimensions in common!);");
680 base->scaleBy(factor);
695 base->minSpanIfSingular(min_span);
705 template<
typename... RangeBasesOther>
710 using T_BASE = std::decay_t<decltype(*base)>;
713 const auto& rhs_base = (T_BASE&)rhs;
714 if (!rhs_base.isEmpty()) base->
pushInto(rhs_base);
726 template<
typename... RangeBasesOther>
731 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"No assignment took place (no dimensions in common!);");
740 template<
typename... RangeBasesOther>
745 using T_BASE = std::decay_t<decltype(*base)>;
748 const auto& rhs_base = (T_BASE&)rhs;
749 if (!rhs_base.isEmpty()) base->
clampTo(rhs_base);
761 template<
typename... RangeBasesOther>
766 throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
"No assignment took place (no dimensions in common!);");
776 using Base = std::decay_t<decltype(*base)>;
777 if (base->DIM == dim)
778 r_base = (Base*)
this;
781 assert((r_base !=
nullptr) &&
"No base class has this MSDim!");
791 using Base = std::decay_t<decltype(*base)>;
792 if (base->DIM == dim)
793 r_base = (Base*)
this;
796 assert((r_base !=
nullptr) &&
"No base class has this MSDim!");
803 constexpr
size_t total{
sizeof...(RangeBases)};
806 count += !base->isEmpty();
823 template<
typename... RangeBasesOther>
826 bool contained =
true;
827 bool has_overlap =
false;
829 using T_BASE = std::decay_t<decltype(*base)>;
833 if (((T_BASE&)rhs).isEmpty())
return;
834 if (base->contains((T_BASE&) rhs))
return;
858 if constexpr (std::is_base_of_v<RangeRT, ThisRangeType>) this->
RangeRT::clear();
861 if constexpr (std::is_base_of_v<RangeMZ, ThisRangeType>) this->
RangeMZ::clear();
874 assert(
false &&
"This should never be reached. Did you forget to implement a new DIM_UNIT?");
889 template<
typename Visitor>
892 (void(visitor(
static_cast<RangeBases*
>(
this))), ...);
895 template<
typename Visitor>
898 (void(visitor(
static_cast<const RangeBases*
>(
this))), ...);
902 template<
typename Visitor>
905 (void(visitor(
static_cast<const RangeBases*
>(
nullptr))), ...);
909 template<
typename... Range>
918 template <
typename ...RangeBases>
Invalid range exception.
Definition: Exception.h:278
Definition: RangeManager.h:921
const ThisRangeType & getRange() const
get range of current data (call updateRanges() before to ensure the range is accurate)
Definition: RangeManager.h:930
typename RangeManager< RangeBases... >::ThisRangeType ThisRangeType
Definition: RangeManager.h:923
virtual void updateRanges()=0
ThisRangeType & getRange()
get mutable range, provided for efficiency reasons (avoid updateRanges(), if only minor changes were ...
Definition: RangeManager.h:936
Handles the management of a multidimensional range, e.g. RangeMZ and RangeIntensity for spectra.
Definition: RangeManager.h:589
void pushInto(const RangeManager< RangeBasesOther... > &sandbox)
Definition: RangeManager.h:727
bool assignUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:615
const RangeBase & getRangeForDim(MSDim dim) const
obtain a range dimension at runtime using dim
Definition: RangeManager.h:771
bool pushIntoUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:706
bool clampToUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:741
HasRangeType hasRange() const
is any/some/all dimension in this range populated?
Definition: RangeManager.h:801
RangeBase & getRangeForDim(MSDim dim)
obtain a range dimension at runtime using dim
Definition: RangeManager.h:786
bool operator==(const RangeManager &rhs) const
Definition: RangeManager.h:595
void for_each_base_(Visitor &&visitor)
use fold expression to iterate over all RangeBases of RangeManager and apply a lambda (Visitor) for e...
Definition: RangeManager.h:890
void for_each_base_(Visitor &&visitor) const
.. and a const version
Definition: RangeManager.h:896
ThisRangeType & clear(const DIM_UNIT range)
Definition: RangeManager.h:853
void clampTo(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:762
void scaleBy(const double factor)
calls RangeBase::scale() for each dimension
Definition: RangeManager.h:677
void minSpanIfSingular(const double min_span)
If any dimension is a single point, e.g. min==max, then extend this dimension by min_span / 2 on eith...
Definition: RangeManager.h:692
auto & assign(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:635
bool extendUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:649
void clearRanges()
Resets all ranges.
Definition: RangeManager.h:844
void printRange(std::ostream &out) const
print each dimension (base classes) to a stream
Definition: RangeManager.h:880
void extend(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:668
bool operator!=(const RangeManager &rhs) const
Definition: RangeManager.h:605
bool containsAll(const RangeManager< RangeBasesOther... > &rhs) const
Definition: RangeManager.h:824
static void static_for_each_base_(Visitor &&visitor)
use fold expression to iterate over all RangeBases of RangeManager and apply a lambda (Visitor) for e...
Definition: RangeManager.h:903
bool contains(T value, T min, T max)
Is a value contained in [min, max] ?
Definition: MathFunctions.h:87
FLASHIda C++ to C# (or vice versa) bridge functions The functions here are called in C# to invoke fun...
Definition: FeatureDeconvolution.h:48
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
DIM
Definition: DimMapper.h:590
MSDim
Dimensions of data acquisition for MS data.
Definition: RangeManager.h:50
DIM_UNIT
Definition: CommonEnums.h:46
@ IM_VSSC
volt-second per square centimeter (i.e. 1/K_0)
@ FAIMS_CV
FAIMS compensation voltage.
@ IM_MS
ion mobility milliseconds
HasRangeType
Enum listing state of dimensions (RangeBases)
Definition: RangeManager.h:566
@ ALL
all dimensions are filled
@ SOME
some dimensions are empty, some are filled
@ NONE
all dimensions are empty (=cleared)
Base class for a simple range with minimum and maximum.
Definition: RangeManager.h:59
double max_
Definition: RangeManager.h:287
double getSpan() const
Definition: RangeManager.h:262
RangeBase(const RangeBase &rhs)=default
Copy C'tor.
void setMin(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:118
RangeBase & operator=(RangeBase &&rhs) noexcept=default
Move assignment (seems useless, but is required for completeness in derived classes' move c'tor)
std::pair< double, double > getNonEmptyRange() const
Return the current range, or (if empty) a full range (-1e308, 1e308).
Definition: RangeManager.h:277
void scaleBy(const double factor)
Scale the range of the dimension by a factor. A factor > 1 increases the range; factor < 1 decreases ...
Definition: RangeManager.h:234
RangeBase & operator=(const RangeBase &rhs)=default
Assignment operator.
void minSpanIfSingular(const double min_span)
If the current range is a single point, e.g. min==max, then extend the range by min_span / 2 on eithe...
Definition: RangeManager.h:175
void pushInto(const RangeBase &sandbox)
Definition: RangeManager.h:200
void shift(const double distance)
Definition: RangeManager.h:245
~RangeBase() noexcept=default
D'tor.
bool contains(const double value) const
is value within [min, max]?
Definition: RangeManager.h:100
double center() const
Definition: RangeManager.h:254
RangeBase()=default
C'tor: initialize with empty range.
void extend(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:154
void extendLeftRight(const double by)
Definition: RangeManager.h:163
RangeBase(RangeBase &&rhs) noexcept=default
Move C'tor (seems useless, but is required for completeness in derived classes' move c'tor)
bool contains(const RangeBase &inner_range) const
is the range inner_range within [min, max]?
Definition: RangeManager.h:106
void clampTo(const RangeBase &other)
Definition: RangeManager.h:186
double getMin() const
only useful if isEmpty() returns false
Definition: RangeManager.h:134
void clear()
make the range empty, i.e. isEmpty() will be true
Definition: RangeManager.h:88
void setMax(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:126
bool isEmpty() const
is the range empty (i.e. min > max)?
Definition: RangeManager.h:94
double min_
Definition: RangeManager.h:286
RangeBase(const double min, const double max)
Definition: RangeManager.h:66
bool operator==(const RangeBase &rhs) const
Definition: RangeManager.h:268
double getMax() const
only useful if isEmpty() returns false
Definition: RangeManager.h:140
void extend(const RangeBase &other)
ensure the range includes the range of other
Definition: RangeManager.h:147
Definition: RangeManager.h:429
void setMinIntensity(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:452
double getMinIntensity() const
only useful if isEmpty() returns false
Definition: RangeManager.h:464
void extendIntensity(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:477
bool containsIntensity(const double value) const
is value within [min, max]?
Definition: RangeManager.h:483
RangeIntensity & operator=(const RangeBase &rhs)
Definition: RangeManager.h:439
RangeIntensity(const double min, const double max)
Definition: RangeManager.h:434
double getMaxIntensity() const
only useful if isEmpty() returns false
Definition: RangeManager.h:470
bool containsIntensity(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:489
void setMaxIntensity(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:458
Definition: RangeManager.h:362
bool containsMZ(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:422
void setMaxMZ(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:391
void extendMZ(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:410
void setMinMZ(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:385
double getMaxMZ() const
only useful if isEmpty() returns false
Definition: RangeManager.h:403
double getMinMZ() const
only useful if isEmpty() returns false
Definition: RangeManager.h:397
RangeMZ & operator=(const RangeBase &rhs)
Definition: RangeManager.h:372
RangeMZ(const double min, const double max)
Definition: RangeManager.h:367
bool containsMZ(const double value) const
is value within [min, max]?
Definition: RangeManager.h:416
Definition: RangeManager.h:497
bool containsMobility(const double value) const
is value within [min, max]?
Definition: RangeManager.h:550
void extendMobility(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:544
RangeMobility & operator=(const RangeBase &rhs)
Definition: RangeManager.h:506
double getMinMobility() const
only useful if isEmpty() returns false
Definition: RangeManager.h:531
bool containsMobility(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:556
double getMaxMobility() const
only useful if isEmpty() returns false
Definition: RangeManager.h:537
void setMinMobility(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:519
void setMaxMobility(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:525
RangeMobility(const double min, const double max)
Definition: RangeManager.h:501
Definition: RangeManager.h:292
bool containsRT(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:353
void extendRT(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:341
double getMaxRT() const
only useful if isEmpty() returns false
Definition: RangeManager.h:334
RangeRT(const double min, const double max)
Definition: RangeManager.h:297
void setMaxRT(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:322
void setMinRT(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:316
double getMinRT() const
only useful if isEmpty() returns false
Definition: RangeManager.h:328
RangeRT & operator=(const RangeBase &rhs)
Definition: RangeManager.h:302
bool containsRT(const double value) const
is value within [min, max]?
Definition: RangeManager.h:347