opensurgsim
Public Member Functions | Static Public Member Functions | Friends | List of all members
SurgSim::Math::Interval< T > Class Template Reference

Interval defines the concept of a mathematical interval and provides operations on it including arithmetic operations, construction, and IO. More...

#include <IntervalArithmetic.h>

Public Member Functions

 Interval ()
 Constructor.
 
 Interval (const T &min, const T &max)
 Constructor. More...
 
 Interval (const Interval< T > &i)
 Copy constructor. More...
 
 Interval (Interval< T > &&i)
 Move constructor. More...
 
Interval< T > & operator= (const Interval< T > &i)
 Assignment operator. More...
 
Interval< T > & operator= (Interval< T > &&i)
 Move assignment operator. More...
 
bool overlapsWith (const Interval< T > &i) const
 
bool contains (const T &val) const
 
bool containsZero () const
 
bool isApprox (const Interval< T > &i, const T &epsilon) const
 
bool operator== (const Interval< T > &i) const
 
bool operator!= (const Interval< T > &i) const
 
Interval< T > & addThickness (const T &thickness)
 Widens the current interval by thickness on both sides. More...
 
Interval< T > & extendToInclude (const T &x)
 Widens the current interval on one end to include x. More...
 
Interval< T > & extendToInclude (const Interval< T > &i)
 Widens the current interval on both ends to include i. More...
 
Interval< T > inverse () const
 
Interval< T > operator/ (const Interval< T > &i) const
 
Interval< T > & operator/= (const Interval< T > &i)
 
Interval< T > square () const
 
getMin () const
 
getMax () const
 
Interval< T > lowerHalf () const
 
Interval< T > upperHalf () const
 
Interval< T > operator+ (const Interval< T > &i) const
 
Interval< T > operator+ (const T &v) const
 
Interval< T > & operator+= (const Interval< T > &i)
 
Interval< T > & operator+= (const T &v)
 
Interval< T > operator- () const
 
Interval< T > operator- (const Interval< T > &i) const
 
Interval< T > operator- (const T &v) const
 
Interval< T > & operator-= (const Interval< T > &i)
 
Interval< T > & operator-= (const T &v)
 
Interval< T > operator* (const Interval< T > &i) const
 
Interval< T > operator* (const T &v) const
 
Interval< T > & operator*= (const Interval< T > &i)
 
Interval< T > & operator*= (const T &v)
 

Static Public Member Functions

static Interval< T > minToMax (const T &a1, const T &a2)
 Generate an interval from min to max based on the inputs. More...
 
static Interval< T > minToMax (const T &a1, const T &a2, const T &a3)
 Generate an interval from min to max based on the inputs. More...
 
static Interval< T > minToMax (const T &a1, const T &a2, const T &a3, const T &a4)
 Generate an interval from min to max based on the inputs. More...
 

Friends

template<class P >
void IntervalArithmetic_add (const Interval< P > &a, const Interval< P > &b, Interval< P > *res)
 Calculate the sum of two intervals. More...
 
template<class P >
void IntervalArithmetic_addadd (const Interval< P > &a, const Interval< P > &b, Interval< P > *res)
 Calculate the sum of three intervals res + a + b. More...
 
template<class P >
void IntervalArithmetic_sub (const Interval< P > &a, const Interval< P > &b, Interval< P > *res)
 Calculate the difference of two intervals. More...
 
template<class P >
void IntervalArithmetic_addsub (const Interval< P > &a, const Interval< P > &b, Interval< P > *res)
 Add the difference of two intervals to an existing value. More...
 
template<class P >
void IntervalArithmetic_mul (const Interval< P > &a, const Interval< P > &b, Interval< P > *res)
 Calculate the product of two intervals. More...
 
template<class P >
void IntervalArithmetic_addmul (const Interval< P > &a, const Interval< P > &b, Interval< P > *res)
 Add the product of two intervals to an existing value. More...
 
template<class P >
void IntervalArithmetic_submul (const Interval< P > &a, const Interval< P > &b, Interval< P > *res)
 Subtract the product of two intervals from an existing value. More...
 

Detailed Description

template<class T>
class SurgSim::Math::Interval< T >

Interval defines the concept of a mathematical interval and provides operations on it including arithmetic operations, construction, and IO.

Template Parameters
Tunderlying data type over which the interval is defined.
See also
IntervalND<T, N> and IntervalND<T, 3>

Constructor & Destructor Documentation

§ Interval() [1/3]

template<class T >
SurgSim::Math::Interval< T >::Interval ( const T &  min,
const T &  max 
)

Constructor.

Parameters
minLower bound of the constructed interval
maxUpper bound of the constructed interval
Exceptions
ifmax is less than min

§ Interval() [2/3]

template<class T >
SurgSim::Math::Interval< T >::Interval ( const Interval< T > &  i)

Copy constructor.

Parameters
iInterval to be copied

§ Interval() [3/3]

template<class T >
SurgSim::Math::Interval< T >::Interval ( Interval< T > &&  i)

Move constructor.

Parameters
iInterval to be copied

Member Function Documentation

§ addThickness()

template<class T >
Interval< T > & SurgSim::Math::Interval< T >::addThickness ( const T &  thickness)

Widens the current interval by thickness on both sides.

Parameters
thicknessthe amount to widen the current interval on both sides
Returns
the current interval after modification

§ contains()

template<class T >
bool SurgSim::Math::Interval< T >::contains ( const T &  val) const
Parameters
valthe value to test for inclusion in the interval
Returns
true if the current interval contains val

§ containsZero()

template<class T >
bool SurgSim::Math::Interval< T >::containsZero ( ) const
Returns
true if the current interval contains 0

§ extendToInclude() [1/2]

template<class T >
Interval< T > & SurgSim::Math::Interval< T >::extendToInclude ( const T &  x)

Widens the current interval on one end to include x.

Parameters
xthe value to be included in the interval
Returns
the current interval extended to include x

§ extendToInclude() [2/2]

template<class T >
Interval< T > & SurgSim::Math::Interval< T >::extendToInclude ( const Interval< T > &  i)

Widens the current interval on both ends to include i.

Parameters
ithe interval to be wholly contained in the current interval
Returns
the current interval extended to include the entirety of i

§ getMax()

template<class T >
T SurgSim::Math::Interval< T >::getMax ( ) const
Returns
the upper limit of the interval

§ getMin()

template<class T >
T SurgSim::Math::Interval< T >::getMin ( ) const
Returns
the lower limit of the interval

§ inverse()

template<class T >
Interval< T > SurgSim::Math::Interval< T >::inverse ( ) const
Returns
the inverse of the current interval
Exceptions
ifthe interval includes 0

§ isApprox()

template<class T >
bool SurgSim::Math::Interval< T >::isApprox ( const Interval< T > &  i,
const T &  epsilon 
) const
Parameters
ithe interval to be tested
epsilonthe nearness parameter
Returns
true if the current interval is within epsilon of the input interval

§ lowerHalf()

template<class T >
Interval< T > SurgSim::Math::Interval< T >::lowerHalf ( ) const
Returns
the interval from the lower limit to the midpoint

§ minToMax() [1/3]

template<class T >
Interval< T > SurgSim::Math::Interval< T >::minToMax ( const T &  a1,
const T &  a2 
)
static

Generate an interval from min to max based on the inputs.

Parameters
a1first input value
a2second input value
Returns
an interval spanning the minimum input to the maximum input.

§ minToMax() [2/3]

template<class T >
Interval< T > SurgSim::Math::Interval< T >::minToMax ( const T &  a1,
const T &  a2,
const T &  a3 
)
static

Generate an interval from min to max based on the inputs.

Parameters
a1first input value
a2second input value
a3third input value
Returns
an interval spanning the minimum input to the maximum input.

§ minToMax() [3/3]

template<class T >
Interval< T > SurgSim::Math::Interval< T >::minToMax ( const T &  a1,
const T &  a2,
const T &  a3,
const T &  a4 
)
static

Generate an interval from min to max based on the inputs.

Parameters
a1first input value
a2second input value
a3third input value
a4fourth input value
Returns
an interval spanning the minimum input to the maximum input.

§ operator!=()

template<class T >
bool SurgSim::Math::Interval< T >::operator!= ( const Interval< T > &  i) const
Parameters
ithe interval to be tested
Returns
true if the current interval is not identical to the input interval

§ operator+()

template<class T >
Interval< T > SurgSim::Math::Interval< T >::operator+ ( const Interval< T > &  i) const

Standard arithmetic operators extended to intervals

§ operator/()

template<class T >
Interval< T > SurgSim::Math::Interval< T >::operator/ ( const Interval< T > &  i) const
Parameters
ithe interval to be divided by
Returns
the current interval multiplied by the inverse of i
Exceptions
ifi includes 0

§ operator/=()

template<class T >
Interval< T > & SurgSim::Math::Interval< T >::operator/= ( const Interval< T > &  i)
Parameters
ithe interval to be divided by
Returns
the current interval multiplied by the inverse of i
Exceptions
ifi includes 0
Note
the current interval is modified by this operation

§ operator=() [1/2]

template<class T >
Interval< T > & SurgSim::Math::Interval< T >::operator= ( const Interval< T > &  i)

Assignment operator.

Parameters
iInterval to be copied

§ operator=() [2/2]

template<class T >
Interval< T > & SurgSim::Math::Interval< T >::operator= ( Interval< T > &&  i)

Move assignment operator.

Parameters
iInterval to be moved

§ operator==()

template<class T >
bool SurgSim::Math::Interval< T >::operator== ( const Interval< T > &  i) const
Parameters
ithe interval to be tested
Returns
true if the current interval is identical to the input interval

§ overlapsWith()

template<class T >
bool SurgSim::Math::Interval< T >::overlapsWith ( const Interval< T > &  i) const
Parameters
ithe interval the current interval will be tested against
Returns
true if the input interval overlaps the current interval

§ square()

template<class T >
Interval< T > SurgSim::Math::Interval< T >::square ( ) const
Returns
the square of the current interval
Note
if the original interval contains 0, then the result will have the minimum identically set to 0

§ upperHalf()

template<class T >
Interval< T > SurgSim::Math::Interval< T >::upperHalf ( ) const
Returns
the interval from the midpoint to the upper limit

Friends And Related Function Documentation

§ IntervalArithmetic_add

template<class T>
template<class P >
void IntervalArithmetic_add ( const Interval< P > &  a,
const Interval< P > &  b,
Interval< P > *  res 
)
friend

Calculate the sum of two intervals.

Template Parameters
Punderlying type of the interval
Parameters
athe first interval
bthe second interval
res[out] the result of a + b

§ IntervalArithmetic_addadd

template<class T>
template<class P >
void IntervalArithmetic_addadd ( const Interval< P > &  a,
const Interval< P > &  b,
Interval< P > *  res 
)
friend

Calculate the sum of three intervals res + a + b.

Template Parameters
Punderlying type of the interval
Parameters
athe first interval
bthe second interval
res[in/out] the result of res + a + b

§ IntervalArithmetic_addmul

template<class T>
template<class P >
void IntervalArithmetic_addmul ( const Interval< P > &  a,
const Interval< P > &  b,
Interval< P > *  res 
)
friend

Add the product of two intervals to an existing value.

Template Parameters
Punderlying type of the interval
Parameters
athe first interval
bthe second interval
res[in/out] the result of res + (a * b)

§ IntervalArithmetic_addsub

template<class T>
template<class P >
void IntervalArithmetic_addsub ( const Interval< P > &  a,
const Interval< P > &  b,
Interval< P > *  res 
)
friend

Add the difference of two intervals to an existing value.

Template Parameters
Punderlying type of the interval
Parameters
athe first interval
bthe second interval
res[in/out] the result of res + (a - b)

§ IntervalArithmetic_mul

template<class T>
template<class P >
void IntervalArithmetic_mul ( const Interval< P > &  a,
const Interval< P > &  b,
Interval< P > *  res 
)
friend

Calculate the product of two intervals.

Template Parameters
Punderlying type of the interval
Parameters
athe first interval
bthe second interval
res[out] the result of a * b

§ IntervalArithmetic_sub

template<class T>
template<class P >
void IntervalArithmetic_sub ( const Interval< P > &  a,
const Interval< P > &  b,
Interval< P > *  res 
)
friend

Calculate the difference of two intervals.

Template Parameters
Punderlying type of the interval
Parameters
athe first interval
bthe second interval
res[out] the result of a - b

§ IntervalArithmetic_submul

template<class T>
template<class P >
void IntervalArithmetic_submul ( const Interval< P > &  a,
const Interval< P > &  b,
Interval< P > *  res 
)
friend

Subtract the product of two intervals from an existing value.

Template Parameters
Punderlying type of the interval
Parameters
athe first interval
bthe second interval
res[in/out] the result of res - (a * b)

The documentation for this class was generated from the following files: