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

Interval.

Template parameters
T

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).

Public types

using value_type = T

Constructors, destructors, conversion operators

Interval(T&& lower, T&& upper) constexpr noexcept
Construct a new Interval object.
Interval(const T& lower, const T& upper) constexpr
Construct a new Interval object.
Interval(const T& alpha) explicit constexpr
Construct a new Interval object.

Public functions

auto operator=(const T& alpha) -> Interval & -> auto constexpr
Assignment operator.
auto lb() const -> const T & -> auto constexpr
lower bound
auto ub() const -> const T & -> auto constexpr
upper bound
auto length() const -> T -> auto constexpr
length
auto is_invalid() const -> bool -> auto constexpr
Checks if the interval is invalid.
template<typename U>
auto overlaps(const U& other) const -> bool -> auto constexpr
Checks if the current interval overlaps with another interval.
template<typename U>
auto contains(const U& other) const -> bool -> auto constexpr
Checks if the current interval contains another interval.
template<typename U>
auto intersect_with(const U& other) const -> auto constexpr
Computes the intersection of the current interval with another interval or scalar value.
template<typename U>
auto min_dist_with(const U& other) const -> T -> auto constexpr
Computes the minimum distance between the current interval and the other interval or scalar value.
template<typename U>
auto min_dist_change_with(U& other) const -> T -> auto constexpr
Computes the minimum distance between the current interval and the other interval or scalar value, and updates the interval bounds accordingly.

Comparison operators

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

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

Arithmetic operators

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

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

Friends

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

Function documentation

template<typename T>
recti::Interval<T>::Interval(T&& lower, T&& upper) constexpr noexcept

Construct a new Interval object.

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

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

template<typename T>
recti::Interval<T>::Interval(const T& lower, const T& upper) constexpr

Construct a new Interval object.

Parameters
lower in The lower bound of the interval. It represents the minimum value that can be included in the interval.
upper in The "upper" parameter represents the upper bound of the interval. It is the maximum value that can be included in the interval.

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

template<typename T>
recti::Interval<T>::Interval(const T& alpha) explicit constexpr

Construct a new Interval object.

Parameters
alpha in The parameter "alpha" 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.

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

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

Assignment operator.

Parameters
alpha in The parameter "alpha" 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.

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

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

lower bound

Returns a reference to a constant object of type T.

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

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

upper bound

Returns a reference to a constant object of type T.

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

template<typename T>
auto recti::Interval<T>::length() const -> T constexpr

length

Returns a value of type T.

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

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

Checks if the interval is invalid.

Returns true if the interval is invalid, false otherwise.

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

template<typename T> template<typename U>
auto recti::Interval<T>::overlaps(const U& other) const -> bool constexpr

Checks if the current interval overlaps with another interval.

Template parameters
U The type of the other interval.
Parameters
other in The interval to check for overlap.
Returns true if the intervals overlap, false otherwise.

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

template<typename T> template<typename U>
auto recti::Interval<T>::contains(const U& other) const -> bool constexpr

Checks if the current interval contains another interval.

Template parameters
U The type of the other interval or scalar value.
Parameters
other in The interval or scalar value to check if it is contained within the current interval.
Returns true if the current interval contains the other interval or scalar value, false otherwise.

This function checks if the current Interval object contains the interval represented by the other parameter. If the other 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, and the upper bound of the current interval is greater than or equal to the upper bound of the other interval. Otherwise, it assumes the other parameter is a scalar value and checks if it is within the bounds of the current interval.

template<typename T> template<typename U>
auto recti::Interval<T>::intersect_with(const U& other) const constexpr

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

Template parameters
U The type of the other interval or scalar value.
Parameters
other in The interval or scalar value to intersect with the current interval.
Returns The intersection of the current interval with the other 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 parameter. If the other 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 parameter is a scalar value and computes the intersection using the lower and upper bounds of the current interval and the scalar value.

template<typename T> template<typename U>
auto recti::Interval<T>::min_dist_with(const U& other) const -> T constexpr

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

Template parameters
U The type of the other interval or scalar value.
Parameters
other in The interval or scalar value to compute the minimum distance with.
Returns The minimum distance between the current interval and the other interval or scalar value.

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

template<typename T> template<typename U>
auto recti::Interval<T>::min_dist_change_with(U& other) const -> T constexpr

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

Template parameters
U The type of the other interval or scalar value.
Parameters
other in/out The interval or scalar value to compute the minimum distance with.
Returns The minimum distance between the current interval and the other interval or scalar value.

This function returns the minimum distance between the current interval and the interval or scalar value represented by the other parameter. If the other 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 parameter. If the other 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 parameter. If the other parameter is within the current interval, the function updates the interval to the intersection of the current interval and the other interval or scalar value, and returns 0.

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

Equality comparison operator for Interval objects.

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

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<typename T> template<typename U>
auto recti::Interval<T>::operator!=(const Interval<U>& rhs) const -> bool constexpr

Not equal to comparison operator for Interval objects.

Template parameters
U The type of the interval bounds.
Parameters
rhs in The right-hand side Interval object to compare against.
Returns true if the intervals are not equal, false otherwise.

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<typename T> template<typename U>
auto recti::Interval<T>::operator<=>(const U& rhs) const -> std::weak_ordering constexpr

Spaceship comparison operator for Interval objects.

Template parameters
U The type of the value to compare against the interval bounds.
Parameters
rhs in The value to compare against the interval bounds.
Returns std::weak_ordering indicating the relationship between the interval and the value.

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<typename T>
friend auto recti::Interval<T>::operator<=>(const T& lhs, const Interval& rhs) -> std::weak_ordering constexpr

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

Parameters
lhs in The value to compare against the interval bounds.
rhs in The Interval object to compare the value against.
Returns std::weak_ordering indicating the relationship between the value and the interval.

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<typename T>
auto recti::Interval<T>::operator-() const -> Interval constexpr

Negation operator for an Interval object.

Returns The negated 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.

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

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

Template parameters
U The type of the value to add to the interval bounds.
Parameters
alpha in The value to add to the interval bounds.
Returns A reference to the modified Interval object.

This function adds the given value alpha 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<typename T> template<typename U>
auto recti::Interval<T>::operator-=(const U& alpha) -> Interval & constexpr

Subtract a scalar value from an Interval object.

Template parameters
U The type of the scalar value to subtract.
Parameters
alpha in The scalar value to subtract from the Interval object.
Returns A reference to the modified Interval object.

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

template<typename T>
auto recti::Interval<T>::enlarge_with(const T& alpha) -> Interval & constexpr

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

Parameters
alpha in The value to subtract from the lower bound and add to the upper bound.
Returns A reference to the modified Interval object.

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

template<typename T> template<typename U>
friend auto recti::Interval<T>::operator+(Interval rhs, const U& alpha) -> Interval constexpr

Add a scalar value to an Interval object.

Template parameters
U The type of the scalar value to add.
Parameters
rhs in The Interval object to add the scalar value to.
alpha in The scalar value to add to the Interval object.
Returns A new Interval object with the scalar value added to the bounds.

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

template<typename T>
friend auto recti::Interval<T>::operator+(const T& alpha, Interval rhs) -> Interval constexpr

Add (by a scalar)

Parameters
alpha in The scalar value to add to the Interval object.
rhs in The Interval object to add the scalar value to.
Returns A new Interval object with the scalar value added to the bounds.

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

template<typename T> template<typename U>
friend auto recti::Interval<T>::operator-(const Interval& rhs, const U& alpha) -> Interval constexpr

Subtract a scalar value from an Interval object.

Template parameters
U The type of the scalar value to subtract.
Parameters
rhs in The Interval object to subtract the scalar value from.
alpha in The scalar value to subtract from the Interval object.
Returns A new Interval object with the scalar value subtracted from the bounds.

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

template<typename T> 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.

Template parameters
Stream The type of the output stream.
Parameters
out The output stream to write the Interval object to.
intvl The Interval object to be printed.
Returns A reference to the output stream (out) for chaining stream operations.

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].