Interval

#include <Imath/ImathInterval.h>

The Interval class template represents a scalar interval, with predefined typedefs for short, int, float, and double.

An Interval is essentially a Box<T> that allows T to be a scalar.

Example:

#include <Imath/ImathInterval.h>
#include <cassert>

void
interval_example ()
{
    Imath::Intervalf v;

    assert (v.isEmpty ());
    assert (!v.hasVolume ());
    assert (!v.isInfinite ());

    v.extendBy (1.0f);
    assert (!v.isEmpty ());

    v.extendBy (2.0f);
    assert (v.hasVolume ());
    assert (v.intersects (1.5f));
}
typedef Interval<short> Imath::Intervals

Interval of type short.

typedef Interval<int> Imath::Intervali

Interval of type integer.

typedef Interval<float> Imath::Intervalf

Interval of type float.

typedef Interval<double> Imath::Intervald

Interval of type double.

template<class T>
class Interval

An Interval has a min and a max and some miscellaneous functions.

It is basically a Box<T> that allows T to be a scalar.

Direct access to bounds

T min

The minimum value of the interval.

T max

The minimum value of the interval.

Constructors

inline constexpr Interval() noexcept

Initialize to the empty interval.

inline constexpr Interval(const T &point) noexcept

Intitialize to a single point.

inline constexpr Interval(const T &minT, const T &maxT) noexcept

Intitialize to a given (min,max)

Comparison

inline constexpr bool operator==(const Interval<T> &src) const noexcept

Equality.

inline constexpr bool operator!=(const Interval<T> &src) const noexcept

Inequality.

Manipulation

inline void makeEmpty() noexcept

Set the interval to be empty.

An interval is empty if the minimum is greater than the maximum.

inline void extendBy(const T &point) noexcept

Extend the interval to include the given point.

inline void extendBy(const Interval<T> &interval) noexcept

Extend the interval to include the given interval.

inline void makeInfinite() noexcept

Make the interval include the entire range of the base type.

Query

inline constexpr T size() const noexcept

Return the size of the interval. The size is (max-min). An empty box has a size of 0.

inline constexpr T center() const noexcept

Return the center of the interval.

The center is defined as (max+min)/2. The center of an empty interval is undefined.

inline constexpr bool intersects(const T &point) const noexcept

Return true if the given point is inside the interval, false otherwise.

inline constexpr bool intersects(const Interval<T> &interval) const noexcept

Return true if the given interval is inside the interval, false otherwise.

inline constexpr bool isEmpty() const noexcept

Return true if the interval is empty, false otherwise.

An empty interval’s minimum is greater than its maximum.

inline constexpr bool hasVolume() const noexcept

Return true if the interval is larger than a single point, false otherwise.

inline constexpr bool isInfinite() const noexcept

Return true if the interval contains all points, false otherwise.

An infinite box has a mimimum of std::numeric_limits<T>::lowest() and a maximum of std::numeric_limits<T>::max()

template<class T>
std::ostream &Imath::operator<<(std::ostream &s, const Interval<T> &v)

Stream output, as “(min max)”.

Stream output.