OpenMS
DRange< D > Class Template Reference

A D-dimensional half-open interval. More...

#include <OpenMS/DATASTRUCTURES/DRange.h>

Inheritance diagram for DRange< D >:
[legend]
Collaboration diagram for DRange< D >:
[legend]

Public Member Functions

Constructors and Destructor
 DRange ()
 Default constructor. More...
 
 DRange (const PositionType &lower, const PositionType &upper)
 Constructor that takes two Points and constructs a range. More...
 
 DRange (const DRange &range)
 Copy constructor. More...
 
 DRange (DRange &&) noexcept=default
 Move constructor. More...
 
 DRange (const Base &range)
 Copy constructor for the base class. More...
 
 DRange (CoordinateType minx, CoordinateType miny, CoordinateType maxx, CoordinateType maxy)
 Convenient constructor for DRange<2> More...
 
DRangeoperator= (const DRange &rhs)
 Assignment operator. More...
 
DRangeoperator= (const Base &rhs)
 Assignment operator for the base class. More...
 
 ~DRange ()
 Destructor. More...
 
Predicates
bool operator== (const DRange &rhs) const
 Equality operator. More...
 
bool operator== (const Base &rhs) const
 Equality operator. More...
 
bool encloses (const PositionType &position) const
 Checks whether this range contains a certain point. More...
 
bool encloses (CoordinateType x, CoordinateType y) const
 2D-version of encloses for convenience only More...
 
DRange united (const DRange< D > &other_range) const
 Returns the smallest range containing this range and other_range. More...
 
DRangeIntersection intersects (const DRange &range) const
 Checks how this range intersects with another range. More...
 
bool isIntersected (const DRange &range) const
 Checks whether this range intersects with another range. More...
 
DRange< D > & extend (double factor)
 Extends the range in all dimensions by a certain multiplier. More...
 
DRange< D > & extend (typename Base::PositionType addition)
 Extends the range in all dimensions by a certain amount. More...
 
DRange< D > & ensureMinSpan (typename Base::PositionType min_span)
 
DRange< D > & swapDimensions ()
 swaps dimensions for 2D data (i.e. x and y coordinates) More...
 
void pullIn (DPosition< D > &point) const
 Make sure point is inside the current area. More...
 
- Public Member Functions inherited from DIntervalBase< D >
 DIntervalBase ()
 Default constructor. More...
 
 DIntervalBase (const DIntervalBase &rhs)
 Copy constructor. More...
 
 DIntervalBase (DIntervalBase &&) noexcept=default
 Move constructor. More...
 
DIntervalBaseoperator= (const DIntervalBase &rhs)
 Assignment operator. More...
 
 ~DIntervalBase ()
 Destructor. More...
 
 DIntervalBase (PositionType const &minimum, PositionType const &maximum)
 This constructor sets min_ and max_ directly. More...
 
PositionType const & minPosition () const
 Accessor to minimum position. More...
 
PositionType const & maxPosition () const
 Accessor to maximum position. More...
 
void setMin (PositionType const &position)
 Mutator for minimum position. More...
 
void setMax (PositionType const &position)
 Mutator for maximum position. More...
 
void setMinMax (PositionType const &min, PositionType const &max)
 Mutator for minimum and maximum position. More...
 
template<UInt D2>
void assign (const DIntervalBase< D2 > rhs)
 Assignment from a DIntervalBase of different dimensions. More...
 
bool operator== (const DIntervalBase &rhs) const
 Equality operator. More...
 
bool operator!= (const DIntervalBase &rhs) const
 Equality operator. More...
 
DIntervalBase operator+ (const PositionType &point) const
 
DIntervalBaseoperator+= (const PositionType &point)
 
DIntervalBase operator- (const PositionType &point) const
 
DIntervalBaseoperator-= (const PositionType &point)
 
void clear ()
 Make the interval empty. More...
 
bool isEmpty () const
 
bool isEmpty (UInt dim) const
 Is the dimension dim empty? If min==max, the interval is NOT empty! More...
 
void setDimMinMax (UInt dim, const DIntervalBase< 1 > &min_max)
 only set interval for a single dimension More...
 
PositionType center () const
 Returns the center of the interval. More...
 
PositionType diagonal () const
 Returns the diagonal of the area, i.e. max_ - min_. More...
 
CoordinateType minX () const
 Accessor for min_ coordinate minimum. More...
 
CoordinateType minY () const
 Accessor for max_ coordinate minimum. More...
 
CoordinateType maxX () const
 Accessor for min_ coordinate maximum. More...
 
CoordinateType maxY () const
 Accessor for max_ coordinate maximum. More...
 
void setMinX (CoordinateType const c)
 Mutator for min_ coordinate of the smaller point. More...
 
void setMinY (CoordinateType const c)
 Mutator for max_ coordinate of the smaller point. More...
 
void setMaxX (CoordinateType const c)
 Mutator for min_ coordinate of the larger point. More...
 
void setMaxY (CoordinateType const c)
 Mutator for max_ coordinate of the larger point. More...
 
CoordinateType width () const
 Returns the width of the area i.e. the difference of dimension zero (X). More...
 
CoordinateType height () const
 Returns the height of the area i.e. the difference of dimension one (Y). More...
 

Type definitions

enum  { DIMENSION = D }
 Dimensions. More...
 
enum  DRangeIntersection { Disjoint , Intersects , Inside }
 Types that describe the kind of intersection between two ranges. More...
 
typedef Internal::DIntervalBase< D > Base
 Base class type. More...
 
typedef Base::PositionType PositionType
 Position type. More...
 
typedef Base::CoordinateType CoordinateType
 Coordinate type of the positions. More...
 
PositionType min_
 lower left point More...
 
PositionType max_
 upper right point More...
 

Additional Inherited Members

- Public Types inherited from DIntervalBase< D >
enum  { DIMENSION = D }
 Dimensions. More...
 
typedef DPosition< D > PositionType
 Position type. More...
 
typedef PositionType::CoordinateType CoordinateType
 Coordinate type of the positions. More...
 
- Static Public Attributes inherited from DIntervalBase< D >
static DIntervalBase const empty = DIntervalBase<D>(std::make_pair(DIntervalBase<D>::PositionType::maxPositive(), DIntervalBase<D>::PositionType::minNegative()))
 empty instance More...
 
static DIntervalBase const zero = DIntervalBase<D>(DIntervalBase<D>::PositionType::zero(), DIntervalBase<D>::PositionType::zero())
 instance with all positions zero More...
 
- Protected Member Functions inherited from DIntervalBase< D >
void normalize_ ()
 normalization to keep all dimensions in the right geometrical order (min_[X] < max_[X]) More...
 
 DIntervalBase (const std::pair< PositionType, PositionType > &pair)
 Protected constructor for the construction of static instances. More...
 
- Protected Attributes inherited from DIntervalBase< D >
PositionType min_
 lower left point More...
 
PositionType max_
 upper right point More...
 

Detailed Description

template<UInt D>
class OpenMS::DRange< D >

A D-dimensional half-open interval.

This class describes a range in D-dimensional space delimited by two points (i.e. a D-dimensional hyper-rectangle). The two points define the lower left and the upper right corner in 2D and analogous points in higher dimensions.

A range is a pair of positions in D-space represented by DPosition. The two limiting points are accessed as minPosition() and maxPosition().

A range denotes a semi-open interval. A lower coordinate of each dimension is part of the range, the higher coordinate is not.

Member Typedef Documentation

◆ Base

Base class type.

◆ CoordinateType

Coordinate type of the positions.

◆ PositionType

Position type.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Dimensions.

Enumerator
DIMENSION 

◆ DRangeIntersection

Types that describe the kind of intersection between two ranges.

Enumerator
Disjoint 

No intersection.

Intersects 

Intersection.

Inside 

One contains the other.

Constructor & Destructor Documentation

◆ DRange() [1/6]

DRange ( )
inline

Default constructor.

Creates a range with all coordinates zero.

◆ DRange() [2/6]

DRange ( const PositionType lower,
const PositionType upper 
)
inline

Constructor that takes two Points and constructs a range.

◆ DRange() [3/6]

DRange ( const DRange< D > &  range)
inline

Copy constructor.

◆ DRange() [4/6]

DRange ( DRange< D > &&  )
defaultnoexcept

Move constructor.

◆ DRange() [5/6]

DRange ( const Base range)
inline

Copy constructor for the base class.

◆ DRange() [6/6]

DRange ( CoordinateType  minx,
CoordinateType  miny,
CoordinateType  maxx,
CoordinateType  maxy 
)
inline

Convenient constructor for DRange<2>

References DRange< D >::max_, DRange< D >::min_, and DIntervalBase< D >::normalize_().

◆ ~DRange()

~DRange ( )
inline

Destructor.

Member Function Documentation

◆ encloses() [1/2]

bool encloses ( const PositionType position) const
inline

Checks whether this range contains a certain point.

Parameters
positionThe point's position.
Returns
true if point lies inside this area.

References DRange< D >::max_, and DRange< D >::min_.

Referenced by DRange< D >::intersects(), DRange< D >::isIntersected(), and DTA2DFile::load().

◆ encloses() [2/2]

bool encloses ( CoordinateType  x,
CoordinateType  y 
) const
inline

2D-version of encloses for convenience only

References DRange< D >::max_, and DRange< D >::min_.

◆ ensureMinSpan()

DRange<D>& ensureMinSpan ( typename Base::PositionType  min_span)
inline

◆ extend() [1/2]

DRange<D>& extend ( double  factor)
inline

Extends the range in all dimensions by a certain multiplier.

Extends the range, while maintaining the original center position.

Examples (for D=1): factor = 1.01 extends the range by 1% in total, i.e. 0.5% left and right. factor = 2.00 doubles the total range, e.g. from [0,100] to [-50,150]

Parameters
factorMultiplier (allowed is [0, inf)).
Returns
A reference to self

References DRange< D >::max_, and DRange< D >::min_.

Referenced by DRange< D >::ensureMinSpan().

◆ extend() [2/2]

DRange<D>& extend ( typename Base::PositionType  addition)
inline

Extends the range in all dimensions by a certain amount.

Extends the range, while maintaining the original center position. If a negative addition is given, the range shrinks and may result in min==max (but never min>max).

Examples (for D=1): addition = 0.5 extends the range by 1 in total, i.e. 0.5 left and right.

Parameters
additionAdditive for each dimension (can be negative). Resulting invalid min/max are not fixed automatically!
Returns
A reference to self

References DRange< D >::max_, and DRange< D >::min_.

◆ intersects()

DRangeIntersection intersects ( const DRange< D > &  range) const
inline

Checks how this range intersects with another range.

Parameters
rangeThe max_ range.

References DRange< D >::Disjoint, DRange< D >::encloses(), DRange< D >::Inside, DRange< D >::Intersects, DRange< D >::max_, and DRange< D >::min_.

◆ isIntersected()

bool isIntersected ( const DRange< D > &  range) const
inline

Checks whether this range intersects with another range.

Parameters
rangeThe max_ range.
Returns
True if the areas intersect (i.e. they intersect or one contains the other).

References DRange< D >::encloses(), DRange< D >::max_, and DRange< D >::min_.

◆ operator=() [1/2]

DRange& operator= ( const Base rhs)
inline

Assignment operator for the base class.

References DIntervalBase< D >::operator=().

◆ operator=() [2/2]

DRange& operator= ( const DRange< D > &  rhs)
inline

Assignment operator.

References DIntervalBase< D >::operator=().

◆ operator==() [1/2]

bool operator== ( const Base rhs) const
inline

Equality operator.

References DIntervalBase< D >::operator==().

◆ operator==() [2/2]

bool operator== ( const DRange< D > &  rhs) const
inline

Equality operator.

References DIntervalBase< D >::operator==().

◆ pullIn()

void pullIn ( DPosition< D > &  point) const
inline

Make sure point is inside the current area.

Parameters
pointA point potentially outside the current range, which will be pulled into the current range.

References DRange< D >::max_, and DRange< D >::min_.

◆ swapDimensions()

DRange<D>& swapDimensions ( )
inline

swaps dimensions for 2D data (i.e. x and y coordinates)

References DRange< D >::max_, and DRange< D >::min_.

◆ united()

DRange united ( const DRange< D > &  other_range) const
inline

Returns the smallest range containing this range and other_range.

References DRange< D >::max_, DIntervalBase< D >::maxPosition(), DRange< D >::min_, DIntervalBase< D >::minPosition(), and DIntervalBase< D >::setMinMax().

Member Data Documentation

◆ max_

◆ min_