OpenMS  2.7.0
Public Types | Public Member Functions | Protected Attributes | List of all members
AveragePosition< D > Class Template Reference

Maintain an average position by summing up positions with weights. More...

#include <OpenMS/MATH/STATISTICS/AveragePosition.h>

Collaboration diagram for AveragePosition< D >:
[legend]

Public Types

enum  { DIMENSION = D }
 Dimensionality. More...
 
typedef DPosition< DIMENSIONPositionType
 Position type (a D-dimensional position) More...
 
typedef PositionType::CoordinateType CoordinateType
 Weight type (for weighted average - a scalar type) More...
 

Public Member Functions

 AveragePosition ()
 Default constructor. More...
 
 AveragePosition (AveragePosition const &rhs)
 Copy constructor. More...
 
PositionType const & getPosition () const
 Returns the current average position. More...
 
CoordinateType const & getWeight () const
 Returns the total weight. More...
 
void clear ()
 Reset everything. (Note that update() will cause a division by zero after that.) More...
 
void add (PositionType position, CoordinateType const weight=1)
 Add a position. More...
 

Protected Attributes

PositionType position_
 
PositionType position_weighted_sum_
 
CoordinateType weight_sum_
 

Detailed Description

template<UInt D>
class OpenMS::Math::AveragePosition< D >

Maintain an average position by summing up positions with weights.

Improvement:
A lot of convenience methods could be added. For example, we could overload operator + and -, consequently +=, -=, even < and ==, inherit the whole thing from an extended DPosition with similar methods, initialize from iterator ranges, ... but there are not concrete use cases at the moment. Please contact the maintainer if you need something for your application field. (Clemens)

Member Typedef Documentation

◆ CoordinateType

Weight type (for weighted average - a scalar type)

◆ PositionType

Position type (a D-dimensional position)

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Dimensionality.

Enumerator
DIMENSION 

Constructor & Destructor Documentation

◆ AveragePosition() [1/2]

AveragePosition ( )
inline

Default constructor.

◆ AveragePosition() [2/2]

AveragePosition ( AveragePosition< D > const &  rhs)
inline

Copy constructor.

Member Function Documentation

◆ add()

void add ( PositionType  position,
CoordinateType const  weight = 1 
)
inline

◆ clear()

void clear ( )
inline

Reset everything. (Note that update() will cause a division by zero after that.)

References DPosition< D, TCoordinateType >::clear(), AveragePosition< D >::position_, AveragePosition< D >::position_weighted_sum_, and AveragePosition< D >::weight_sum_.

◆ getPosition()

PositionType const& getPosition ( ) const
inline

Returns the current average position.

References AveragePosition< D >::position_.

◆ getWeight()

CoordinateType const& getWeight ( ) const
inline

Returns the total weight.

References AveragePosition< D >::weight_sum_.

Member Data Documentation

◆ position_

PositionType position_
protected

◆ position_weighted_sum_

PositionType position_weighted_sum_
protected

◆ weight_sum_

CoordinateType weight_sum_
protected