Box

#include <Imath/ImathBox.h>

The Box class template represents 2D and 3D axis-aligned bounding boxes, with predefined typedefs for boxes of type short, int, int64_t, float, and double.

The box is defined by minimum and maximum values along each axis, represented by Vec2<T> for the Box2 types and by Vec3<T> for Box3 types.

There are also various utility functions that operate on bounding boxes defined in ImathBoxAlgo.h and described in Box Functions.

Example:

#include <Imath/ImathBox.h>
        
void
box_example()
{
    Imath::V3f   a (0, 0, 0);
    Imath::V3f   b (1, 1, 1);
    Imath::V3f   c (2, 9, 2);

    Imath::Box3f box (a);

    assert (box.isEmpty());
    assert (!box.isInfinite());
    assert (!box.hasVolume());
    
    box.extendBy (c);

    assert (box.size() == (c-a));
    assert (box.intersects (b));
    assert (box.max[0] > box.min[0]);
    assert (box.max[1] > box.min[1]);
    assert (box.max[2] > box.min[2]);
    assert (box.hasVolume());
    assert (box.majorAxis() == 1);
}
typedef Box<V2s> Imath::Box2s

2D box of base type short.

typedef Box<V2i> Imath::Box2i

2D box of base type int.

typedef Box<V2i64> Imath::Box2i64

2D box of base type int64_t.

typedef Box<V2f> Imath::Box2f

2D box of base type float.

typedef Box<V2d> Imath::Box2d

2D box of base type double.

typedef Box<V3s> Imath::Box3s

3D box of base type short.

typedef Box<V3i> Imath::Box3i

3D box of base type int.

typedef Box<V3i64> Imath::Box3i64

3D box of base type int64_t.

typedef Box<V3f> Imath::Box3f

3D box of base type float.

typedef Box<V3d> Imath::Box3d

3D box of base type double.

template<class V>
class Imath::Box

The Box<V> template represents an axis-aligned bounding box defined by minimum and maximum values of type V.

The min and max members are public.

The type V is typically an Imath vector (i.e. V2i, V3f, etc) and must implement an index operator[] that returns a type (typically as scalar) that supports assignment, comparison, and arithmetic operators.

V must also provide a constructor that takes a float and/or double for use in initializing the box.

V must also provide a function V::dimensions() which returns the number of dimensions in the class (since its assumed its a vector) preferably, this returns a constant expression, typically 2 or 3.

Direct access to bounds

V min

The minimum value of the box.

V max

The maximum value of the box.

Constructors

inline constexpr Box() noexcept

Construct an empty bounding box.

This initializes the mimimum to std::numeric_limits<V::baseType>::max() and the maximum to std::numeric_limits<V::baseType>::lowest().

inline constexpr Box(const V &point) noexcept

Construct a bounding box that contains a single point.

inline constexpr Box(const V &minV, const V &maxV) noexcept

Construct a bounding box with the given minimum and maximum values.

Comparison

inline constexpr bool operator==(const Box<V> &src) const noexcept

Equality.

inline constexpr bool operator!=(const Box<V> &src) const noexcept

Inequality.

Manipulation

inline void makeEmpty() noexcept

Set the box to be empty.

A box is empty if the mimimum is greater than the maximum. makeEmpty() sets the mimimum to V::baseTypeMax() and the maximum to V::baseTypeLowest().

inline void extendBy(const V &point) noexcept

Extend the box to include the given point.

inline void extendBy(const Box<V> &box) noexcept

Extend the box to include the given box.

inline void makeInfinite() noexcept

Make the box include the entire range of V.

Query

inline constexpr V size() const noexcept

Return the size of the box.

The size is of type V, defined as (max-min). An empty box has a size of V(0), i.e. 0 in each dimension.

inline constexpr V center() const noexcept

Return the center of the box.

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

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

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

inline constexpr bool intersects(const Box<V> &box) const noexcept

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

inline constexpr unsigned int majorAxis() const noexcept

Return the major axis of the box.

The major axis is the dimension with the greatest difference between maximum and minimum.

inline constexpr bool isEmpty() const noexcept

Return true if the box is empty, false otherwise.

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

inline constexpr bool hasVolume() const noexcept

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

inline constexpr bool isInfinite() const noexcept

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

An infinite box has a mimimum ofV::baseTypeLowest() and a maximum of V::baseTypeMax().

template<class T>
class Imath::Box<Vec2<T>>

The Box<Vec2<T>> template represents a 2D bounding box defined by minimum and maximum values of type Vec2<T>.

The min and max members are public.

Direct access to bounds

Vec2<T> min

The minimum value of the box.

Vec2<T> max

The maximum value of the box.

Constructors and Assignment

inline constexpr Box() noexcept

Empty by default.

inline constexpr Box(const Vec2<T> &point) noexcept

Construct a bounding box that contains a single point.

inline constexpr Box(const Vec2<T> &minT, const Vec2<T> &maxT) noexcept

Construct a bounding box with the given minimum and maximum points.

Comparison

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

Equality.

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

Inequality.

Manipulation

inline void makeEmpty() noexcept

Set the Box to be empty.

A Box is empty if the mimimum is greater than the maximum. makeEmpty() sets the mimimum to `numeric_limits<T>::max()’ and the maximum to numeric_limits<T>::lowest().

inline void extendBy(const Vec2<T> &point) noexcept

Extend the Box to include the given point.

inline void extendBy(const Box<Vec2<T>> &box) noexcept

Extend the Box to include the given box.

inline void makeInfinite() noexcept

Make the box include the entire range of T.

Query

inline constexpr Vec2<T> size() const noexcept

Return the size of the box.

The size is of type V, defined as (max-min). An empty box has a size of V(0), i.e. 0 in each dimension.

inline constexpr Vec2<T> center() const noexcept

Return the center of the box.

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

inline constexpr bool intersects(const Vec2<T> &point) const noexcept

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

inline constexpr bool intersects(const Box<Vec2<T>> &box) const noexcept

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

inline constexpr unsigned int majorAxis() const noexcept

Return the major axis of the box.

The major axis is the dimension with the greatest difference between maximum and minimum.

inline constexpr bool isEmpty() const noexcept

Return true if the box is empty, false otherwise.

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

inline constexpr bool hasVolume() const noexcept

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

inline constexpr bool isInfinite() const noexcept

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

An infinite box has a mimimum of V::baseTypeMin() and a maximum of V::baseTypeMax().

template<class T>
class Imath::Box<Vec3<T>>

The Box<Vec3> template represents a 3D bounding box defined by minimum and maximum values of type Vec3.

Direct access to bounds

Vec3<T> min

The minimum value of the box.

Vec3<T> max

The maximum value of the box.

Constructors

inline constexpr Box() noexcept

Empty by default.

inline constexpr Box(const Vec3<T> &point) noexcept

Construct a bounding box that contains a single point.

inline constexpr Box(const Vec3<T> &minT, const Vec3<T> &maxT) noexcept

Construct a bounding box with the given minimum and maximum points.

Public Functions

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

Equality.

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

Inequality.

inline void makeEmpty() noexcept

Set the Box to be empty.

A Box is empty if the mimimum is greater than the maximum. makeEmpty() sets the mimimum to numeric_limits<T>::max() and the maximum to numeric_limits<T>::lowest().

inline void extendBy(const Vec3<T> &point) noexcept

Extend the Box to include the given point.

inline void extendBy(const Box<Vec3<T>> &box) noexcept

Extend the Box to include the given box.

inline void makeInfinite() noexcept

Make the box include the entire range of T.

inline constexpr Vec3<T> size() const noexcept

Return the size of the box.

The size is of type V, defined as (max-min). An empty box has a size of V(0), i.e. 0 in each dimension.

inline constexpr Vec3<T> center() const noexcept

Return the center of the box.

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

inline constexpr bool intersects(const Vec3<T> &point) const noexcept

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

inline constexpr bool intersects(const Box<Vec3<T>> &box) const noexcept

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

inline constexpr unsigned int majorAxis() const noexcept

Return the major axis of the box.

The major axis is the dimension with the greatest difference between maximum and minimum.

inline constexpr bool isEmpty() const noexcept

Return true if the box is empty, false otherwise.

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

inline constexpr bool hasVolume() const noexcept

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

inline constexpr bool isInfinite() const noexcept

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

An infinite box has a mimimum ofV::baseTypeMin() and a maximum of V::baseTypeMax().