Recti 1.2.4
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Friends | List of all members
recti::Interval< T > Class Template Reference

Interval. More...

#include <interval.hpp>

Public Types

using value_type = T
 

Public Member Functions

constexpr Interval ()
 Construct a new Interval object.
 
constexpr Interval (T lower, T upper) noexcept
 Construct a new Interval object.
 
constexpr Interval (const T &value)
 Construct a new Interval object.
 
constexpr auto operator= (const T &value) -> Interval &
 Assignment operator.
 
constexpr auto lb () const -> const T &
 lower bound
 
constexpr auto ub () const -> const T &
 upper bound
 
constexpr auto measure () const -> T
 measure (length)
 
constexpr auto is_invalid () const -> bool
 Checks if the interval is invalid.
 
template<typename U >
constexpr auto overlaps (const U &other_interval) const -> bool
 Checks if the current interval overlaps with another interval.
 
template<typename U >
constexpr auto contains (const U &other_interval) const -> bool
 Checks if the current interval contains another interval.
 
template<typename U >
constexpr auto intersect_with (const U &other_interval) const
 Computes the intersection of the current interval with another interval or scalar value.
 
template<typename U >
constexpr auto hull_with (const U &other_interval) const
 Computes the hull of the current interval with another interval or scalar value.
 
template<typename U >
constexpr auto min_dist_with (const U &other_interval) const -> T
 Computes the minimum distance between the current interval and the other_interval interval or scalar value.
 
constexpr auto nearest_to (const T &reference_value) const -> T
 Find the nearest point to a given value.
 
template<typename U >
constexpr auto min_dist_change_with (U &other_interval) -> T
 Computes the minimum distance between the current interval and the other_interval interval or scalar value, and updates the interval bounds accordingly.
 
constexpr auto get_center () const -> T
 Calculate the center of the interval.
 
constexpr auto lower_corner () const -> T
 Get the lower corner of the interval.
 
constexpr auto upper_corner () const -> T
 Get the upper corner of the interval.
 

Friends

template<class Stream >
auto operator<< (Stream &out, const Interval &intvl) -> Stream &
 Overloads the stream insertion operator (<<) to print an Interval object to the given output stream.
 

Comparison operators

definie ==, !=, <, >, <=, >=.

template<typename U >
constexpr auto operator== (const Interval< U > &rhs) const -> bool
 Equality comparison operator for Interval objects.
 
template<typename U >
constexpr auto operator!= (const Interval< U > &rhs) const -> bool
 Not equal to comparison operator for Interval objects.
 
template<typename U >
constexpr auto operator<=> (const U &rhs) const -> std::weak_ordering
 Spaceship comparison operator for Interval objects.
 
constexpr auto operator<=> (const T &lhs, const Interval &rhs) -> std::weak_ordering
 Spaceship comparison operator for comparing a value with an Interval object.
 

Arithmetic operators

definie +, -, *, /, +=, -=, +=, /=, etc.

constexpr auto operator- () const -> Interval
 Negation operator for an Interval object.
 
template<typename U >
constexpr auto operator+= (const U &value) -> Interval &
 Add a value to the lower and upper bounds of the interval.
 
template<typename U >
constexpr auto operator-= (const U &value) -> Interval &
 Subtract a scalar value from an Interval object.
 
constexpr auto enlarge_with (const T &value) const
 Enlarge the interval by subtracting value from the lower bound and adding value to the upper bound.
 
template<typename U >
constexpr auto operator+ (Interval rhs, const U &value) -> Interval
 Add a scalar value to an Interval object.
 
constexpr auto operator+ (const T &value, Interval rhs) -> Interval
 Add (by a scalar)
 
template<typename U >
constexpr auto operator- (const Interval &rhs, const U &value) -> Interval
 Subtract a scalar value from an Interval object.
 

Detailed Description

template<typename T = int>
class recti::Interval< T >

Interval.

The above code is defining a template class called "Interval" with a default template parameter of type "int". The class has two private member variables: "_lb" (lower bound) and "_ub" (upper bound).

Template Parameters
T

Member Typedef Documentation

◆ value_type

template<typename T = int>
using recti::Interval< T >::value_type = T

Constructor & Destructor Documentation

◆ Interval() [1/3]

template<typename T = int>
constexpr recti::Interval< T >::Interval ( )
inlineconstexpr

Construct a new Interval object.

◆ Interval() [2/3]

template<typename T = int>
constexpr recti::Interval< T >::Interval ( lower,
upper 
)
inlineconstexprnoexcept

Construct a new Interval object.

The function constructs a new Interval object with given lower and upper values.

Parameters
[in]lowerThe lower bound of the interval.
[in]upperThe "upper" parameter is the upper bound of the interval. It represents the maximum value that can be included in the interval.

◆ Interval() [3/3]

template<typename T = int>
constexpr recti::Interval< T >::Interval ( const T &  value)
inlineexplicitconstexpr

Construct a new Interval object.

The function constructs a new Interval object with the same lower and upper bounds.

Parameters
[in]valueThe parameter "value" is of type T, which is a template parameter for the Interval class. It represents the value that will be used as both the lower bound and upper bound of the interval.

Member Function Documentation

◆ contains()

template<typename T = int>
template<typename U >
constexpr auto recti::Interval< T >::contains ( const U &  other_interval) const -> bool
inlineconstexpr

Checks if the current interval contains another interval.

This function checks if the current Interval object contains the interval represented by the other_interval parameter. If the other_interval parameter has a lb() and ub() member function, it checks if the lower bound of the current interval is less than or equal to the lower bound of the other_interval interval, and the upper bound of the current interval is greater than or equal to the upper bound of the other_interval interval. Otherwise, it assumes the other_interval parameter is a scalar value and checks if it is within the bounds of the current interval.

Template Parameters
UThe type of the other_interval interval or scalar value.
Parameters
[in]other_intervalThe interval or scalar value to check if it is contained within the current interval.
Returns
true if the current interval contains the other_interval interval or scalar value, false otherwise.

◆ enlarge_with()

template<typename T = int>
constexpr auto recti::Interval< T >::enlarge_with ( const T &  value) const
inlineconstexpr

Enlarge the interval by subtracting value from the lower bound and adding value to the upper bound.

This function modifies the current Interval object by subtracting value from the lower bound (_lb) and adding value to the upper bound (_ub). It returns a reference to the modified Interval object.

Parameters
[in]valueThe value to subtract from the lower bound and add to the upper bound.

◆ get_center()

template<typename T = int>
constexpr auto recti::Interval< T >::get_center ( ) const -> T
inlineconstexpr

Calculate the center of the interval.

Returns
The center of the interval.

◆ hull_with()

template<typename T = int>
template<typename U >
constexpr auto recti::Interval< T >::hull_with ( const U &  other_interval) const
inlineconstexpr

Computes the hull of the current interval with another interval or scalar value.

This function returns a new Interval object that represents the hull of the current Interval object with the interval or scalar value represented by the other_interval parameter. If the other_interval parameter has lb() and ub() member functions, it computes the hull using the lower and upper bounds of both intervals. Otherwise, it assumes the other_interval parameter is a scalar value and computes the hull using the lower and upper bounds of the current interval and the scalar value.

Template Parameters
UThe type of the other_interval interval or scalar value.
Parameters
[in]other_intervalThe interval or scalar value to intersect with the current interval.
Returns
The hull of the current interval with the other_interval interval or scalar value.

◆ intersect_with()

template<typename T = int>
template<typename U >
constexpr auto recti::Interval< T >::intersect_with ( const U &  other_interval) const
inlineconstexpr

Computes the intersection of the current interval with another interval or scalar value.

This function returns a new Interval object that represents the intersection of the current Interval object with the interval or scalar value represented by the other_interval parameter. If the other_interval parameter has lb() and ub() member functions, it computes the intersection using the lower and upper bounds of both intervals. Otherwise, it assumes the other_interval parameter is a scalar value and computes the intersection using the lower and upper bounds of the current interval and the scalar value.

Template Parameters
UThe type of the other_interval interval or scalar value.
Parameters
[in]other_intervalThe interval or scalar value to intersect with the current interval.
Returns
The intersection of the current interval with the other_interval interval or scalar value.

◆ is_invalid()

template<typename T = int>
constexpr auto recti::Interval< T >::is_invalid ( ) const -> bool
inlineconstexpr

Checks if the interval is invalid.

This function checks if the interval is invalid, which occurs when the lower bound is greater than the upper bound.

Returns
true if the interval is invalid, false otherwise.

◆ lb()

template<typename T = int>
constexpr auto recti::Interval< T >::lb ( ) const -> const T&
inlineconstexpr

lower bound

The function returns a constant reference to the lower bound value.

Returns
a reference to a constant object of type T.

◆ lower_corner()

template<typename T = int>
constexpr auto recti::Interval< T >::lower_corner ( ) const -> T
inlineconstexpr

Get the lower corner of the interval.

Returns
The lower bound.

◆ measure()

template<typename T = int>
constexpr auto recti::Interval< T >::measure ( ) const -> T
inlineconstexpr

measure (length)

The function returns the measure (length) of a range by subtracting the upper bound from the lower bound.

Returns
a value of type T.

◆ min_dist_change_with()

template<typename T = int>
template<typename U >
constexpr auto recti::Interval< T >::min_dist_change_with ( U &  other_interval) -> T
inlineconstexpr

Computes the minimum distance between the current interval and the other_interval interval or scalar value, and updates the interval bounds accordingly.

This function returns the minimum distance between the current interval and the interval or scalar value represented by the other_interval parameter. If the other_interval parameter is less than the current interval, the function updates the lower bound of the current interval to the upper bound, and returns the distance between the new lower bound and the other_interval parameter. If the other_interval parameter is greater than the current interval, the function updates the upper bound of the current interval to the lower bound, and returns the distance between the new upper bound and the other_interval parameter. If the other_interval parameter is within the current interval, the function updates the interval to the intersection of the current interval and the other_interval interval or scalar value, and returns 0.

Template Parameters
UThe type of the other_interval interval or scalar value.
Parameters
[in,out]other_intervalThe interval or scalar value to compute the minimum distance with.
Returns
The minimum distance between the current interval and the other_interval interval or scalar value.

◆ min_dist_with()

template<typename T = int>
template<typename U >
constexpr auto recti::Interval< T >::min_dist_with ( const U &  other_interval) const -> T
inlineconstexpr

Computes the minimum distance between the current interval and the other_interval interval or scalar value.

This function returns the minimum distance between the current interval and the interval or scalar value represented by the other_interval parameter. If the other_interval parameter is less than the current interval, the function returns the distance between the lower bound of the current interval and the other_interval parameter. If the other_interval parameter is greater than the current interval, the function returns the distance between the upper bound of current interval and the other_interval parameter. If the other_interval parameter is within the current interval, the function returns 0.

Template Parameters
UThe type of the other_interval interval or scalar value.
Parameters
[in]other_intervalThe interval or scalar value to compute the minimum distance with.
Returns
The minimum distance between the current interval and the other_interval interval or scalar value.

◆ nearest_to()

template<typename T = int>
constexpr auto recti::Interval< T >::nearest_to ( const T &  reference_value) const -> T
inlineconstexpr

Find the nearest point to a given value.

Parameters
[in]reference_valueThe reference value.
Returns
The nearest point in the interval to obj.

◆ operator!=()

template<typename T = int>
template<typename U >
constexpr auto recti::Interval< T >::operator!= ( const Interval< U > &  rhs) const -> bool
inlineconstexpr

Not equal to comparison operator for Interval objects.

Compares two Interval objects for inequality by negating the result of the == (equal to) operator. If the two intervals are not equal, the operator returns true, otherwise it returns false.

Template Parameters
UThe type of the interval bounds.
Parameters
[in]rhsThe right-hand side Interval object to compare against.
Returns
true if the intervals are not equal, false otherwise.

◆ operator+=()

template<typename T = int>
template<typename U >
constexpr auto recti::Interval< T >::operator+= ( const U &  value) -> Interval&
inlineconstexpr

Add a value to the lower and upper bounds of the interval.

This function adds the given value value to both the lower bound (_lb) and upper bound (_ub) of the Interval object. It then returns a reference to the modified Interval object.

Template Parameters
UThe type of the value to add to the interval bounds.
Parameters
[in]valueThe value to add to the interval bounds.
Returns
A reference to the modified Interval object.

◆ operator-()

template<typename T = int>
constexpr auto recti::Interval< T >::operator- ( ) const -> Interval
inlineconstexpr

Negation operator for an Interval object.

This function returns a new Interval object that is the negation of the current Interval object. The lower bound of the new interval is the negation of the upper bound of the current interval, and the upper bound of the new interval is the negation of the lower bound of the current interval.

Returns
The negated Interval object.

◆ operator-=()

template<typename T = int>
template<typename U >
constexpr auto recti::Interval< T >::operator-= ( const U &  value) -> Interval&
inlineconstexpr

Subtract a scalar value from an Interval object.

This function subtracts the scalar value value from the lower and upper bounds of the Interval object and returns a reference to the modified Interval object.

Template Parameters
UThe type of the scalar value to subtract.
Parameters
[in]valueThe scalar value to subtract from the Interval object.
Returns
A reference to the modified Interval object.

◆ operator<=>()

template<typename T = int>
template<typename U >
constexpr auto recti::Interval< T >::operator<=> ( const U &  rhs) const -> std::weak_ordering
inlineconstexpr

Spaceship comparison operator for Interval objects.

Compares the upper bound (ub) of the Interval object on the left-hand side (LHS) with the value on the right-hand side (RHS). If the LHS upper bound is less than the RHS value, it returns std::weak_ordering::less. If the LHS lower bound is greater than the RHS value, it returns std::weak_ordering::greater. Otherwise, it returns std::weak_ordering::equivalent.

Template Parameters
UThe type of the value to compare against the interval bounds.
Parameters
[in]rhsThe value to compare against the interval bounds.
Returns
std::weak_ordering indicating the relationship between the interval and the value.

◆ operator=()

template<typename T = int>
constexpr auto recti::Interval< T >::operator= ( const T &  value) -> Interval&
inlineconstexpr

Assignment operator.

The assignment operator sets the lower and upper bounds of an Interval object to the given value.

Parameters
[in]valueThe parameter "value" is of type T, which is the type of the object being assigned to the Interval object.
Returns
The assignment operator is returning a reference to the Interval object.

◆ operator==()

template<typename T = int>
template<typename U >
constexpr auto recti::Interval< T >::operator== ( const Interval< U > &  rhs) const -> bool
inlineconstexpr

Equality comparison operator for Interval objects.

Compares two Interval objects for equality by checking if their lower bounds (lb) and upper bounds (ub) are equal. If both the lower bounds and upper bounds are equal, the operator returns true, otherwise it returns false.

Template Parameters
UThe type of the interval bounds.
Parameters
rhsThe right-hand side Interval object to compare against.
Returns
true if the intervals are equal, false otherwise.

◆ overlaps()

template<typename T = int>
template<typename U >
constexpr auto recti::Interval< T >::overlaps ( const U &  other_interval) const -> bool
inlineconstexpr

Checks if the current interval overlaps with another interval.

This function checks if the current Interval object overlaps with the interval represented by the other_interval parameter. It returns true if the intervals overlap, and false otherwise.

Template Parameters
UThe type of the other_interval interval.
Parameters
[in]other_intervalThe interval to check for overlap.
Returns
true if the intervals overlap, false otherwise.

◆ ub()

template<typename T = int>
constexpr auto recti::Interval< T >::ub ( ) const -> const T&
inlineconstexpr

upper bound

The function returns a constant reference to the upper bound value.

Returns
a reference to a constant object of type T.

◆ upper_corner()

template<typename T = int>
constexpr auto recti::Interval< T >::upper_corner ( ) const -> T
inlineconstexpr

Get the upper corner of the interval.

Returns
The upper bound.

Friends And Related Symbol Documentation

◆ operator+ [1/2]

template<typename T = int>
constexpr auto operator+ ( const T &  value,
Interval< T >  rhs 
) -> Interval
friend

Add (by a scalar)

The function adds a scalar value value to an Interval object rhs and returns the resulting Interval object.

Parameters
[in]valueThe scalar value to add to the Interval object.
[in]rhsThe Interval object to add the scalar value to.
Returns
A new Interval object with the scalar value added to the bounds.

◆ operator+ [2/2]

template<typename T = int>
template<typename U >
constexpr auto operator+ ( Interval< T >  rhs,
const U &  value 
) -> Interval
friend

Add a scalar value to an Interval object.

This function creates a new Interval object by adding the scalar value value to the lower and upper bounds of the rhs Interval object.

Template Parameters
UThe type of the scalar value to add.
Parameters
[in]rhsThe Interval object to add the scalar value to.
[in]valueThe scalar value to add to the Interval object.
Returns
A new Interval object with the scalar value added to the bounds.

◆ operator-

template<typename T = int>
template<typename U >
constexpr auto operator- ( const Interval< T > &  rhs,
const U &  value 
) -> Interval
friend

Subtract a scalar value from an Interval object.

This function subtracts the scalar value value from the lower and upper bounds of the Interval object rhs and returns a new Interval object with the modified bounds.

Template Parameters
UThe type of the scalar value to subtract.
Parameters
[in]rhsThe Interval object to subtract the scalar value from.
[in]valueThe scalar value to subtract from the Interval object.
Returns
A new Interval object with the scalar value subtracted from the bounds.

◆ operator<<

template<typename T = int>
template<class Stream >
auto operator<< ( Stream &  out,
const Interval< T > &  intvl 
) -> Stream&
friend

Overloads the stream insertion operator (<<) to print an Interval object to the given output stream.

This function allows Interval objects to be printed directly to an output stream, such as std::cout, by overloading the stream insertion operator (<<). The Interval object is printed in the format [lower_bound, upper_bound].

Template Parameters
StreamThe type of the output stream.
Parameters
outThe output stream to write the Interval object to.
intvlThe Interval object to be printed.
Returns
A reference to the output stream (out) for chaining stream operations.

◆ operator<=>

template<typename T = int>
constexpr auto operator<=> ( const T &  lhs,
const Interval< T > &  rhs 
) -> std::weak_ordering
friend

Spaceship comparison operator for comparing a value with an Interval object.

Compares the given value with the bounds of the Interval object on the right-hand side. If the value is less than the lower bound of the interval, it returns std::weak_ordering::less. If the value is greater than the upper bound of the interval, it returns std::weak_ordering::greater. Otherwise, it returns std::weak_ordering::equivalent.

Template Parameters
TThe type of the value to compare against the interval bounds.
Parameters
[in]lhsThe value to compare against the interval bounds.
[in]rhsThe Interval object to compare the value against.
Returns
std::weak_ordering indicating the relationship between the value and the interval.

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