OpenMS
RangeBase Struct Reference

Base class for a simple range with minimum and maximum. More...

#include <OpenMS/KERNEL/RangeManager.h>

Inheritance diagram for RangeBase:
[legend]
Collaboration diagram for RangeBase:
[legend]

Public Member Functions

 RangeBase ()=default
 C'tor: initialize with empty range. More...
 
 RangeBase (const double min, const double max)
 
 RangeBase (const RangeBase &rhs)=default
 Copy C'tor. More...
 
 RangeBase (RangeBase &&rhs) noexcept=default
 Move C'tor (seems useless, but is required for completeness in derived classes' move c'tor) More...
 
RangeBaseoperator= (const RangeBase &rhs)=default
 Assignment operator. More...
 
RangeBaseoperator= (RangeBase &&rhs) noexcept=default
 Move assignment (seems useless, but is required for completeness in derived classes' move c'tor) More...
 
 ~RangeBase () noexcept=default
 D'tor. More...
 
 operator RangeRT () const
 conversion operator to allow accepting a RangeBase (instead of RangeRT) for the implicitly defined special members, e.g. assignment operator (RangeRT& operator=(const RangeRT&)) More...
 
 operator RangeMZ () const
 conversion operator to allow accepting a RangeBase (instead of RangeMZ) for the implicitly defined special members, e.g. assignment operator (RangeMZ& operator=(const RangeMZ&)) More...
 
 operator RangeIntensity () const
 conversion operator to allow accepting a RangeBase (instead of RangeIntensity) for the implicitly defined special members, e.g. assignment operator (RangeIntensity& operator=(const RangeIntensity&)) More...
 
 operator RangeMobility () const
 conversion operator to allow accepting a RangeBase (instead of RangeMobility) for the implicitly defined special members, e.g. assignment operator (RangeMobility& operator=(const RangeMobility&)) More...
 
void clear ()
 make the range empty, i.e. isEmpty() will be true More...
 
bool isEmpty () const
 is the range empty (i.e. min > max)? More...
 
bool contains (const double value) const
 is value within [min, max]? More...
 
bool contains (const RangeBase &inner_range) const
 is the range inner_range within [min, max]? More...
 
void extend (const RangeBase &other)
 ensure the range includes the range of other More...
 
void extend (const double value)
 extend the range such that it includes the given value More...
 
void extendLeftRight (const double by)
 
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 either side. More...
 
void clampTo (const RangeBase &other)
 
void pushInto (const RangeBase &sandbox)
 
void scaleBy (const double factor)
 Scale the range of the dimension by a factor. A factor > 1 increases the range; factor < 1 decreases it. More...
 
void shift (const double distance)
 
double center () const
 
double getSpan () const
 
bool operator== (const RangeBase &rhs) const
 
std::pair< double, double > getNonEmptyRange () const
 Return the current range, or (if empty) a full range (-1e308, 1e308). More...
 
Accessors for min and max

We use accessors, to keep range consistent (i.e. ensure that min <= max)

void setMin (const double min)
 sets the minimum (and the maximum, if uninitialized) More...
 
void setMax (const double max)
 sets the maximum (and the minimum, if uninitialized) More...
 
double getMin () const
 only useful if isEmpty() returns false More...
 
double getMax () const
 only useful if isEmpty() returns false More...
 

Protected Attributes

double min_ = std::numeric_limits<double>::max()
 
double max_ = std::numeric_limits<double>::lowest()
 

Detailed Description

Base class for a simple range with minimum and maximum.

Constructor & Destructor Documentation

◆ RangeBase() [1/4]

RangeBase ( )
default

C'tor: initialize with empty range.

◆ RangeBase() [2/4]

RangeBase ( const double  min,
const double  max 
)
inline

Custom C'tor to set min and max

Exceptions
Exception::InvalidRangeif min > max

◆ RangeBase() [3/4]

RangeBase ( const RangeBase rhs)
default

Copy C'tor.

◆ RangeBase() [4/4]

RangeBase ( RangeBase &&  rhs)
defaultnoexcept

Move C'tor (seems useless, but is required for completeness in derived classes' move c'tor)

◆ ~RangeBase()

~RangeBase ( )
defaultnoexcept

D'tor.

Member Function Documentation

◆ center()

double center ( ) const
inline

Compute the center point of the range If range is empty(), 'nan' will be returned

◆ clampTo()

void clampTo ( const RangeBase other)
inline

Ensure the range of this does not exceed the range of other. If other already contains() this range, nothing changes. If this range is entirely outside the range of other, the resulting range is empty. Empty ranges are not modified.

Exceptions
Exception::InvalidRangeif other is empty

References RangeBase::isEmpty(), RangeBase::max_, and RangeBase::min_.

◆ clear()

void clear ( )
inline

make the range empty, i.e. isEmpty() will be true

Referenced by RangeManager< RangeBases >::clear().

◆ contains() [1/2]

bool contains ( const double  value) const
inline

◆ contains() [2/2]

bool contains ( const RangeBase inner_range) const
inline

is the range inner_range within [min, max]?

References OpenMS::Math::contains(), RangeBase::max_, and RangeBase::min_.

◆ extend() [1/2]

void extend ( const double  value)
inline

extend the range such that it includes the given value

◆ extend() [2/2]

void extend ( const RangeBase other)
inline

ensure the range includes the range of other

References RangeBase::max_, and RangeBase::min_.

◆ extendLeftRight()

void extendLeftRight ( const double  by)
inline

Extend the range by by units to left and right Using negative values will shrink the range. It may become empty. Calling this on an empty range will not have any effect.

◆ getMax()

double getMax ( ) const
inline

only useful if isEmpty() returns false

Referenced by DimMapper< N_DIM >::mapRange().

◆ getMin()

double getMin ( ) const
inline

only useful if isEmpty() returns false

Referenced by DimMapper< N_DIM >::mapRange().

◆ getNonEmptyRange()

std::pair<double, double> getNonEmptyRange ( ) const
inline

Return the current range, or (if empty) a full range (-1e308, 1e308).

Returns
A range where always: min <= max

◆ getSpan()

double getSpan ( ) const
inline

Get the 'width' of the range If range is empty(), 'nan' will be returned

Referenced by RangeBase::pushInto().

◆ isEmpty()

bool isEmpty ( ) const
inline

is the range empty (i.e. min > max)?

Referenced by RangeBase::clampTo(), DimMapper< N_DIM >::mapRange(), and RangeBase::pushInto().

◆ minSpanIfSingular()

void minSpanIfSingular ( const double  min_span)
inline

If the current range is a single point, e.g. min==max, then extend the range by min_span / 2 on either side.

Calling span() afterwards, returns min_span.

◆ operator RangeIntensity()

operator RangeIntensity ( ) const

conversion operator to allow accepting a RangeBase (instead of RangeIntensity) for the implicitly defined special members, e.g. assignment operator (RangeIntensity& operator=(const RangeIntensity&))

◆ operator RangeMobility()

operator RangeMobility ( ) const

conversion operator to allow accepting a RangeBase (instead of RangeMobility) for the implicitly defined special members, e.g. assignment operator (RangeMobility& operator=(const RangeMobility&))

◆ operator RangeMZ()

operator RangeMZ ( ) const

conversion operator to allow accepting a RangeBase (instead of RangeMZ) for the implicitly defined special members, e.g. assignment operator (RangeMZ& operator=(const RangeMZ&))

◆ operator RangeRT()

operator RangeRT ( ) const

conversion operator to allow accepting a RangeBase (instead of RangeRT) for the implicitly defined special members, e.g. assignment operator (RangeRT& operator=(const RangeRT&))

◆ operator=() [1/2]

RangeBase& operator= ( const RangeBase rhs)
default

Assignment operator.

◆ operator=() [2/2]

RangeBase& operator= ( RangeBase &&  rhs)
defaultnoexcept

Move assignment (seems useless, but is required for completeness in derived classes' move c'tor)

◆ operator==()

bool operator== ( const RangeBase rhs) const
inline

References RangeBase::max_, and RangeBase::min_.

◆ pushInto()

void pushInto ( const RangeBase sandbox)
inline

Move range of *this to min/max of sandbox, without changing the span, if possible. This does tighten the range unless sandbox's ranges are smaller than *this. Empty ranges are not modified.

Parameters
sandboxRange to translate/move the current range into
Exceptions
Exception::InvalidRangeif sandbox is empty

References RangeBase::contains(), RangeBase::getSpan(), RangeBase::isEmpty(), RangeBase::max_, and RangeBase::min_.

◆ scaleBy()

void scaleBy ( const double  factor)
inline

Scale the range of the dimension by a factor. A factor > 1 increases the range; factor < 1 decreases it.

Let d = max - min; then min = min - d*(factor-1)/2, i.e. scale(1.5) extends the range by 25% on each side.

Scaling an empty range will not have any effect.

Parameters
factorThe multiplier to increase the range by

◆ setMax()

void setMax ( const double  max)
inline

sets the maximum (and the minimum, if uninitialized)

◆ setMin()

void setMin ( const double  min)
inline

sets the minimum (and the maximum, if uninitialized)

◆ shift()

void shift ( const double  distance)
inline

Move the range by distance (negative values shift left) Shifting an empty range will not have any effect.

Member Data Documentation

◆ max_

double max_ = std::numeric_limits<double>::lowest()
protected

◆ min_

double min_ = std::numeric_limits<double>::max()
protected