Elementa v8.0.0
Minimalistic library for any C++ application (C++11 and up)
Loading...
Searching...
No Matches
numeric intervals

Description

Author
Juan-Antonio Fernandez-Madrigal. http://jafma.net
Date
2020
Collaboration diagram for numeric intervals:

Classes

class  elementa::math::Interval< ELEMTYPE >
 A numeric interval, either closed, opened or semi-closed. More...
 

Functions

static Interval elementa::math::Interval< ELEMTYPE >::fromWidth (ELEMTYPE mi, ELEMTYPE width, IntervalCl cl=IntervalCl::CLOSED)
 Factory constructor from the minimum and width of the interval. More...
 
 elementa::math::Interval< ELEMTYPE >::Interval (void)
 Default constructor: empty interval. More...
 
 elementa::math::Interval< ELEMTYPE >::Interval (ELEMTYPE mi, ELEMTYPE ma, IntervalCl cl=IntervalCl::CLOSED)
 Constructor from the minimum and maximum of the interval. More...
 
 elementa::math::Interval< ELEMTYPE >::Interval (const Interval &o)
 
 elementa::math::Interval< ELEMTYPE >::Interval (Interval &&o)
 
Intervalelementa::math::Interval< ELEMTYPE >::operator= (const Interval &o)
 
Intervalelementa::math::Interval< ELEMTYPE >::operator= (Interval &&o)
 
ELEMTYPE elementa::math::Interval< ELEMTYPE >::minimum (void) const noexcept
 Return the minimum value. More...
 
ELEMTYPE elementa::math::Interval< ELEMTYPE >::maximum (void) const noexcept
 Return the maximum value. More...
 
ELEMTYPE elementa::math::Interval< ELEMTYPE >::width (void) const noexcept
 Return the distance from the minimum to the maximum. More...
 
IntervalCl elementa::math::Interval< ELEMTYPE >::closedness (void) const noexcept
 < Return the closedness of the interval. More...
 
bool elementa::math::Interval< ELEMTYPE >::closedMin (void) const noexcept
 Return the closedness of the minimum bound. More...
 
bool elementa::math::Interval< ELEMTYPE >::closedMax (void) const noexcept
 Return the closedness of the maximum bound. More...
 
bool elementa::math::Interval< ELEMTYPE >::empty (void) const noexcept
 Return true if the interval is empty. More...
 
Interval elementa::math::Interval< ELEMTYPE >::intersect (const Interval &oth) const noexcept
 < Return the interval that is the intersection of both, or empty if none. More...
 
bool elementa::math::Interval< ELEMTYPE >::containPoint (ELEMTYPE e) const noexcept
 < Return true if E is inside the interval. More...
 
std::string elementa::math::Interval< ELEMTYPE >::to_string (void) const
 < Return a string describing the interval. More...
 
enum class  elementa::math::IntervalCl : uint8_t { CLOSED , OPENED , LEFT_CLOSED , RIGHT_CLOSED }
 Kinds of closedness for numeric intervals. More...
 

Class Documentation

◆ elementa::math::Interval

class elementa::math::Interval
template<typename ELEMTYPE>
class elementa::math::Interval< ELEMTYPE >

A numeric interval, either closed, opened or semi-closed.

ELEMTYPE must have minus, < , - and == operators, and + if the min-width ctor is used.

Definition at line 61 of file intervals.h.

Static Public Member Functions

static Interval fromWidth (ELEMTYPE mi, ELEMTYPE width, IntervalCl cl=IntervalCl::CLOSED)
 Factory constructor from the minimum and width of the interval. More...
 

Public Member Functions

 Interval (void)
 Default constructor: empty interval. More...
 
 Interval (ELEMTYPE mi, ELEMTYPE ma, IntervalCl cl=IntervalCl::CLOSED)
 Constructor from the minimum and maximum of the interval. More...
 
 Interval (const Interval &o)
 
 Interval (Interval &&o)
 
Intervaloperator= (const Interval &o)
 
Intervaloperator= (Interval &&o)
 
ELEMTYPE minimum (void) const noexcept
 Return the minimum value. More...
 
ELEMTYPE maximum (void) const noexcept
 Return the maximum value. More...
 
ELEMTYPE width (void) const noexcept
 Return the distance from the minimum to the maximum. More...
 
IntervalCl closedness (void) const noexcept
 < Return the closedness of the interval. More...
 
bool closedMin (void) const noexcept
 Return the closedness of the minimum bound. More...
 
bool closedMax (void) const noexcept
 Return the closedness of the maximum bound. More...
 
bool empty (void) const noexcept
 Return true if the interval is empty. More...
 
Interval intersect (const Interval &oth) const noexcept
 < Return the interval that is the intersection of both, or empty if none. More...
 
bool containPoint (ELEMTYPE e) const noexcept
 < Return true if E is inside the interval. More...
 
std::string to_string (void) const
 < Return a string describing the interval. More...
 

Enumeration Type Documentation

◆ IntervalCl

enum class elementa::math::IntervalCl : uint8_t
strong

#include <elementa/math/intervals.h>

Kinds of closedness for numeric intervals.

Definition at line 43 of file intervals.h.

Function Documentation

◆ fromWidth()

template<typename ELEMTYPE >
static Interval elementa::math::Interval< ELEMTYPE >::fromWidth ( ELEMTYPE  mi,
ELEMTYPE  width,
IntervalCl  cl = IntervalCl::CLOSED 
)
inlinestatic

#include <elementa/math/intervals.h>

Factory constructor from the minimum and width of the interval.

Throw if the minimum + width yields a number smaller than the minimum.

Parameters
aux,aux2are needed to differ from the min-max constructor. Their values are ignored.

Definition at line 69 of file intervals.h.

References elementa::math::Interval< ELEMTYPE >::width().

◆ Interval() [1/4]

template<typename ELEMTYPE >
elementa::math::Interval< ELEMTYPE >::Interval ( void  )
inline

#include <elementa/math/intervals.h>

Default constructor: empty interval.

Definition at line 75 of file intervals.h.

◆ Interval() [2/4]

template<typename ELEMTYPE >
elementa::math::Interval< ELEMTYPE >::Interval ( ELEMTYPE  mi,
ELEMTYPE  ma,
IntervalCl  cl = IntervalCl::CLOSED 
)
inline

#include <elementa/math/intervals.h>

Constructor from the minimum and maximum of the interval.

Definition at line 82 of file intervals.h.

References ELE_CODE_INVARG.

◆ Interval() [3/4]

template<typename ELEMTYPE >
elementa::math::Interval< ELEMTYPE >::Interval ( const Interval< ELEMTYPE > &  o)
inline

#include <elementa/math/intervals.h>

Definition at line 98 of file intervals.h.

◆ Interval() [4/4]

template<typename ELEMTYPE >
elementa::math::Interval< ELEMTYPE >::Interval ( Interval< ELEMTYPE > &&  o)
inline

#include <elementa/math/intervals.h>

Definition at line 99 of file intervals.h.

◆ operator=() [1/2]

template<typename ELEMTYPE >
Interval & elementa::math::Interval< ELEMTYPE >::operator= ( const Interval< ELEMTYPE > &  o)
inline

#include <elementa/math/intervals.h>

Definition at line 100 of file intervals.h.

◆ operator=() [2/2]

template<typename ELEMTYPE >
Interval & elementa::math::Interval< ELEMTYPE >::operator= ( Interval< ELEMTYPE > &&  o)
inline

#include <elementa/math/intervals.h>

Definition at line 101 of file intervals.h.

◆ minimum()

template<typename ELEMTYPE >
ELEMTYPE elementa::math::Interval< ELEMTYPE >::minimum ( void  ) const
inlinenoexcept

#include <elementa/math/intervals.h>

Return the minimum value.

Definition at line 104 of file intervals.h.

◆ maximum()

template<typename ELEMTYPE >
ELEMTYPE elementa::math::Interval< ELEMTYPE >::maximum ( void  ) const
inlinenoexcept

#include <elementa/math/intervals.h>

Return the maximum value.

Definition at line 107 of file intervals.h.

◆ width()

template<typename ELEMTYPE >
ELEMTYPE elementa::math::Interval< ELEMTYPE >::width ( void  ) const
inlinenoexcept

#include <elementa/math/intervals.h>

Return the distance from the minimum to the maximum.

Definition at line 110 of file intervals.h.

Referenced by elementa::math::Interval< ELEMTYPE >::fromWidth().

◆ closedness()

template<typename ELEMTYPE >
IntervalCl elementa::math::Interval< ELEMTYPE >::closedness ( void  ) const
inlinenoexcept

#include <elementa/math/intervals.h>

< Return the closedness of the interval.

Definition at line 113 of file intervals.h.

◆ closedMin()

template<typename ELEMTYPE >
bool elementa::math::Interval< ELEMTYPE >::closedMin ( void  ) const
inlinenoexcept

#include <elementa/math/intervals.h>

Return the closedness of the minimum bound.

Definition at line 117 of file intervals.h.

◆ closedMax()

template<typename ELEMTYPE >
bool elementa::math::Interval< ELEMTYPE >::closedMax ( void  ) const
inlinenoexcept

#include <elementa/math/intervals.h>

Return the closedness of the maximum bound.

Definition at line 120 of file intervals.h.

◆ empty()

template<typename ELEMTYPE >
bool elementa::math::Interval< ELEMTYPE >::empty ( void  ) const
inlinenoexcept

#include <elementa/math/intervals.h>

Return true if the interval is empty.

Closed intervals will never be empty because they include both extremes even when they are equal.

Definition at line 123 of file intervals.h.

◆ intersect()

template<typename ELEMTYPE >
Interval elementa::math::Interval< ELEMTYPE >::intersect ( const Interval< ELEMTYPE > &  oth) const
inlinenoexcept

#include <elementa/math/intervals.h>

< Return the interval that is the intersection of both, or empty if none.

Definition at line 127 of file intervals.h.

◆ containPoint()

template<typename ELEMTYPE >
bool elementa::math::Interval< ELEMTYPE >::containPoint ( ELEMTYPE  e) const
inlinenoexcept

#include <elementa/math/intervals.h>

< Return true if E is inside the interval.

Definition at line 153 of file intervals.h.

◆ to_string()

template<typename ELEMTYPE >
std::string elementa::math::Interval< ELEMTYPE >::to_string ( void  ) const
inline

#include <elementa/math/intervals.h>

< Return a string describing the interval.

Definition at line 159 of file intervals.h.