SPH
Public Member Functions | Static Public Member Functions | Friends | List of all members
Interval Class Reference

Object representing a 1D interval of real numbers. More...

#include <Interval.h>

Public Member Functions

INLINE Interval ()
 Default construction of an empty interval. More...
 
INLINE Interval (const Float &lower, const Float &upper)
 Constructs the interval given its lower and upper bound. More...
 
INLINE void extend (const Float &value)
 Extends the interval to contain given value. More...
 
INLINE void extend (const Interval &other)
 Extends the interval to contain another interval. More...
 
INLINE bool contains (const Float &value) const
 Checks whether value is inside the interval. More...
 
INLINE Interval intersect (const Interval &other) const
 Computes the intersection with another interval. More...
 
INLINE Float clamp (const Float &value) const
 Clamps the given value by the interval. More...
 
INLINE Float lower () const
 Returns lower bound of the interval. More...
 
INLINE Float upper () const
 Returns upper bound of the interval. More...
 
INLINE Float center () const
 Returns the center of the interval. More...
 
INLINE Float size () const
 Returns the size of the interval. More...
 
INLINE bool operator== (const Interval &other) const
 Comparison operator; true if and only if both bounds are equal. More...
 
INLINE bool operator!= (const Interval &other) const
 Negation of comparison operator. More...
 
INLINE bool empty () const
 Returns true if the interval is empty (default constructed). More...
 

Static Public Member Functions

static Interval unbounded ()
 Returns an unbounded (infinite) interval. More...
 

Friends

std::ostream & operator<< (std::ostream &stream, const Interval &range)
 

Detailed Description

Object representing a 1D interval of real numbers.

Can also represent one sided [x, infty] or [-infty, x], or even unbounded [-infty, infty] intervals.

Definition at line 17 of file Interval.h.

Constructor & Destructor Documentation

◆ Interval() [1/2]

INLINE Interval::Interval ( )
inline

Default construction of an empty interval.

Any contains() call will return false, extending the interval will result in zero-size interval containing the inserted value.

Definition at line 27 of file Interval.h.

◆ Interval() [2/2]

INLINE Interval::Interval ( const Float lower,
const Float upper 
)
inline

Constructs the interval given its lower and upper bound.

You can use INFTY and -INFTY to create one-sided or unbounded intervals.

Definition at line 34 of file Interval.h.

Member Function Documentation

◆ center()

INLINE Float Interval::center ( ) const
inline

Returns the center of the interval.

Definition at line 84 of file Interval.h.

◆ clamp()

INLINE Float Interval::clamp ( const Float value) const
inline

Clamps the given value by the interval.

Definition at line 68 of file Interval.h.

◆ contains()

INLINE bool Interval::contains ( const Float value) const
inline

Checks whether value is inside the interval.

Definition at line 55 of file Interval.h.

◆ empty()

INLINE bool Interval::empty ( ) const
inline

Returns true if the interval is empty (default constructed).

Definition at line 104 of file Interval.h.

◆ extend() [1/2]

INLINE void Interval::extend ( const Float value)
inline

Extends the interval to contain given value.

If the value is already inside the interval, nothing changes.

Definition at line 41 of file Interval.h.

◆ extend() [2/2]

INLINE void Interval::extend ( const Interval other)
inline

Extends the interval to contain another interval.

If the other interval is already inside this interval, nothing changes.

Definition at line 49 of file Interval.h.

◆ intersect()

INLINE Interval Interval::intersect ( const Interval other) const
inline

Computes the intersection with another interval.

Definition at line 60 of file Interval.h.

◆ lower()

INLINE Float Interval::lower ( ) const
inline

Returns lower bound of the interval.

Definition at line 74 of file Interval.h.

◆ operator!=()

INLINE bool Interval::operator!= ( const Interval other) const
inline

Negation of comparison operator.

Definition at line 99 of file Interval.h.

◆ operator==()

INLINE bool Interval::operator== ( const Interval other) const
inline

Comparison operator; true if and only if both bounds are equal.

Definition at line 94 of file Interval.h.

◆ size()

INLINE Float Interval::size ( ) const
inline

Returns the size of the interval.

Definition at line 89 of file Interval.h.

◆ unbounded()

static Interval Interval::unbounded ( )
inlinestatic

Returns an unbounded (infinite) interval.

Definition at line 109 of file Interval.h.

◆ upper()

INLINE Float Interval::upper ( ) const
inline

Returns upper bound of the interval.

Definition at line 79 of file Interval.h.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  stream,
const Interval range 
)
friend

Definition at line 23 of file Interval.cpp.


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