Thea
Public Types | Public Member Functions | List of all members
AxisAlignedBoxN< N, T > Class Template Reference

An axis-aligned box in N-dimensional space, where N is any positive (non-zero) integer and T is a field. More...

#include <AxisAlignedBoxN.hpp>

Inheritance diagram for AxisAlignedBoxN< N, T >:
AxisAlignedBoxNBase< N, T > RayIntersectableN< N, T >

Public Types

typedef AxisAlignedBoxN< N, T > AxisAlignedBoxT
 N-dimensional axis-aligned box. More...
 

Public Member Functions

void addPoint (VectorT const &p)
 Grow to include a point. More...
 
 AxisAlignedBoxN ()
 Default constructor, creates a null box. More...
 
 AxisAlignedBoxN (VectorT const &v)
 Constructor. More...
 
 AxisAlignedBoxN (VectorT const &lo_, VectorT const &hi_)
 Constructor. More...
 
template<typename U >
AxisAlignedBoxN< N, U > cast () const
 Cast the box to a different scalar type. More...
 
VectorT closestPoint (VectorT const &p) const
 Get the point in this box closest to a given point. More...
 
bool contains (VectorT const &p) const
 Test if this box contains a point. More...
 
bool contains (AxisAlignedBoxT const &other) const
 Test if this box contains another. More...
 
distance (AxisAlignedBoxT const &other) const
 Get the closest distance between this box and another one. More...
 
distance (VectorT const &point) const
 Get the closest distance to a point. More...
 
distance (LineN< N, T > const &line) const
 Get the distance between this box and an infinite line. More...
 
distance (LineSegmentN< N, T > const &seg) const
 Get the distance between this box and a line segment. More...
 
distance (RayN< N, T > const &ray) const
 Get the distance between this box and a ray. More...
 
VectorT getCenter () const
 Get the center of the box. More...
 
VectorT getExtent () const
 Get the extent of the box. More...
 
VectorT const & getHigh () const
 Get the maximum corner of the box. More...
 
VectorT const & getLow () const
 Get the minimum corner of the box. More...
 
VectorT getVertex (uintx i) const
 Get the i'th corner vertex of the box, for i in the range [0, 2^N - 1]. More...
 
bool intersects (VectorT const &p) const
 Test if this box intersects (i.e. More...
 
bool intersects (AxisAlignedBoxT const &other) const
 Test if this box intersects another. More...
 
bool isNull () const
 Check if the box is null. More...
 
maxDistance (VectorT const &point) const
 Get the largest distance between points of this box and a given point. More...
 
void merge (VectorT const &p)
 Grow to include a point. More...
 
void merge (AxisAlignedBoxT const &aab)
 Grow to include a box. More...
 
bool operator== (AxisAlignedBoxNBase const &other) const
 Check if two boxes are equal. More...
 
RayIntersectionN< N, T > rayIntersection (RayN< N, T > const &ray, T max_time=-1) const
 Get the intersection of a ray with the object, including the hit time and the normal at the intersection point. More...
 
rayIntersectionTime (RayN< N, T > const &ray, T max_time=-1) const
 Get the time taken for a ray to intersect the object, or a negative value if there was no intersection in the forward direction. More...
 
bool rayIntersects (RayN< N, T > const &ray, T max_time=-1) const
 Check if a ray intersects the object in the forward direction. More...
 
void scaleCentered (T const &scale)
 Scale the box by a linear factor relative to its center. More...
 
void scaleCentered (VectorT const &scale)
 Scale the box relative to its center. More...
 
AxisAlignedBoxT scaleCenteredCopy (T const &scale) const
 Return a box that is a copy of this, scaled by a linear factor relative to its center. More...
 
AxisAlignedBoxT scaleCenteredCopy (VectorT const &scale) const
 Return a box that is a copy of this, scaled relative to its center. More...
 
void set (VectorT const &lo_, VectorT const &hi_)
 Set the corners of the box. More...
 
void setCenter (VectorT const &center)
 Set the center of the box, without changing its size. More...
 
void setExtent (VectorT const &ext)
 Set the extent (size) of the box, without changing its center. More...
 
void setNull ()
 Set the box to be null. More...
 
squaredDistance (AxisAlignedBoxT const &other) const
 Get the square of the closest distance between this box and another one. More...
 
squaredDistance (VectorT const &point) const
 Get the square of the closest distance to a point. More...
 
squaredDistance (LineN< N, T > const &line, VectorT *this_pt=nullptr, VectorT *line_pt=nullptr) const
 Get the squared distance between this box and an infinite line, and optionally return the closest pair of points. More...
 
squaredDistance (LineSegmentN< N, T > const &seg, VectorT *this_pt=nullptr, VectorT *seg_pt=nullptr) const
 Get the squared distance between this box and a line segment, and optionally return the closest pair of points. More...
 
squaredDistance (RayN< N, T > const &ray, VectorT *this_pt=nullptr, VectorT *ray_pt=nullptr) const
 Get the squared distance between this box and a ray, and optionally return the closest pair of points. More...
 
squaredMaxDistance (VectorT const &point) const
 Get the square of the largest distance between points of this box and a given point. More...
 
std::string toString () const
 Get a string representing the box as "[low, high]", or "[null]" if the box is null. More...
 
template<typename TransformT >
AxisAlignedBoxT transformAndBound (TransformT const &tr) const
 Transform the box and return a new axis-aligned box which tightly encloses the result. More...
 
volume () const
 Get the volume of the box. More...
 

Detailed Description

template<int N, typename T = Real>
class Thea::AxisAlignedBoxN< N, T >

An axis-aligned box in N-dimensional space, where N is any positive (non-zero) integer and T is a field.

Definition at line 30 of file AxisAlignedBoxN.hpp.

Member Typedef Documentation

typedef AxisAlignedBoxN<N, T> AxisAlignedBoxT
inherited

N-dimensional axis-aligned box.

Definition at line 44 of file AxisAlignedBoxN.hpp.

Constructor & Destructor Documentation

Default constructor, creates a null box.

Definition at line 510 of file AxisAlignedBoxN.hpp.

AxisAlignedBoxN ( VectorT const &  v)

Constructor.

Sets the box to be a single point.

Definition at line 513 of file AxisAlignedBoxN.hpp.

AxisAlignedBoxN ( VectorT const &  lo_,
VectorT const &  hi_ 
)

Constructor.

Sets the extents of the box.

Definition at line 516 of file AxisAlignedBoxN.hpp.

Member Function Documentation

void addPoint ( VectorT const &  p)
inherited

Grow to include a point.

Alias for merge(VectorT const &), for use with PointCollectorN.

Definition at line 171 of file AxisAlignedBoxN.hpp.

AxisAlignedBoxN<N, U> cast ( ) const
inherited

Cast the box to a different scalar type.

Definition at line 63 of file AxisAlignedBoxN.hpp.

VectorT closestPoint ( VectorT const &  p) const
inherited

Get the point in this box closest to a given point.

Definition at line 349 of file AxisAlignedBoxN.hpp.

bool contains ( VectorT const &  p) const
inherited

Test if this box contains a point.

Definition at line 291 of file AxisAlignedBoxN.hpp.

bool contains ( AxisAlignedBoxT const &  other) const
inherited

Test if this box contains another.

Null boxes do not contain or are contained by other boxes.

Definition at line 305 of file AxisAlignedBoxN.hpp.

T distance ( AxisAlignedBoxT const &  other) const
inherited

Get the closest distance between this box and another one.

Returns zero if either box is null.

Definition at line 335 of file AxisAlignedBoxN.hpp.

T distance ( VectorT const &  point) const
inherited

Get the closest distance to a point.

Returns zero if the box is null.

Definition at line 355 of file AxisAlignedBoxN.hpp.

T distance ( LineN< N, T > const &  line) const
inherited

Get the distance between this box and an infinite line.

Definition at line 370 of file AxisAlignedBoxN.hpp.

T distance ( LineSegmentN< N, T > const &  seg) const
inherited

Get the distance between this box and a line segment.

Definition at line 379 of file AxisAlignedBoxN.hpp.

T distance ( RayN< N, T > const &  ray) const
inherited

Get the distance between this box and a ray.

Definition at line 388 of file AxisAlignedBoxN.hpp.

VectorT getCenter ( ) const
inherited

Get the center of the box.

The return value is zero for null boxes.

Definition at line 193 of file AxisAlignedBoxN.hpp.

VectorT getExtent ( ) const
inherited

Get the extent of the box.

The return value is zero for null boxes.

Definition at line 207 of file AxisAlignedBoxN.hpp.

VectorT const& getHigh ( ) const
inherited

Get the maximum corner of the box.

The return value is zero if the box is null.

Definition at line 95 of file AxisAlignedBoxN.hpp.

VectorT const& getLow ( ) const
inherited

Get the minimum corner of the box.

The return value is zero if the box is null.

Definition at line 92 of file AxisAlignedBoxN.hpp.

VectorT getVertex ( uintx  i) const
inherited

Get the i'th corner vertex of the box, for i in the range [0, 2^N - 1].

This function works as expected only if N <= sizeof(uintx). The d'th coordinate of the returned point is assigned the d'th coordinate of the maximum corner of the box if the d'th bit of i (where the 0'th bit is the least significant) is 1, and of the minimum corner if it is 0.

Definition at line 110 of file AxisAlignedBoxN.hpp.

bool intersects ( VectorT const &  p) const
inherited

Test if this box intersects (i.e.

contains) a point.

Definition at line 275 of file AxisAlignedBoxN.hpp.

bool intersects ( AxisAlignedBoxT const &  other) const
inherited

Test if this box intersects another.

Null boxes do not intersect each other.

Definition at line 278 of file AxisAlignedBoxN.hpp.

bool isNull ( ) const
inherited

Check if the box is null.

A null box has no extent or location in space. It is not equivalent to a box with zero extent. All null boxes are considered equal.

Definition at line 78 of file AxisAlignedBoxN.hpp.

T maxDistance ( VectorT const &  point) const
inherited

Get the largest distance between points of this box and a given point.

Returns zero if the box is null.

Definition at line 358 of file AxisAlignedBoxN.hpp.

void merge ( VectorT const &  p)
inherited

Grow to include a point.

Equivalent to assignment if this box is initially null.

Definition at line 156 of file AxisAlignedBoxN.hpp.

void merge ( AxisAlignedBoxT const &  aab)
inherited

Grow to include a box.

Equivalent to assignment if this box is initially null. No-op if the argument is a null box.

Definition at line 174 of file AxisAlignedBoxN.hpp.

bool operator== ( AxisAlignedBoxNBase< N, T > const &  other) const
inherited

Check if two boxes are equal.

Null boxes are considered to be equal to each other.

Definition at line 69 of file AxisAlignedBoxN.hpp.

RayIntersectionN<N, T> rayIntersection ( RayN< N, T > const &  ray,
max_time = -1 
) const
virtualinherited

Get the intersection of a ray with the object, including the hit time and the normal at the intersection point.

A negative time is returned if there was no intersection in the forward direction. If the normal cannot be computed, the zero vector is returned.

Parameters
rayThe ray to test for intersection.
max_timeMaximum allowable hit time, ignored if negative.
Note
The returned normal need not have unit length.

Reimplemented from RayIntersectableN< N, T >.

Definition at line 420 of file AxisAlignedBoxN.hpp.

T rayIntersectionTime ( RayN< N, T > const &  ray,
max_time = -1 
) const
virtualinherited

Get the time taken for a ray to intersect the object, or a negative value if there was no intersection in the forward direction.

All subclasses must reimplement this method. If the return value is negative, it should be at least

Parameters
rayThe ray to test for intersection.
max_timeMaximum allowable hit time, ignored if negative.

Implements RayIntersectableN< N, T >.

Definition at line 413 of file AxisAlignedBoxN.hpp.

bool rayIntersects ( RayN< N, T > const &  ray,
max_time = -1 
) const
virtualinherited

Check if a ray intersects the object in the forward direction.

Parameters
rayThe ray to test for intersection.
max_timeMaximum allowable hit time, ignored if negative.

Reimplemented from RayIntersectableN< N, T >.

Definition at line 407 of file AxisAlignedBoxN.hpp.

void scaleCentered ( T const &  scale)
inherited

Scale the box by a linear factor relative to its center.

No-op if the box is null.

Definition at line 235 of file AxisAlignedBoxN.hpp.

void scaleCentered ( VectorT const &  scale)
inherited

Scale the box relative to its center.

No-op if the box is null.

Definition at line 246 of file AxisAlignedBoxN.hpp.

AxisAlignedBoxT scaleCenteredCopy ( T const &  scale) const
inherited

Return a box that is a copy of this, scaled by a linear factor relative to its center.

Definition at line 257 of file AxisAlignedBoxN.hpp.

AxisAlignedBoxT scaleCenteredCopy ( VectorT const &  scale) const
inherited

Return a box that is a copy of this, scaled relative to its center.

Definition at line 266 of file AxisAlignedBoxN.hpp.

void set ( VectorT const &  lo_,
VectorT const &  hi_ 
)
inherited

Set the corners of the box.

Definition at line 98 of file AxisAlignedBoxN.hpp.

void setCenter ( VectorT const &  center)
inherited

Set the center of the box, without changing its size.

No-op if the box is null.

Definition at line 196 of file AxisAlignedBoxN.hpp.

void setExtent ( VectorT const &  ext)
inherited

Set the extent (size) of the box, without changing its center.

No-op if the box is null.

Definition at line 210 of file AxisAlignedBoxN.hpp.

void setNull ( )
inherited

Set the box to be null.

See also
isNull()

Definition at line 85 of file AxisAlignedBoxN.hpp.

T squaredDistance ( AxisAlignedBoxT const &  other) const
inherited

Get the square of the closest distance between this box and another one.

Returns zero if either box is null.

Definition at line 319 of file AxisAlignedBoxN.hpp.

T squaredDistance ( VectorT const &  point) const
inherited

Get the square of the closest distance to a point.

Returns zero if the box is null.

Definition at line 338 of file AxisAlignedBoxN.hpp.

T squaredDistance ( LineN< N, T > const &  line,
VectorT this_pt = nullptr,
VectorT line_pt = nullptr 
) const
inherited

Get the squared distance between this box and an infinite line, and optionally return the closest pair of points.

Definition at line 373 of file AxisAlignedBoxN.hpp.

T squaredDistance ( LineSegmentN< N, T > const &  seg,
VectorT this_pt = nullptr,
VectorT seg_pt = nullptr 
) const
inherited

Get the squared distance between this box and a line segment, and optionally return the closest pair of points.

Definition at line 382 of file AxisAlignedBoxN.hpp.

T squaredDistance ( RayN< N, T > const &  ray,
VectorT this_pt = nullptr,
VectorT ray_pt = nullptr 
) const
inherited

Get the squared distance between this box and a ray, and optionally return the closest pair of points.

Definition at line 391 of file AxisAlignedBoxN.hpp.

T squaredMaxDistance ( VectorT const &  point) const
inherited

Get the square of the largest distance between points of this box and a given point.

Returns zero if the box is null.

Definition at line 361 of file AxisAlignedBoxN.hpp.

std::string toString ( ) const
inherited

Get a string representing the box as "[low, high]", or "[null]" if the box is null.

Definition at line 397 of file AxisAlignedBoxN.hpp.

AxisAlignedBoxT transformAndBound ( TransformT const &  tr) const
inherited

Transform the box and return a new axis-aligned box which tightly encloses the result.

Algorithm derived from the Ogre source code, http://www.ogre3d.org.

Definition at line 124 of file AxisAlignedBoxN.hpp.

T volume ( ) const
inherited

Get the volume of the box.

A null box has zero volume.

Definition at line 222 of file AxisAlignedBoxN.hpp.


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