OpenMS
RangeManager.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2023.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Chris Bielow $
32 // $Authors: Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/config.h>
40 
41 #include <cmath> // for nan()
42 #include <algorithm> // for min/max
43 #include <cassert>
44 #include <iosfwd> // for std::ostream
45 
46 namespace OpenMS
47 {
49  enum class MSDim
50  {
51  RT,
52  MZ,
53  INT,
54  IM
55  };
56 
57  struct RangeRT;
58  struct RangeMZ;
59  struct RangeIntensity;
60  struct RangeMobility;
61 
63  struct OPENMS_DLLAPI RangeBase
64  {
65  public:
67  RangeBase() = default;
68 
71  RangeBase(const double min, const double max) :
72  min_(min), max_(max)
73  {
74  if (min_ > max_)
75  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "Invalid initialization of range");
76  }
78  RangeBase(const RangeBase& rhs) = default;
79 
81  RangeBase(RangeBase&& rhs) noexcept = default;
82 
84  RangeBase& operator=(const RangeBase& rhs) = default;
85 
87  RangeBase& operator=(RangeBase&& rhs) noexcept = default;
88 
90  ~RangeBase() noexcept = default;
91 
93  operator RangeRT() const;
95  operator RangeMZ() const;
97  operator RangeIntensity() const;
99  operator RangeMobility() const;
100 
102  void clear()
103  {
104  *this = RangeBase(); // overwrite with fresh instance
105  }
106 
108  bool isEmpty() const
109  {
110  return min_ > max_;
111  }
112 
114  bool contains(const double value) const
115  {
116  return uint8_t(min_ <= value) & uint8_t(value <= max_); // using && leads to branches on all compilers in Debug and in Release on MVSC
117  }
118 
120  bool contains(const RangeBase& inner_range) const
121  {
122  return uint8_t(contains(inner_range.min_)) & uint8_t(contains(inner_range.max_)); // using && leads to branches on all compilers in Debug and in Release on MVSC
123  }
124 
130 
132  void setMin(const double min)
133  {
134  min_ = min;
135  if (max_ < min)
136  max_ = min;
137  }
138 
140  void setMax(const double max)
141  {
142  max_ = max;
143  if (min_ > max)
144  min_ = max;
145  }
146 
148  double getMin() const
149  {
150  return min_;
151  }
152 
154  double getMax() const
155  {
156  return max_;
157  }
159 
161  void extend(const RangeBase& other)
162  {
163  min_ = std::min(min_, other.min_);
164  max_ = std::max(max_, other.max_);
165  }
166 
168  void extend(const double value)
169  {
170  min_ = std::min(min_, value);
171  max_ = std::max(max_, value);
172  }
173 
177  void extendLeftRight(const double by)
178  {
179  if (isEmpty()) return;
180  min_ -= by;
181  max_ += by;
182  }
183 
189  void minSpanIfSingular(const double min_span)
190  {
191  if (min_ == max_) extendLeftRight(min_span / 2);
192  }
193 
200  void clampTo(const RangeBase& other)
201  {
202  if (isEmpty()) return;
203  if (other.isEmpty()) throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
204 
205  min_ = std::max(min_, other.min_);
206  max_ = std::min(max_, other.max_);
207  }
208 
214  void pushInto(const RangeBase& sandbox)
215  {
216  if (isEmpty()) return;
217  if (sandbox.isEmpty()) throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
218 
219  if (!sandbox.contains(*this))
220  {
221  if (getSpan() > sandbox.getSpan())
222  { // make interval fit into sandbox (= ensure full containment)
223  max_ = min_ + sandbox.getSpan();
224  }
225  if (min_ < sandbox.min_)
226  { // need to shift right (positive shift)
227  shift(sandbox.min_ - min_);
228  }
229  else if (max_ > sandbox.max_)
230  { // need to shift left (negative shift)
231  shift(sandbox.max_ - max_);
232  }
233  }
234 
235  }
236 
237 
248  void scaleBy(const double factor)
249  {
250  if (isEmpty()) return;
251  const double dist = max_ - min_;
252  const double extension = dist * (factor - 1) / 2;
253  min_ -= extension;
254  max_ += extension;
255  }
256 
259  void shift(const double distance)
260  {
261  if (isEmpty()) return;
262  min_ += distance;
263  max_ += distance;
264  }
265 
268  double center() const
269  {
270  if (isEmpty()) return nan("");
271  return min_ + (max_ - min_) / 2.0;
272  }
273 
276  double getSpan() const
277  {
278  if (isEmpty()) return nan("");
279  return max_ - min_;
280  }
281 
282  bool operator==(const RangeBase& rhs) const
283  {
284  return min_ == rhs.min_ && max_ == rhs.max_;
285  }
286 
291  std::pair<double, double> getNonEmptyRange() const
292  {
293  // pair with full range
294  if (isEmpty()) return {std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max()};
295  else return {min_, max_};
296  }
297 
298  protected:
299  // make members non-accessible to maintain invariant: min <= max (unless uninitialized)
300  double min_ = std::numeric_limits<double>::max();
301  double max_ = std::numeric_limits<double>::lowest();
302  };
303 
304  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& out, const RangeBase& b);
305 
306  struct OPENMS_DLLAPI RangeRT : public RangeBase {
307 
308  const static MSDim DIM = MSDim::RT;
309 
310  // Rule of 0!
311  using RangeBase::RangeBase; // inherit C'tors from base
312 
318 
320  void setMinRT(const double min)
321  {
322  setMin(min);
323  }
324 
326  void setMaxRT(const double max)
327  {
328  setMax(max);
329  }
330 
332  double getMinRT() const
333  {
334  return min_;
335  }
336 
338  double getMaxRT() const
339  {
340  return max_;
341  }
343 
345  void extendRT(const double value)
346  {
347  extend(value);
348  }
349 
351  bool containsRT(const double value) const
352  {
353  return RangeBase::contains(value);
354  }
355 
357  bool containsRT(const RangeBase& inner_range) const
358  {
359  return RangeBase::contains(inner_range);
360  }
361  };
362 
363  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& out, const RangeRT& range);
364 
365  struct OPENMS_DLLAPI RangeMZ : public RangeBase
366  {
367 
368  const static MSDim DIM = MSDim::MZ;
369 
370  // Rule of 0!
371  using RangeBase::RangeBase; // inherit C'tors from base
372 
378 
380  void setMinMZ(const double min)
381  {
382  setMin(min);
383  }
384 
386  void setMaxMZ(const double max)
387  {
388  setMax(max);
389  }
390 
392  double getMinMZ() const
393  {
394  return min_;
395  }
396 
398  double getMaxMZ() const
399  {
400  return max_;
401  }
403 
405  void extendMZ(const double value)
406  {
407  extend(value);
408  }
409 
411  bool containsMZ(const double value) const
412  {
413  return RangeBase::contains(value);
414  }
415 
417  bool containsMZ(const RangeBase& inner_range) const
418  {
419  return RangeBase::contains(inner_range);
420  }
421  };
422  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& out, const RangeMZ& range);
423 
424  struct OPENMS_DLLAPI RangeIntensity : public RangeBase {
425 
426  const static MSDim DIM = MSDim::INT;
427 
428  // Rule of 0!
429  using RangeBase::RangeBase; // inherit C'tors from base
430 
436 
438  void setMinIntensity(const double min)
439  {
440  setMin(min);
441  }
442 
444  void setMaxIntensity(const double max)
445  {
446  setMax(max);
447  }
448 
450  double getMinIntensity() const
451  {
452  return min_;
453  }
454 
456  double getMaxIntensity() const
457  {
458  return max_;
459  }
461 
463  void extendIntensity(const double value)
464  {
465  extend(value);
466  }
467 
469  bool containsIntensity(const double value) const
470  {
471  return RangeBase::contains(value);
472  }
473 
475  bool containsIntensity(const RangeBase& inner_range) const
476  {
477  return RangeBase::contains(inner_range);
478  }
479  };
480  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& out, const RangeIntensity& range);
481 
482  struct OPENMS_DLLAPI RangeMobility : public RangeBase
483  {
484  const static MSDim DIM = MSDim::IM;
485 
486  // Rule of 0!
487  using RangeBase::RangeBase; // inherit C'tors from base
488 
494 
496  void setMinMobility(const double min)
497  {
498  setMin(min);
499  }
500 
502  void setMaxMobility(const double max)
503  {
504  setMax(max);
505  }
506 
508  double getMinMobility() const
509  {
510  return min_;
511  }
512 
514  double getMaxMobility() const
515  {
516  return max_;
517  }
519 
521  void extendMobility(const double value)
522  {
523  extend(value);
524  }
525 
527  bool containsMobility(const double value) const
528  {
529  return RangeBase::contains(value);
530  }
531 
533  bool containsMobility(const RangeBase& inner_range) const
534  {
535  return RangeBase::contains(inner_range);
536  }
537  };
538 
539  OPENMS_DLLAPI std::ostream& operator<<(std::ostream& out, const RangeMobility& range);
540 
542  enum class HasRangeType
543  {
544  ALL,
545  SOME,
546  NONE
547  };
548 
564  template<typename... RangeBases>
565  class RangeManager : public RangeBases...
566  {
567  public:
568  using ThisRangeType = RangeManager<RangeBases...>;
569  // rule of 0 -- no need for a virtual d'tor or anything fancy
570  // ...
571 
572  bool operator==(const RangeManager& rhs) const
573  {
574  bool equal = true;
575  for_each_base_([&](auto* base) {
576  using T_BASE = std::decay_t<decltype(*base)>; // remove const/ref qualifiers
577  equal &= ((T_BASE&) rhs == (T_BASE&) *this);
578  });
579  return equal;
580  }
581 
582  bool operator!=(const RangeManager& rhs) const
583  {
584  return !operator==(rhs);
585  }
586 
591  template <typename... RangeBasesOther>
593  {
594  bool found = false;
595  for_each_base_([&](auto* base) {
596  using T_BASE = std::decay_t<decltype(*base)>; // remove const/ref qualifiers
597  if constexpr (std::is_base_of_v<T_BASE, RangeManager<RangeBasesOther...>>)
598  {
599  base->operator=((T_BASE&) rhs);
600  found = true;
601  }
602  });
603 
604  return found;
605  }
606 
611  template<typename... RangeBasesOther>
613  {
614  if (!assignUnsafe(rhs))
615  {
616  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION , "No assignment took place (no dimensions in common!);");
617  }
618  return *this;
619  }
620 
625  template<typename... RangeBasesOther>
627  {
628  bool found = false;
629  for_each_base_([&](auto* base) {
630  using T_BASE = std::decay_t<decltype(*base)>; // remove const/ref qualifiers
631  if constexpr (std::is_base_of_v<T_BASE, RangeManager<RangeBasesOther...>>)
632  {
633  base->extend((T_BASE&) rhs);
634  found = true;
635  }
636  });
637  return found;
638  }
639 
644  template<typename... RangeBasesOther>
646  {
647  if (!extendUnsafe(rhs))
648  {
649  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "No assignment took place (no dimensions in common!);");
650  }
651  }
652 
654  void scaleBy(const double factor)
655  {
656  for_each_base_([&](auto* base) {
657  base->scaleBy(factor);
658  });
659  }
660 
669  void minSpanIfSingular(const double min_span)
670  {
671  for_each_base_([&](auto* base) {
672  base->minSpanIfSingular(min_span);
673  });
674  }
675 
676 
682  template<typename... RangeBasesOther>
684  {
685  bool found = false;
686  for_each_base_([&](auto* base) {
687  using T_BASE = std::decay_t<decltype(*base)>; // remove const/ref qualifiers
688  if constexpr (std::is_base_of_v<T_BASE, RangeManager<RangeBasesOther...>>)
689  {
690  const auto& rhs_base = (T_BASE&)rhs;
691  if (!rhs_base.isEmpty()) base->pushInto(rhs_base);
692  found = true;
693  }
694  });
695  return found;
696  }
697 
703  template<typename... RangeBasesOther>
705  {
706  if (!pushIntoUnsafe(sandbox))
707  {
708  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "No assignment took place (no dimensions in common!);");
709  }
710  }
711 
712 
717  template<typename... RangeBasesOther>
719  {
720  bool found = false;
721  for_each_base_([&](auto* base) {
722  using T_BASE = std::decay_t<decltype(*base)>; // remove const/ref qualifiers
723  if constexpr (std::is_base_of_v<T_BASE, RangeManager<RangeBasesOther...>>)
724  {
725  const auto& rhs_base = (T_BASE&)rhs;
726  if (!rhs_base.isEmpty()) base->clampTo(rhs_base);
727  found = true;
728  }
729  });
730  return found;
731  }
732 
738  template<typename... RangeBasesOther>
740  {
741  if (!clampToUnsafe(rhs))
742  {
743  throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, "No assignment took place (no dimensions in common!);");
744  }
745  }
746 
748  const RangeBase& getRangeForDim(MSDim dim) const
749  {
750  RangeBase* r_base = nullptr;
751 
752  static_for_each_base_([&](auto* base) {
753  using Base = std::decay_t<decltype(*base)>; // remove const/ref qualifiers
754  if (base->DIM == dim)
755  r_base = (Base*)this;
756  });
757 
758  assert((r_base != nullptr) && "No base class has this MSDim!");
759  return *r_base;
760  }
761 
764  {
765  RangeBase* r_base = nullptr;
766 
767  static_for_each_base_([&](auto* base) {
768  using Base = std::decay_t<decltype(*base)>; // remove const/ref qualifiers
769  if (base->DIM == dim)
770  r_base = (Base*) this;
771  });
772 
773  assert((r_base != nullptr) && "No base class has this MSDim!");
774  return *r_base;
775  }
776 
779  {
780  constexpr size_t total{sizeof...(RangeBases)};// total number of bases
781  size_t count{0};
782  for_each_base_([&](auto* base) {
783  count += !base->isEmpty();
784  });
785  switch (count)
786  {
787  case 0:
788  return HasRangeType::NONE;
789  case total:
790  return HasRangeType::ALL;
791  default:
792  return HasRangeType::SOME;
793  }
794  }
795 
800  template<typename... RangeBasesOther>
802  {
803  bool contained = true; // assume rhs is contained, until proven otherwise
804  bool has_overlap = false;
805  for_each_base_([&](auto* base) {
806  using T_BASE = std::decay_t<decltype(*base)>; // remove const/ref qualifiers
807  if constexpr (std::is_base_of_v<T_BASE, RangeManager<RangeBasesOther...>>)
808  {
809  has_overlap = true; // at least one dimension overlaps
810  if (((T_BASE&)rhs).isEmpty()) return;
811  if (base->contains((T_BASE&) rhs)) return;
812  contained = false;
813  }
814  });
815  if (!has_overlap) throw Exception::InvalidRange(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION);
816 
817  return contained;
818  }
819 
821  void clearRanges()
822  {
823  for_each_base_([&](auto* base) {
824  base->clear();
825  });
826  }
827 
831  {
832  switch (range)
833  {
834  case DIM_UNIT::RT:
835  if constexpr (std::is_base_of_v<RangeRT, ThisRangeType>) this->RangeRT::clear();
836  break;
837  case DIM_UNIT::MZ:
838  if constexpr (std::is_base_of_v<RangeMZ, ThisRangeType>) this->RangeMZ::clear();
839  break;
840  case DIM_UNIT::INT:
841  if constexpr (std::is_base_of_v<RangeIntensity, ThisRangeType>) this->RangeIntensity::clear();
842  break;
843  // assume all ion mobility ranges are the same and never occur together. If this is violated at some point, then split RangeMobility into subclasses...
844  case DIM_UNIT::IM_MS:
845  case DIM_UNIT::IM_VSSC:
846  case DIM_UNIT::FAIMS_CV:
847  if constexpr (std::is_base_of_v<RangeMobility, ThisRangeType>) this->RangeMobility::clear();
848  break;
849  default:
850  // all cases should be covered above
851  assert(false && "This should never be reached. Did you forget to implement a new DIM_UNIT?");
852  }
853  return *this;
854  }
855 
857  void printRange(std::ostream& out) const
858  {
859  for_each_base_([&](auto* base) {
860  out << *base;
861  });
862  }
863 
864  protected:
866  template<typename Visitor>
867  void for_each_base_(Visitor&& visitor)
868  {
869  (void(visitor(static_cast<RangeBases*>(this))), ...);
870  }
872  template<typename Visitor>
873  void for_each_base_(Visitor&& visitor) const
874  {
875  (void(visitor(static_cast<const RangeBases*>(this))), ...);
876  }
877 
879  template<typename Visitor>
880  static void static_for_each_base_(Visitor&& visitor)
881  {
882  (void(visitor(static_cast<const RangeBases*>(nullptr))), ...);
883  }
884  };
885 
886  template<typename... Range>
887  std::ostream& operator<<(std::ostream& out, const RangeManager<Range...>& me)
888  {
889  me.printRange(out);
890  return out;
891  }
892 
895  template <typename ...RangeBases>
897  : public RangeManager<RangeBases...>
898  {
899  public:
900  using ThisRangeType = typename RangeManager<RangeBases...>::ThisRangeType;
901 
903  virtual ~RangeManagerContainer() = default; // required since we have virtual methods
904 
907  virtual void updateRanges() = 0;
908 
910  const ThisRangeType& getRange() const
911  {
912  return (ThisRangeType&)*this;
913  }
914 
917  {
918  return (ThisRangeType&)*this;
919  }
920  };
921 
924 
925 } // namespace OpenMS
Invalid range exception.
Definition: Exception.h:278
Definition: RangeManager.h:898
const ThisRangeType & getRange() const
get range of current data (call updateRanges() before to ensure the range is accurate)
Definition: RangeManager.h:910
typename RangeManager< RangeBases... >::ThisRangeType ThisRangeType
Definition: RangeManager.h:900
virtual void updateRanges()=0
ThisRangeType & getRange()
get mutable range, provided for efficiency reasons (avoid updateRanges(), if only minor changes were ...
Definition: RangeManager.h:916
virtual ~RangeManagerContainer()=default
D'tor.
Handles the management of a multidimensional range, e.g. RangeMZ and RangeIntensity for spectra.
Definition: RangeManager.h:566
void pushInto(const RangeManager< RangeBasesOther... > &sandbox)
Definition: RangeManager.h:704
bool assignUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:592
const RangeBase & getRangeForDim(MSDim dim) const
obtain a range dimension at runtime using dim
Definition: RangeManager.h:748
bool pushIntoUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:683
bool clampToUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:718
HasRangeType hasRange() const
is any/some/all dimension in this range populated?
Definition: RangeManager.h:778
RangeBase & getRangeForDim(MSDim dim)
obtain a range dimension at runtime using dim
Definition: RangeManager.h:763
bool operator==(const RangeManager &rhs) const
Definition: RangeManager.h:572
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:867
void for_each_base_(Visitor &&visitor) const
.. and a const version
Definition: RangeManager.h:873
ThisRangeType & clear(const DIM_UNIT range)
Definition: RangeManager.h:830
void clampTo(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:739
void scaleBy(const double factor)
calls RangeBase::scale() for each dimension
Definition: RangeManager.h:654
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:669
auto & assign(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:612
bool extendUnsafe(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:626
void clearRanges()
Resets all ranges.
Definition: RangeManager.h:821
void printRange(std::ostream &out) const
print each dimension (base classes) to a stream
Definition: RangeManager.h:857
void extend(const RangeManager< RangeBasesOther... > &rhs)
Definition: RangeManager.h:645
bool operator!=(const RangeManager &rhs) const
Definition: RangeManager.h:582
bool containsAll(const RangeManager< RangeBasesOther... > &rhs) const
Definition: RangeManager.h:801
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:880
bool contains(T value, T min, T max)
Is a value contained in [min, max] ?
Definition: MathFunctions.h:88
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
DIM
Definition: DimMapper.h:627
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)
@ INT
intensity
@ FAIMS_CV
FAIMS compensation voltage.
@ RT
RT in seconds.
@ IM_MS
ion mobility milliseconds
HasRangeType
Enum listing state of dimensions (RangeBases)
Definition: RangeManager.h:543
@ 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:64
double max_
Definition: RangeManager.h:301
double getSpan() const
Definition: RangeManager.h:276
RangeBase(const RangeBase &rhs)=default
Copy C'tor.
void setMin(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:132
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:291
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:248
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:189
void pushInto(const RangeBase &sandbox)
Definition: RangeManager.h:214
void shift(const double distance)
Definition: RangeManager.h:259
~RangeBase() noexcept=default
D'tor.
bool contains(const double value) const
is value within [min, max]?
Definition: RangeManager.h:114
double center() const
Definition: RangeManager.h:268
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:168
void extendLeftRight(const double by)
Definition: RangeManager.h:177
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:120
void clampTo(const RangeBase &other)
Definition: RangeManager.h:200
double getMin() const
only useful if isEmpty() returns false
Definition: RangeManager.h:148
void clear()
make the range empty, i.e. isEmpty() will be true
Definition: RangeManager.h:102
void setMax(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:140
bool isEmpty() const
is the range empty (i.e. min > max)?
Definition: RangeManager.h:108
double min_
Definition: RangeManager.h:300
RangeBase(const double min, const double max)
Definition: RangeManager.h:71
bool operator==(const RangeBase &rhs) const
Definition: RangeManager.h:282
double getMax() const
only useful if isEmpty() returns false
Definition: RangeManager.h:154
void extend(const RangeBase &other)
ensure the range includes the range of other
Definition: RangeManager.h:161
Definition: RangeManager.h:424
void setMinIntensity(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:438
double getMinIntensity() const
only useful if isEmpty() returns false
Definition: RangeManager.h:450
void extendIntensity(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:463
bool containsIntensity(const double value) const
is value within [min, max]?
Definition: RangeManager.h:469
double getMaxIntensity() const
only useful if isEmpty() returns false
Definition: RangeManager.h:456
bool containsIntensity(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:475
void setMaxIntensity(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:444
Definition: RangeManager.h:366
bool containsMZ(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:417
void setMaxMZ(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:386
void extendMZ(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:405
void setMinMZ(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:380
double getMaxMZ() const
only useful if isEmpty() returns false
Definition: RangeManager.h:398
double getMinMZ() const
only useful if isEmpty() returns false
Definition: RangeManager.h:392
bool containsMZ(const double value) const
is value within [min, max]?
Definition: RangeManager.h:411
Definition: RangeManager.h:483
bool containsMobility(const double value) const
is value within [min, max]?
Definition: RangeManager.h:527
void extendMobility(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:521
double getMinMobility() const
only useful if isEmpty() returns false
Definition: RangeManager.h:508
bool containsMobility(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:533
double getMaxMobility() const
only useful if isEmpty() returns false
Definition: RangeManager.h:514
void setMinMobility(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:496
void setMaxMobility(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:502
Definition: RangeManager.h:306
bool containsRT(const RangeBase &inner_range) const
is the range inner_range within [min, max] of this range?
Definition: RangeManager.h:357
void extendRT(const double value)
extend the range such that it includes the given value
Definition: RangeManager.h:345
double getMaxRT() const
only useful if isEmpty() returns false
Definition: RangeManager.h:338
void setMaxRT(const double max)
sets the maximum (and the minimum, if uninitialized)
Definition: RangeManager.h:326
void setMinRT(const double min)
sets the minimum (and the maximum, if uninitialized)
Definition: RangeManager.h:320
double getMinRT() const
only useful if isEmpty() returns false
Definition: RangeManager.h:332
bool containsRT(const double value) const
is value within [min, max]?
Definition: RangeManager.h:351