Loading...
Searching...
No Matches
SBDTypePhysicalInterval< Quantity > Class Template Reference

This template class is used to describe physical intervals. More...

Useful functions

static const SBDTypePhysicalInterval< Quantity > zero
 The zero physical interval.
 
static const SBDTypePhysicalInterval< Quantity > empty
 The empty physical interval (+infinite, -infinite)
 
static const SBDTypePhysicalInterval< Quantity > infinite
 The infinite physical interval (-infinite, +infinite)
 
Quantity i [2]
 The components of the interval.
 
bool isEmpty (const SBDTypePhysicalInterval< Quantity > u) const
 Determines whether the intersection between this physical interval and the physical interval u is empty,.
 
bool isEmpty (Quantity l, Quantity r) const
 Determines whether the intersection between this physical interval and the physical interval [l, r] is empty,.
 
Quantity getAbsLower () const
 Returns the lower bound of the absolute value of this physical interval.
 
Quantity getAbsUpper () const
 Returns the upper bound of the absolute value of this physical interval.
 
bool contains (Quantity v) const
 Returns true when this physical interval contains v.
 
bool contains (const SBDTypePhysicalInterval< Quantity > &j) const
 Returns true when this physical interval contains physical interval j.
 
void bound (Quantity v)
 Enlarges this physical interval to contain v.
 
void bound (const SBDTypePhysicalInterval< Quantity > &j)
 Enlarges this physical interval to contain the physical interval j.
 
void expand (Quantity r)
 Expands this physical interval by offset r.
 
void shrink (Quantity r)
 Shrinks this physical interval by offset r.
 
Quantity center () const
 Returns the center 0.5*(i[0]+i[1]) of the physical interval.
 
Quantity diameter () const
 Returns the diameter i[1]-i[0] of the physical interval.
 
void setZero ()
 Sets the physical interval to [0,0].
 
void print () const
 Prints the physical interval.
 
template<typename QuantityLower , typename QuantityUpper >
void updateBounds (SBDTypePhysicalInterval< QuantityLower > &lower, SBDTypePhysicalInterval< QuantityUpper > &upper) const
 Updates the lower and upper bounds with this physical interval.
 

Constructors

 SBDTypePhysicalInterval ()
 The default constructor initializes all components to zero.
 
 SBDTypePhysicalInterval (Quantity x)
 Constructs a physical interval [x, x].
 
 SBDTypePhysicalInterval (Quantity x, Quantity y)
 Constructs a physical interval [x, y].
 
 SBDTypePhysicalInterval (Quantity val[2])
 Constructs a physical interval [val[0], val[1]].
 
 SBDTypePhysicalInterval (const SBDTypePhysicalInterval< Quantity > &u)
 Copy constructor.
 

Serialization

void serialize (SBCSerializer *serializer, const SBVersionNumber &sdkVersionNumber=SB_SDK_VERSION_NUMBER) const
 Serializes the physical interval using the provided serializer.
 
void unserialize (SBCSerializer *serializer, const SBVersionNumber &sdkVersionNumber=SB_SDK_VERSION_NUMBER)
 Unserializes the physical interval using the provided serializer.
 

Accessors

SBDTypePhysicalInterval< SBQuantity::dimensionlessgetValue () const
 Returns a dimensionless physical interval whose bounds are equal to those of this physical interval.
 
void setValue (const SBDTypePhysicalInterval< SBQuantity::dimensionless > &u)
 Sets the bounds of this physical interval equal to those of the dimensionless physical interval u.
 

Operators

SBDTypePhysicalInterval< Quantity > operator+ (const SBDTypePhysicalInterval< Quantity > &u) const
 Returns the sum of this physical interval and the physical interval u.
 
SBDTypePhysicalInterval< Quantity > operator- (const SBDTypePhysicalInterval< Quantity > &u) const
 Returns the difference between this physical interval and the physical interval u.
 
SBDTypePhysicalInterval< Quantity > operator* (double d) const
 Returns the result of the product of this physical interval with the double d.
 
template<typename QuantityB >
SBDTypePhysicalInterval< SBQuantityType< typename SBDQuantityUnitMultiplication< typename Quantity::UnitType, typename QuantityB::UnitType >::UnitType > > operator* (const QuantityB &d) const
 Returns the product of this physical interval with the quantity d.
 
template<typename QuantityB >
SBDTypePhysicalInterval< SBQuantityType< typename SBDQuantityUnitMultiplication< typename Quantity::UnitType, typename QuantityB::UnitType >::UnitType > > operator* (const SBDTypePhysicalInterval< QuantityB > &in) const
 Returns the product of this physical interval with the physical interval in.
 
template<typename QuantityB >
SBDTypePhysicalInterval< Quantity > & operator*= (QuantityB d) const
 Multiplies this physical interval with the quantity d.
 
template<typename QuantityB >
SBDTypePhysicalInterval< Quantity > & operator*= (SBDTypePhysicalInterval< QuantityB > in) const
 Multiplies this physical interval with the physical interval in.
 
SBDTypePhysicalInterval< Quantity > operator/ (double d) const
 Returns the result of the division of this physical interval by the double d.
 
template<typename QuantityB >
SBDTypePhysicalInterval< SBQuantityType< typename SBDQuantityUnitDivision< typename Quantity::UnitType, typename QuantityB::UnitType >::UnitType > > operator/ (QuantityB d) const
 Returns the result of the division of this physical interval by the quantity d.
 
template<typename QuantityB >
SBDTypePhysicalInterval< SBQuantityType< typename SBDQuantityUnitDivision< typename Quantity::UnitType, typename QuantityB::UnitType >::UnitType > > operator/ (const SBDTypePhysicalInterval< QuantityB > &in) const
 Returns the result of the division of this physical interval by the physical interval in.
 
template<typename QuantityB >
SBDTypePhysicalInterval< Quantity > & operator/= (QuantityB d) const
 Divides this physical interval by the quantity d.
 
template<typename QuantityB >
SBDTypePhysicalInterval< Quantity > & operator/= (const SBDTypePhysicalInterval< QuantityB > &in) const
 Divides this physical interval by the physical interval in.
 
SBDTypePhysicalInterval< Quantity > operator- () const
 Returns the opposite of this physical interval.
 
SBDTypePhysicalInterval< Quantity > & operator+= (const SBDTypePhysicalInterval< Quantity > &u)
 Adds the physical interval u to this physical interval.
 
SBDTypePhysicalInterval< Quantity > & operator-= (const SBDTypePhysicalInterval< Quantity > &u)
 Subtracts the physical interval u from this physical interval.
 
bool operator^ (const SBDTypePhysicalInterval< Quantity > &u)
 Intersects this physical interval with the physical interval u.
 
template<typename QuantityB >
 operator SBDTypePhysicalInterval< QuantityB > () const
 Converts this physical interval to a physical interval with units QuantityB.
 
SBDTypePhysicalInterval< Quantity > & operator= (const SBDTypePhysicalInterval< Quantity > &u)
 Copy assignment.
 
template<typename QuantityB >
bool operator== (const SBDTypePhysicalInterval< QuantityB > &u) const
 Returns true when this physical interval is equal to physical interval u.
 
template<typename QuantityB >
bool operator!= (const SBDTypePhysicalInterval< QuantityB > &u) const
 Returns true when this physical interval is different from physical interval u.
 
Quantity & operator[] (int index)
 Returns a reference to component index of this physical interval.
 
const Quantity & operator[] (int index) const
 Returns a reference to component index of this physical interval (const version)
 

Detailed Description

template<typename Quantity>
class SBDTypePhysicalInterval< Quantity >
Template Parameters
QuantityThe quantity type of the interval

This template class is used to describe physical intervals.

Physical intervals are physical quantities, and thus use SAMSON's unit system. In a physical interval (e.g. an energy interval), both bounds have the same unit, so that physical intervals are defined by only one unit, and the SBDTypePhysicalInterval template class is parameterized by only one type: Quantity.

This class may be used to perform interval arithmetics (IA), i.e. arithmetics with intervals instead of numbers, with physical quantities.

Most of the time, developers of SAMSON Extensions do not have to use this template, but may directly use some predefined types that correspond to specific instantiations of this template class, e.g. SBInterval (dimensionless interval), SBEnergyInterval (energy interval), SBPositionInterval (position interval), etc.

Interval arithmetics may be particularly useful to compute bounds on physical quantities:

// bound on the first position
);
// bound on the second position
);
// bound on the squared distance
SBSquareLengthInterval l2 = ((x2 - x1) | (x2 - x1));
This template class defines physical quantity types.
Definition: SBDQuantityType.hpp:43
This template class represents three-dimensional physical interval vectors.
Definition: SBDTypePhysicalIAVector3.hpp:65
This template class is used to describe physical intervals.
Definition: SBDTypePhysicalInterval.hpp:61

Short name: SBPhysicalInterval

See also
SAMSON's unit system
The SBDType library
SBDTypePhysicalIAVector3

Member Function Documentation

◆ expand()

template<typename Quantity >
void SBDTypePhysicalInterval< Quantity >::expand ( Quantity  r)
inline
Parameters
rThe offset size

This function expands this physical interval by offset r: [a, b] becomes [a-r, b+r].

◆ operator*()

template<typename Quantity >
template<typename QuantityB >
SBDTypePhysicalInterval< SBQuantityType< typename SBDQuantityUnitMultiplication< typename Quantity::UnitType, typename QuantityB::UnitType >::UnitType > > SBDTypePhysicalInterval< Quantity >::operator* ( const QuantityB &  d) const
inline
Parameters
dA quantity with unit QuantityB

This function returns the product of this physical interval by the quantity d. Note that the unit of the returned physical interval is the product of the physical interval's unit and the quantity's unit.

◆ operator*=() [1/2]

template<typename Quantity >
template<typename QuantityB >
SBDTypePhysicalInterval< Quantity > & SBDTypePhysicalInterval< Quantity >::operator*= ( QuantityB  d) const
inline
Parameters
dA dimensionless physical quantity or a numeric type (i.e. int, float, double, etc)

This function multiplies this physical interval with the quantity d.

◆ operator*=() [2/2]

template<typename Quantity >
template<typename QuantityB >
SBDTypePhysicalInterval< Quantity > & SBDTypePhysicalInterval< Quantity >::operator*= ( SBDTypePhysicalInterval< QuantityB >  in) const
inline
Parameters
inA dimensionless physical interval

◆ operator/=() [1/2]

template<typename Quantity >
template<typename QuantityB >
SBDTypePhysicalInterval< Quantity > & SBDTypePhysicalInterval< Quantity >::operator/= ( const SBDTypePhysicalInterval< QuantityB > &  in) const
inline
Parameters
inA dimensionless physical interval

◆ operator/=() [2/2]

template<typename Quantity >
template<typename QuantityB >
SBDTypePhysicalInterval< Quantity > & SBDTypePhysicalInterval< Quantity >::operator/= ( QuantityB  d) const
inline
Parameters
dA dimensionless physical quantity or a numeric type (i.e. int, float, double, etc)

◆ operator^()

template<typename Quantity >
bool SBDTypePhysicalInterval< Quantity >::operator^ ( const SBDTypePhysicalInterval< Quantity > &  u)
inline
Parameters
uA physical interval
Returns
True when the intersection with u is empty

This operator returns true when the intersection between this physical interval and the physical interval u is empty. When it is not, this interval is replaced by the intersection.

◆ shrink()

template<typename Quantity >
void SBDTypePhysicalInterval< Quantity >::shrink ( Quantity  r)
inline
Parameters
rThe offset size

This function shrinks this physical interval by offset r: [a, b] becomes [a+r, b-r]. When the offset r is larger than the half-size of the physical interval, the interval becomes [m, m], where m is the center of the interval.

◆ updateBounds()

template<typename Quantity >
template<typename QuantityLower , typename QuantityUpper >
void SBDTypePhysicalInterval< Quantity >::updateBounds ( SBDTypePhysicalInterval< QuantityLower > &  lower,
SBDTypePhysicalInterval< QuantityUpper > &  upper 
) const
inline
Parameters
lowerThe lower bound
upperThe upper bound

If necessary, this function updates the lower and upper bounds to ensure that they contain this physical interval.