cgv
Loading...
Searching...
No Matches
cgv::math::interval< T > Class Template Reference

The interval template represents a closed interval of two numbers, i.e. More...

#include <interval.h>

Public Member Functions

interval operations
 interval ()
 construct empty interval
 
 interval (bool)
 Construct interval over all valid values of the value type, where the parameter is only a dummy to distinguish this constructor from the standard constructor.
 
 interval (const interval< T > &I)
 copy constructor
 
 interval (const T &lb, const T &ub)
 Contruct interval from bounds, sort bounds if necessary. To construct empty interval call the standard constructor.
 
bool empty () const
 check if interval is empty
 
void clear ()
 set to empty interval
 
bool contains (const T &v) const
 check if given value is contained in interval
 
center () const
 return the center value, which is only valid if the interval is not empty
 
size () const
 return the size of the interval
 
interval< T > & intersect (const interval< T > &I)
 set interval to intersection with given interval and return reference to this interval
 
interval< T > intersection (const interval< T > &I) const
 return intersection interval
 
interval< T > & extend (const T &v)
 extend interval such that it includes the given value
 
interval< T > & extend (const T vs[], size_t n)
 extend interval such that it includes the n given values
 
interval< T > & extend (const std::vector< T > &vs)
 extend interval such that it includes the given values
 
interval< T > & extension (const T &v)
 return extension of interval so that it includes the given value
 
interval< T > & extend (const interval< T > &I)
 extend interval such that it includes the given interval
 
interval< T > & extension (const interval< T > &J)
 return extension of interval so that it includes the given interval
 
scalar operators
interval< T > & operator*= (const T &s)
 scale the interval
 
interval< T > operator* (const T &s) const
 return scaled interval
 
interval< T > & operator/= (const T &s)
 divide the interval
 
interval< T > operator/ (const T &s) const
 return divided interval
 
interval< T > & operator+= (const T &s)
 right shift interval by adding scalar to both bounds
 
interval< T > operator+ (const T &s) const
 return right shifted interval
 
interval< T > & operator-= (const T &s)
 left shift interval by subtracting scalar from both bounds
 
interval< T > operator- (const T &s) const
 return left shifted interval
 
interval operators
interval< T > & operator*= (const interval< T > &I)
 compute the interval of all values of all products of values from the two intervals
 
interval< T > operator* (const interval< T > &J) const
 return the interval of all values of products of values from the two intervals
 
interval< T > & operator/= (const interval< T > &I)
 Compute the interval of all values of all quotients of values from the two intervals.
 
interval< T > operator/ (const interval< T > &J) const
 return the interval of all values of quotients of values from the two intervals. See also comments on the /= operator().
 
interval< T > operator- () const
 unary minus operator reflects interval at zero value
 
interval< T > & operator+= (const interval< T > &I)
 compute interval of all sums of values from the two intervals
 
interval< T > operator+ (const interval< T > &J) const
 return interval of all sums of values from the two intervals
 
interval< T > & operator-= (const interval< T > &I)
 compute interval of all differences of values from the two intervals
 
interval< T > operator- (const interval< T > &J) const
 return interval of all differences of values from the two intervals
 
comparison operators
bool operator== (const interval< T > &I) const
 check for equality of two intervals
 
bool operator!= (const interval< T > &I) const
 check for inequality of two intervals
 
bool operator< (const interval< T > &I) const
 only returns true if both intervals are not empty and the operator holds for all values in both intervals
 
bool operator> (const interval< T > &I) const
 only returns true if both intervals are not empty and the operator holds for all values in both intervals
 

Public Attributes

lower_bound
 
upper_bound
 

Detailed Description

template<typename T>
class cgv::math::interval< T >

The interval template represents a closed interval of two numbers, i.e.

[a,b]. All arithmetic operators are overloaded for the interval template. This allows to compute bounds for an arbitrary expression. For example if the variable x is from the interval [-1,1] then the expression x*x is from the interval [0,1], which can be computed via \codebegin interval<int> x(-1,1); interval<int> e = x*x; std::cout << e << std::endl; \codeend Furthermore, the interval template supports further interval based operations like intersection and extension of an interval.

Definition at line 26 of file interval.h.

Constructor & Destructor Documentation

◆ interval() [1/4]

template<typename T >
cgv::math::interval< T >::interval ( )
inline

construct empty interval

Definition at line 37 of file interval.h.

◆ interval() [2/4]

template<typename T >
cgv::math::interval< T >::interval ( bool  )
inline

Construct interval over all valid values of the value type, where the parameter is only a dummy to distinguish this constructor from the standard constructor.

This constructor relies on cgv::type::traits::min and cgv::type::traits::max. Thus if you want to build intervals over non standard types, you need to ensure that these two traits are instantiated for your type when using this constructor.

Definition at line 43 of file interval.h.

◆ interval() [3/4]

template<typename T >
cgv::math::interval< T >::interval ( const interval< T > &  I)
inline

copy constructor

Definition at line 45 of file interval.h.

◆ interval() [4/4]

template<typename T >
cgv::math::interval< T >::interval ( const T &  lb,
const T &  ub 
)
inline

Contruct interval from bounds, sort bounds if necessary. To construct empty interval call the standard constructor.

Definition at line 47 of file interval.h.

Member Function Documentation

◆ center()

template<typename T >
T cgv::math::interval< T >::center ( ) const
inline

return the center value, which is only valid if the interval is not empty

Definition at line 55 of file interval.h.

◆ clear()

template<typename T >
void cgv::math::interval< T >::clear ( )
inline

set to empty interval

Definition at line 51 of file interval.h.

◆ contains()

template<typename T >
bool cgv::math::interval< T >::contains ( const T &  v) const
inline

check if given value is contained in interval

Definition at line 53 of file interval.h.

Referenced by cgv::math::interval< T >::operator/=().

◆ empty()

◆ extend() [1/4]

template<typename T >
interval< T > & cgv::math::interval< T >::extend ( const interval< T > &  I)
inline

extend interval such that it includes the given interval

Definition at line 92 of file interval.h.

References cgv::math::interval< T >::empty(), and cgv::math::interval< T >::extend().

◆ extend() [2/4]

template<typename T >
interval< T > & cgv::math::interval< T >::extend ( const std::vector< T > &  vs)
inline

extend interval such that it includes the given values

Definition at line 84 of file interval.h.

References cgv::math::interval< T >::extend().

◆ extend() [3/4]

◆ extend() [4/4]

template<typename T >
interval< T > & cgv::math::interval< T >::extend ( const T  vs[],
size_t  n 
)
inline

extend interval such that it includes the n given values

Definition at line 78 of file interval.h.

References cgv::math::interval< T >::extend().

◆ extension() [1/2]

template<typename T >
interval< T > & cgv::math::interval< T >::extension ( const interval< T > &  J)
inline

return extension of interval so that it includes the given interval

Definition at line 100 of file interval.h.

References cgv::math::interval< T >::extend().

◆ extension() [2/2]

template<typename T >
interval< T > & cgv::math::interval< T >::extension ( const T &  v)
inline

return extension of interval so that it includes the given value

Definition at line 90 of file interval.h.

References cgv::math::interval< T >::extend().

◆ intersect()

template<typename T >
interval< T > & cgv::math::interval< T >::intersect ( const interval< T > &  I)
inline

set interval to intersection with given interval and return reference to this interval

Definition at line 59 of file interval.h.

Referenced by cgv::math::interval< T >::intersection().

◆ intersection()

template<typename T >
interval< T > cgv::math::interval< T >::intersection ( const interval< T > &  I) const
inline

return intersection interval

Definition at line 65 of file interval.h.

References cgv::math::interval< T >::intersect().

◆ operator!=()

template<typename T >
bool cgv::math::interval< T >::operator!= ( const interval< T > &  I) const
inline

check for inequality of two intervals

Definition at line 181 of file interval.h.

◆ operator*() [1/2]

template<typename T >
interval< T > cgv::math::interval< T >::operator* ( const interval< T > &  J) const
inline

return the interval of all values of products of values from the two intervals

Definition at line 134 of file interval.h.

◆ operator*() [2/2]

template<typename T >
interval< T > cgv::math::interval< T >::operator* ( const T &  s) const
inline

return scaled interval

Definition at line 107 of file interval.h.

◆ operator*=() [1/2]

template<typename T >
interval< T > & cgv::math::interval< T >::operator*= ( const interval< T > &  I)
inline

compute the interval of all values of all products of values from the two intervals

Definition at line 125 of file interval.h.

References cgv::math::interval< T >::empty(), and cgv::math::interval< T >::extend().

◆ operator*=() [2/2]

template<typename T >
interval< T > & cgv::math::interval< T >::operator*= ( const T &  s)
inline

scale the interval

Definition at line 105 of file interval.h.

◆ operator+() [1/2]

template<typename T >
interval< T > cgv::math::interval< T >::operator+ ( const interval< T > &  J) const
inline

return interval of all sums of values from the two intervals

Definition at line 166 of file interval.h.

◆ operator+() [2/2]

template<typename T >
interval< T > cgv::math::interval< T >::operator+ ( const T &  s) const
inline

return right shifted interval

Definition at line 115 of file interval.h.

◆ operator+=() [1/2]

template<typename T >
interval< T > & cgv::math::interval< T >::operator+= ( const interval< T > &  I)
inline

compute interval of all sums of values from the two intervals

Definition at line 156 of file interval.h.

References cgv::math::interval< T >::empty(), and cgv::math::interval< T >::extend().

◆ operator+=() [2/2]

template<typename T >
interval< T > & cgv::math::interval< T >::operator+= ( const T &  s)
inline

right shift interval by adding scalar to both bounds

Definition at line 113 of file interval.h.

◆ operator-() [1/3]

template<typename T >
interval< T > cgv::math::interval< T >::operator- ( ) const
inline

unary minus operator reflects interval at zero value

Definition at line 154 of file interval.h.

References cgv::math::interval< T >::empty().

◆ operator-() [2/3]

template<typename T >
interval< T > cgv::math::interval< T >::operator- ( const interval< T > &  J) const
inline

return interval of all differences of values from the two intervals

Definition at line 170 of file interval.h.

◆ operator-() [3/3]

template<typename T >
interval< T > cgv::math::interval< T >::operator- ( const T &  s) const
inline

return left shifted interval

Definition at line 119 of file interval.h.

◆ operator-=() [1/2]

template<typename T >
interval< T > & cgv::math::interval< T >::operator-= ( const interval< T > &  I)
inline

compute interval of all differences of values from the two intervals

Definition at line 168 of file interval.h.

◆ operator-=() [2/2]

template<typename T >
interval< T > & cgv::math::interval< T >::operator-= ( const T &  s)
inline

left shift interval by subtracting scalar from both bounds

Definition at line 117 of file interval.h.

◆ operator/() [1/2]

template<typename T >
interval< T > cgv::math::interval< T >::operator/ ( const interval< T > &  J) const
inline

return the interval of all values of quotients of values from the two intervals. See also comments on the /= operator().

Definition at line 152 of file interval.h.

◆ operator/() [2/2]

template<typename T >
interval< T > cgv::math::interval< T >::operator/ ( const T &  s) const
inline

return divided interval

Definition at line 111 of file interval.h.

◆ operator/=() [1/2]

template<typename T >
interval< T > & cgv::math::interval< T >::operator/= ( const interval< T > &  I)
inline

Compute the interval of all values of all quotients of values from the two intervals.

Notice that if zero is contained in the second interval, the result is the complete interval of all valid values and the same precondition holds as for the constructor with the bool dummy parameter interval(bool).

Definition at line 139 of file interval.h.

References cgv::math::interval< T >::contains(), cgv::math::interval< T >::empty(), and cgv::math::interval< T >::extend().

◆ operator/=() [2/2]

template<typename T >
interval< T > & cgv::math::interval< T >::operator/= ( const T &  s)
inline

divide the interval

Definition at line 109 of file interval.h.

◆ operator<()

template<typename T >
bool cgv::math::interval< T >::operator< ( const interval< T > &  I) const
inline

only returns true if both intervals are not empty and the operator holds for all values in both intervals

Definition at line 185 of file interval.h.

References cgv::math::interval< T >::empty().

◆ operator==()

template<typename T >
bool cgv::math::interval< T >::operator== ( const interval< T > &  I) const
inline

check for equality of two intervals

Definition at line 176 of file interval.h.

References cgv::math::interval< T >::empty().

◆ operator>()

template<typename T >
bool cgv::math::interval< T >::operator> ( const interval< T > &  I) const
inline

only returns true if both intervals are not empty and the operator holds for all values in both intervals

Definition at line 189 of file interval.h.

References cgv::math::interval< T >::empty().

◆ size()

template<typename T >
T cgv::math::interval< T >::size ( ) const
inline

return the size of the interval

Definition at line 57 of file interval.h.

References cgv::math::interval< T >::empty().

Member Data Documentation

◆ lower_bound

template<typename T >
T cgv::math::interval< T >::lower_bound

Definition at line 30 of file interval.h.

◆ upper_bound

template<typename T >
T cgv::math::interval< T >::upper_bound

Definition at line 32 of file interval.h.


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