Gazebo Math

API Reference

7.5.1

The Interval class represents a range of real numbers. Intervals may be open (a, b), left-closed [a, b), right-closed (a, b], or fully closed [a, b]. More...

#include <gz/math/Interval.hh>

Public Member Functions

 Interval ()=default
 Constructor. More...
 
constexpr Interval (T _leftValue, bool _leftClosed, T _rightValue, bool _rightClosed)
 Constructor. More...
 
bool Contains (const Interval< T > &_other) const
 Check if the interval contains _other interval. More...
 
bool Contains (const T &_value) const
 Check if the interval contains _value More...
 
bool Empty () const
 Check if the interval is empty Some examples of empty intervals include (a, a), [a, a), and [a + 1, a]. More...
 
bool Intersects (const Interval< T > &_other) const
 Check if the interval intersects _other interval. More...
 
bool IsLeftClosed () const
 Check if the interval is left-closed. More...
 
bool IsRightClosed () const
 Check if the interval is right-closed. More...
 
const T & LeftValue () const
 Get the leftmost interval value. More...
 
bool operator!= (const Interval< T > &_other) const
 Inequality test operator. More...
 
bool operator== (const Interval< T > &_other) const
 Equality test operator. More...
 
const T & RightValue () const
 Get the rightmost interval value. More...
 

Static Public Member Functions

static constexpr Interval< T > Closed (T _leftValue, T _rightValue)
 Make a closed interval [_leftValue, _rightValue]. More...
 
static constexpr Interval< T > LeftClosed (T _leftValue, T _rightValue)
 Make a left-closed interval [_leftValue, _rightValue) More...
 
static constexpr Interval< T > Open (T _leftValue, T _rightValue)
 Make an open interval (_leftValue, _rightValue) More...
 
static constexpr Interval< T > RightClosed (T _leftValue, T _rightValue)
 Make a right-closed interval (_leftValue, _rightValue]. More...
 

Static Public Attributes

static const Interval< T > & Unbounded = detail::gUnboundedInterval<T>
 An unbounded interval (-∞, ∞) More...
 

Detailed Description

template<typename T>
class gz::math::Interval< T >

The Interval class represents a range of real numbers. Intervals may be open (a, b), left-closed [a, b), right-closed (a, b], or fully closed [a, b].

Example

#include <iostream>
int main(int argc, char **argv)
{
const gz::math::Intervald defaultInterval;
// A default constructed interval should be empty.
std::cout << "The " << defaultInterval << " interval is empty: "
<< defaultInterval.Empty() << std::endl;
const gz::math::Intervald openInterval =
// An open interval should exclude its endpoints.
std::cout << "The " << openInterval << " interval contains its endpoints: "
<< (openInterval.Contains(openInterval.LeftValue()) ||
openInterval.Contains(openInterval.RightValue()))
const gz::math::Intervald closedInterval =
// A closed interval should include its endpoints.
std::cout << "The " << closedInterval << " interval contains its endpoints: "
<< (closedInterval.Contains(closedInterval.LeftValue()) ||
closedInterval.Contains(closedInterval.RightValue()))
// Closed and open intervals may intersect.
std::cout << "Intervals " << closedInterval << " and " << openInterval
<< " intersect: " << closedInterval.Intersects(openInterval)
// The unbounded interval should include all non-empty intervals.
<< " interval contains all previous non-empty intervals: "
<< (gz::math::Intervald::Unbounded.Contains(openInterval) ||
gz::math::Intervald::Unbounded.Contains(closedInterval))
}

Constructor & Destructor Documentation

◆ Interval() [1/2]

Interval ( )
default

Constructor.

◆ Interval() [2/2]

constexpr Interval ( _leftValue,
bool  _leftClosed,
_rightValue,
bool  _rightClosed 
)
inlineconstexpr

Constructor.

Parameters
[in]_leftValueleftmost interval value
[in]_leftClosedwhether the interval is left-closed or not
[in]_rightValuerightmost interval value
[in]_rightClosedwhether the interval is right-closed or not

Member Function Documentation

◆ Closed()

static constexpr Interval<T> Closed ( _leftValue,
_rightValue 
)
inlinestaticconstexpr

Make a closed interval [_leftValue, _rightValue].

Parameters
[in]_leftValueleftmost interval value
[in]_rightValuerightmost interval value
Returns
the closed interval

References std::move().

◆ Contains() [1/2]

bool Contains ( const Interval< T > &  _other) const
inline

Check if the interval contains _other interval.

Parameters
[in]_otherinterval to check for membership
Returns
true if it is contained, false otherwise

References Interval< T >::Empty().

◆ Contains() [2/2]

bool Contains ( const T &  _value) const
inline

Check if the interval contains _value

Parameters
[in]_valuevalue to check for membership
Returns
true if it is contained, false otherwise

Referenced by Polynomial3< T >::Minimum(), Interval< T >::operator!=(), and Interval< T >::operator==().

◆ Empty()

bool Empty ( ) const
inline

Check if the interval is empty Some examples of empty intervals include (a, a), [a, a), and [a + 1, a].

Returns
true if it is empty, false otherwise

Referenced by Interval< T >::Contains(), Interval< T >::Intersects(), and Polynomial3< T >::Minimum().

◆ Intersects()

bool Intersects ( const Interval< T > &  _other) const
inline

Check if the interval intersects _other interval.

Parameters
[in]_otherinterval to check for intersection
Returns
true if both intervals intersect, false otherwise

References Interval< T >::Empty().

◆ IsLeftClosed()

bool IsLeftClosed ( ) const
inline

Check if the interval is left-closed.

Returns
true if the interval is left-closed, false otherwise

◆ IsRightClosed()

bool IsRightClosed ( ) const
inline

Check if the interval is right-closed.

Returns
true if the interval is right-closed, false otherwise

◆ LeftClosed()

static constexpr Interval<T> LeftClosed ( _leftValue,
_rightValue 
)
inlinestaticconstexpr

Make a left-closed interval [_leftValue, _rightValue)

Parameters
[in]_leftValueleftmost interval value
[in]_rightValuerightmost interval value
Returns
the left-closed interval

References std::move().

◆ LeftValue()

const T& LeftValue ( ) const
inline

Get the leftmost interval value.

Returns
the leftmost interval value

Referenced by Polynomial3< T >::Minimum().

◆ Open()

static constexpr Interval<T> Open ( _leftValue,
_rightValue 
)
inlinestaticconstexpr

Make an open interval (_leftValue, _rightValue)

Parameters
[in]_leftValueleftmost interval value
[in]_rightValuerightmost interval value
Returns
the open interval

References std::move().

◆ operator!=()

bool operator!= ( const Interval< T > &  _other) const
inline

Inequality test operator.

Parameters
_otherinterval to check for inequality
Returns
true if intervals are unequal, false otherwise

References Interval< T >::Contains().

◆ operator==()

bool operator== ( const Interval< T > &  _other) const
inline

Equality test operator.

Parameters
_otherinterval to check for equality
Returns
true if intervals are equal, false otherwise

References Interval< T >::Contains().

◆ RightClosed()

static constexpr Interval<T> RightClosed ( _leftValue,
_rightValue 
)
inlinestaticconstexpr

Make a right-closed interval (_leftValue, _rightValue].

Parameters
[in]_leftValueleftmost interval value
[in]_rightValuerightmost interval value
Returns
the left-closed interval

References std::move().

◆ RightValue()

const T& RightValue ( ) const
inline

Get the rightmost interval value.

Returns
the rightmost interval value

Referenced by Polynomial3< T >::Minimum().

Member Data Documentation

◆ Unbounded

const Interval< T > & Unbounded = detail::gUnboundedInterval<T>
static

An unbounded interval (-∞, ∞)


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