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 <SurgSim/Math/IntervalArithmetic.h>`

## Public Member Functions

| Interval ()
| Constructor. More...
| 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
T | getMin () const
T | 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...

## Private Attributes

T | m_min
| The lower (m_min) and upper (m_max) limits of the interval. More...
T | m_max

## 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

  T | underlying data type over which the interval is defined.

See also
  IntervalND<T, N> and IntervalND<T, 3>

## Constructor & Destructor Documentation

## Interval() [1/4]

template<class T >

SurgSim::Math::Interval< T >::Interval | ( |  | ) |

Constructor.

## Interval() [2/4]

template<class T >

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

Constructor.

Parameters

  min | Lower bound of the constructed interval
  max | Upper bound of the constructed interval

Exceptions

  if | max is less than min

## Interval() [3/4]

template<class T >

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

Copy constructor.

Parameters

  i | Interval to be copied

## Interval() [4/4]

template<class T >

SurgSim::Math::Interval< T >::Interval | ( | Interval< T > && | i | ) |

Move constructor.

Parameters

  i | Interval 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

  thickness | the 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

  val | the 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

  x | the 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

  i | the 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

  if | the interval includes 0

## isApprox()

template<class T >

bool SurgSim::Math::Interval< T >::isApprox | ( | const Interval< T > & | i,
|  | const T & | epsilon
| ) |  | const

Parameters

  i | the interval to be tested
  epsilon | the 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

  a1 | first input value
  a2 | second 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

  a1 | first input value
  a2 | second input value
  a3 | third 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

  a1 | first input value
  a2 | second input value
  a3 | third input value
  a4 | fourth 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

  i | the interval to be tested

Returns
  true if the current interval is not identical to the input interval

## operator*() [1/2]

template<class T >

Interval< T > SurgSim::Math::Interval< T >::operator* | ( | const Interval< T > & | i | ) | const

Standard arithmetic operators extended to intervals

## operator*() [2/2]

template<class T >

Interval< T > SurgSim::Math::Interval< T >::operator* | ( | const T & | v | ) | const

Standard arithmetic operators extended to intervals

## operator*=() [1/2]

template<class T >

Interval< T > & SurgSim::Math::Interval< T >::operator*= | ( | const Interval< T > & | i | ) |

Standard arithmetic operators extended to intervals

## operator*=() [2/2]

template<class T >

Interval< T > & SurgSim::Math::Interval< T >::operator*= | ( | const T & | v | ) |

Standard arithmetic operators extended to intervals

## operator+() [1/2]

template<class T >

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

Standard arithmetic operators extended to intervals

## operator+() [2/2]

template<class T >

Interval< T > SurgSim::Math::Interval< T >::operator+ | ( | const T & | v | ) | const

Standard arithmetic operators extended to intervals

## operator+=() [1/2]

template<class T >

Interval< T > & SurgSim::Math::Interval< T >::operator+= | ( | const Interval< T > & | i | ) |

Standard arithmetic operators extended to intervals

## operator+=() [2/2]

template<class T >

Interval< T > & SurgSim::Math::Interval< T >::operator+= | ( | const T & | v | ) |

Standard arithmetic operators extended to intervals

## operator-() [1/3]

template<class T >

Interval< T > SurgSim::Math::Interval< T >::operator- | ( |  | ) | const

Standard arithmetic operators extended to intervals

## operator-() [2/3]

template<class T >

Interval< T > SurgSim::Math::Interval< T >::operator- | ( | const Interval< T > & | i | ) | const

Standard arithmetic operators extended to intervals

## operator-() [3/3]

template<class T >

Interval< T > SurgSim::Math::Interval< T >::operator- | ( | const T & | v | ) | const

Standard arithmetic operators extended to intervals

## operator-=() [1/2]

template<class T >

Interval< T > & SurgSim::Math::Interval< T >::operator-= | ( | const Interval< T > & | i | ) |

Standard arithmetic operators extended to intervals

## operator-=() [2/2]

template<class T >

Interval< T > & SurgSim::Math::Interval< T >::operator-= | ( | const T & | v | ) |

Standard arithmetic operators extended to intervals

## operator/()

template<class T >

Interval< T > SurgSim::Math::Interval< T >::operator/ | ( | const Interval< T > & | i | ) | const

Parameters

  i | the interval to be divided by

Returns
  the current interval multiplied by the inverse of i

Exceptions

  if | i includes 0

## operator/=()

template<class T >

Interval< T > & SurgSim::Math::Interval< T >::operator/= | ( | const Interval< T > & | i | ) |

Parameters

  i | the interval to be divided by

Returns
  the current interval multiplied by the inverse of i

Exceptions

  if | i 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

  i | Interval to be copied

## operator=() [2/2]

template<class T >

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

Move assignment operator.

Parameters

  i | Interval to be moved

## operator==()

template<class T >

bool SurgSim::Math::Interval< T >::operator== | ( | const Interval< T > & | i | ) | const

Parameters

  i | the 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

  i | the 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

  P | underlying type of the interval

Parameters

  a | the first interval
  b | the 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

  P | underlying type of the interval

Parameters

  a | the first interval
  b | the 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

  P | underlying type of the interval

Parameters

  a | the first interval
  b | the 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

  P | underlying type of the interval

Parameters

  a | the first interval
  b | the 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

  P | underlying type of the interval

Parameters

  a | the first interval
  b | the 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

  P | underlying type of the interval

Parameters

  a | the first interval
  b | the 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

  P | underlying type of the interval

Parameters

  a | the first interval
  b | the second interval
  res | [in/out] the result of res - (a * b)

## Member Data Documentation

## m_max

template<class T>

T SurgSim::Math::Interval< T >::m_max

private

## m_min

template<class T>

T SurgSim::Math::Interval< T >::m_min

private

The lower (m_min) and upper (m_max) limits of the interval.

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

- SurgSim/Math/IntervalArithmetic.h
- SurgSim/Math/IntervalArithmetic-inl.h