Ocean
Ocean::BoxT2< T > Class Template Reference

This class implements an axis aligned 2D box object. More...

Inheritance diagram for Ocean::BoxT2< T >:

Public Types

typedef T Type
 Definition of the used data type. More...
 

Public Member Functions

 BoxT2 ()
 Creates an invalid box object. More...
 
 BoxT2 (const VectorT2< T > &first, const VectorT2< T > &second)
 Creates a new box object by two opposite corner positions. More...
 
 BoxT2 (const VectorT2< T > &center, const T width, const T height)
 Creates a new box object by the center position and the box's dimension. More...
 
 BoxT2 (const T width, const T height, const VectorT2< T > &topLeft)
 Creates a new box object by the center position and the box's dimension. More...
 
 BoxT2 (const T left, const T top, const T right, const T bottom)
 Creates a new box object by the four borders. More...
 
 BoxT2 (const std::vector< VectorT2< T >> &points)
 Creates a new box object by a set of points. More...
 
 BoxT2 (const TriangleT2< T > &triangle)
 Creates a new box object that covers a given triangle. More...
 
 BoxT2 (const std::vector< TriangleT2< T >> &triangles)
 Creates a new box object by a set of triangles. More...
 
 BoxT2 (const VectorT2< T > *points, const size_t number)
 Creates a new box object by a set of points. More...
 
const VectorT2< T > & lower () const
 Returns the lower corner of this box. More...
 
const VectorT2< T > & higher () const
 Returns the higher corner of this box. More...
 
const T & left () const
 Returns the horizontal position of the lower corner of this box. More...
 
const T & top () const
 Returns the vertical position of the lower corner of this box. More...
 
const T & right () const
 Returns the horizontal position of the higher corner of this box. More...
 
const T & bottom () const
 Returns the vertical position of the higher corner of this box. More...
 
width () const
 Returns the width of the box. More...
 
height () const
 Returns the height of the box. More...
 
VectorT2< T > center () const
 Returns the center of this box. More...
 
xDimension () const
 Returns the dimension in x axis, which could e.g. More...
 
yDimension () const
 Returns the dimension in x axis, which could e.g. More...
 
area () const
 Returns the area covered by this box. More...
 
bool isInside (const VectorT2< T > &point) const
 Returns whether a given point is inside the box. More...
 
bool isInside (const VectorT2< T > &point, const T &epsilon) const
 Returns whether a given point is inside the box including a thin epsilon boundary. More...
 
bool isInside (const BoxT2< T > &box) const
 Returns whether a given box is entirely inside this box. More...
 
bool intersects (const BoxT2< T > &box) const
 Returns whether a given box intersects this one. More...
 
BoxT2< T > intersection (const BoxT2< T > &box) const
 Returns the intersection of two boxes. More...
 
BoxT2< T > rounded () const
 Returns this box with corners rounded to integer locations. More...
 
VectorT2< T > corner (const unsigned int index) const
 Returns one of the four corners of this 2D box. More...
 
bool isPoint () const
 Returns whether the box holds exactly one point. More...
 
bool isEqual (const BoxT2< T > &box, const T epsilon=NumericT< T >::eps()) const
 Returns whether two box objects are equal up to an epsilon. More...
 
bool isValid () const
 Returns whether the box holds valid parameters. More...
 
BoxT2< T > operator+ (const BoxT2< T > &right) const
 Returns the combined box given by this one and a second box. More...
 
BoxT2< T > operator+ (const TriangleT2< T > &triangle) const
 Extends this box by a triangle (by the three points of the triangle). More...
 
BoxT2< T > operator+ (const VectorT2< T > &point) const
 Extends this box by another 2D point and returns the result. More...
 
BoxT2< T > operator+ (const T signedBorder) const
 Extends this box by adding a border around the box. More...
 
BoxT2< T > & operator+= (const BoxT2< T > &right)
 Adds a box to this box. More...
 
BoxT2< T > & operator+= (const TriangleT2< T > &triangle)
 Adds a triangle (the three points of the triangle) to this box. More...
 
BoxT2< T > & operator+= (const VectorT2< T > &point)
 Extends this box by another 2D point. More...
 
BoxT2< T > & operator+= (const T signedBorder)
 Extends this box by adding a border around the box. More...
 
BoxT2< T > operator* (const T factor) const
 Returns a new bounding box with scaled dimensions. More...
 
BoxT2< T > & operator*= (const T factor)
 Scales this bounding box with a scalar factor. More...
 
BoxT2< T > operator* (const SquareMatrixT3< T > &transformation) const
 Returns a new bounding box enclosing the transformed corners of this bounding box. More...
 
BoxT2< T > & operator*= (const SquareMatrixT3< T > &transformation)
 Transforms this bounding box with a transformation matrix. More...
 
bool operator== (const BoxT2< T > &right) const
 Returns whether two boxes are identical. More...
 
bool operator!= (const BoxT2< T > &right) const
 Returns whether two boxes are not identical. More...
 
 operator bool () const
 Returns whether this box is not a default box. More...
 
bool box2integer (const int constraintLeft, const int constraintTop, const int constraintRight, const int constraintBottom, int &intersectionLeft, int &intersectionTop, unsigned int &intersectionWidth, unsigned int &intersectionHeight) const
 Calculates the intersection of this bounding box (with floating point accuracy) and a second bounding box (with integer accuracy). More...
 
bool box2integer (const unsigned int maximalWidth, const unsigned int maximalHeight, unsigned int &intersectionLeft, unsigned int &intersectionTop, unsigned int &intersectionWidth, unsigned int &intersectionHeight) const
 Calculates the intersection of this bounding box (with floating point accuracy) and a second bounding box (with integer accuracy). More...
 
bool box2integer (const unsigned int maximalWidth, const unsigned int maximalHeight, const unsigned int extraBorder, unsigned int &intersectionLeft, unsigned int &intersectionTop, unsigned int &intersectionWidth, unsigned int &intersectionHeight) const
 Calculates the intersection of this bounding box (with floating point accuracy) and a second bounding box (with integer accuracy). More...
 

Protected Attributes

VectorT2< T > lower_
 Lower box corner. More...
 
VectorT2< T > higher_
 Higher box corner. More...
 

Detailed Description

template<typename T>
class Ocean::BoxT2< T >

This class implements an axis aligned 2D box object.

Template Parameters
TData type used to represent coordinates
See also
Box2, BoxF2, BoxD2.

Member Typedef Documentation

◆ Type

template<typename T >
typedef T Ocean::BoxT2< T >::Type

Definition of the used data type.

Constructor & Destructor Documentation

◆ BoxT2() [1/9]

template<typename T >
Ocean::BoxT2< T >::BoxT2

Creates an invalid box object.

◆ BoxT2() [2/9]

template<typename T >
Ocean::BoxT2< T >::BoxT2 ( const VectorT2< T > &  first,
const VectorT2< T > &  second 
)

Creates a new box object by two opposite corner positions.

Parameters
firstThe first 2D corner position, (-infinity, infinity)x(-infinity, infinity)
secondThe second 2D corner position (opposite to the first position), (-infinity, infinity)x(-infinity, infinity)

◆ BoxT2() [3/9]

template<typename T >
Ocean::BoxT2< T >::BoxT2 ( const VectorT2< T > &  center,
const T  width,
const T  height 
)

Creates a new box object by the center position and the box's dimension.

Parameters
centerThe center position of the box to create
widthThe width or horizontal dimension of the box, with range [0, infinity)
heightThe height or vertical dimension of the box, with range [0, infinity)

◆ BoxT2() [4/9]

template<typename T >
Ocean::BoxT2< T >::BoxT2 ( const T  width,
const T  height,
const VectorT2< T > &  topLeft 
)

Creates a new box object by the center position and the box's dimension.

Parameters
widthThe width or horizontal dimension of the box, with range [0, infinity)
heightThe height or vertical dimension of the box, with range [0, infinity)
topLeftThe top left location of this bounding box, with range (-infinity, infinity)x(-infinity, infinity)

◆ BoxT2() [5/9]

template<typename T >
Ocean::BoxT2< T >::BoxT2 ( const T  left,
const T  top,
const T  right,
const T  bottom 
)

Creates a new box object by the four borders.

Parameters
leftLeft box border position, with range (-infinity, infinity)
topTop box border position, with range (-infinity, infinity)
rightRight box border position, with range [left, infinity)
bottomBottom box border position, with range [top, infinity)

◆ BoxT2() [6/9]

template<typename T >
Ocean::BoxT2< T >::BoxT2 ( const std::vector< VectorT2< T >> &  points)
explicit

Creates a new box object by a set of points.

The resulting box will cover all given points.
If no point is provided, the resulting box will be invalid.

Parameters
pointsPoints to create the box from, can be empty

◆ BoxT2() [7/9]

template<typename T >
Ocean::BoxT2< T >::BoxT2 ( const TriangleT2< T > &  triangle)
inlineexplicit

Creates a new box object that covers a given triangle.

Parameters
triangleTriangle to create the box from

◆ BoxT2() [8/9]

template<typename T >
Ocean::BoxT2< T >::BoxT2 ( const std::vector< TriangleT2< T >> &  triangles)
explicit

Creates a new box object by a set of triangles.

The resulting box will cover all given triangles.
If no triangle is provided, the resulting box will be invalid.

Parameters
trianglesTriangles to create the box from, can be empty

◆ BoxT2() [9/9]

template<typename T >
Ocean::BoxT2< T >::BoxT2 ( const VectorT2< T > *  points,
const size_t  number 
)

Creates a new box object by a set of points.

The resulting box will cover all given points.
If no point is provided, the resulting box will be invalid.

Parameters
pointsThe points to create the box from, can be nullptr if number == 0
numberThe number of given points, with range [0, infinity)

Member Function Documentation

◆ area()

template<typename T >
T Ocean::BoxT2< T >::area
inline

Returns the area covered by this box.

The result is undefined for invalid boxes.

Returns
Box area

◆ bottom()

template<typename T >
const T & Ocean::BoxT2< T >::bottom
inline

Returns the vertical position of the higher corner of this box.

Returns
Top position

◆ box2integer() [1/3]

template<typename T >
bool Ocean::BoxT2< T >::box2integer ( const int  constraintLeft,
const int  constraintTop,
const int  constraintRight,
const int  constraintBottom,
int &  intersectionLeft,
int &  intersectionTop,
unsigned int &  intersectionWidth,
unsigned int &  intersectionHeight 
) const

Calculates the intersection of this bounding box (with floating point accuracy) and a second bounding box (with integer accuracy).

The resulting intersection (with integer accuracy) will entirely enclose this floating point bounding box - unless not possible due to the given constraints e.g., 'constraintLeft', 'constraintTop', ...
If this box is invalid, than the provided integer bounding box will be returned.

Parameters
constraintLeftMost left (including) position of the resulting intersection, with range (-infinity, infinity)
constraintTopMost top (including) position of the resulting intersection, with range (-infinity, infinity)
constraintRightMost right (including) position of the resulting intersection, with range [left, infinity)
constraintBottomMost bottom (including) position of the resulting intersection, with range [top, infinity)
intersectionLeftResulting horizontal start position of the intersection, with range [constraintLeft, constraintRight]
intersectionTopResulting vertical start position of the intersection, with range [constraintTop, constraintBottom]
intersectionWidthResulting width of the sub-region, with range [0, constraintRight - constraintLeft + 1]
intersectionHeightResulting height of the sub-region, with range [0, constraintBottom - constraintTop + 1]
Returns
True, if the resulting intersection has an area larger than zero (if the intersection is valid)

◆ box2integer() [2/3]

template<typename T >
bool Ocean::BoxT2< T >::box2integer ( const unsigned int  maximalWidth,
const unsigned int  maximalHeight,
const unsigned int  extraBorder,
unsigned int &  intersectionLeft,
unsigned int &  intersectionTop,
unsigned int &  intersectionWidth,
unsigned int &  intersectionHeight 
) const

Calculates the intersection of this bounding box (with floating point accuracy) and a second bounding box (with integer accuracy).

The resulting intersection (with integer accuracy) will entirely enclose this floating point bounding box - unless not possible due to the given constraints e.g., 'maximalWidth', 'maximalHeight', ...
If this box is invalid, than the provided integer bounding box will be returned.

Parameters
maximalWidthMaximal width of the sub-region, with range [0, infinity)
maximalHeightMaximal height of the sub-region, with range [0, infinity)
extraBorderExplicit border that will be added to the left, top, right and bottom borders of the resulting intersection (as long as the specified constraints 'maximalWidth' and 'maximalHeight' parameters are not violated)
intersectionLeftResulting horizontal start position of the intersection, with range [0, maximalWidth - 1]
intersectionTopResulting vertical start position of the intersection, with range [0, maximalHeight - 1]
intersectionWidthResulting width of the sub-region, with range [0, maximalWidth]
intersectionHeightResulting height of the sub-region, with range [0, maximalHeight]
Returns
True, if the resulting intersection has an area larger than zero (if the intersection is valid)

◆ box2integer() [3/3]

template<typename T >
bool Ocean::BoxT2< T >::box2integer ( const unsigned int  maximalWidth,
const unsigned int  maximalHeight,
unsigned int &  intersectionLeft,
unsigned int &  intersectionTop,
unsigned int &  intersectionWidth,
unsigned int &  intersectionHeight 
) const

Calculates the intersection of this bounding box (with floating point accuracy) and a second bounding box (with integer accuracy).

The resulting intersection (with integer accuracy) will entirely enclose this floating point bounding box - unless not possible due to the given constraints e.g., 'maximalWidth', 'maximalHeight', ...
If this box is invalid, than the provided integer bounding box will be returned.
Actually, this function returns box2integer(0, 0, maximalWidth - 1, maximalHeight - 1, intersectionLeft, intersectionTop, intersectionWidth, intersectionHeight)

Parameters
maximalWidthMaximal width of the resulting intersection, with range [0, infinity)
maximalHeightMaximal height of the resulting intersection, with range [0, infinity)
intersectionLeftResulting horizontal start position of the intersection, with range [0, maximalWidth - 1]
intersectionTopResulting vertical start position of the intersection, with range [0, maximalHeight - 1]
intersectionWidthResulting width of the sub-region, with range [0, maximalWidth]
intersectionHeightResulting height of the sub-region, with range [0, maximalHeight]
Returns
True, if the resulting intersection has an area larger than zero (if the intersection is valid)

◆ center()

template<typename T >
VectorT2< T > Ocean::BoxT2< T >::center
inline

Returns the center of this box.

Returns
Box center

◆ corner()

template<typename T >
VectorT2< T > Ocean::BoxT2< T >::corner ( const unsigned int  index) const
inline

Returns one of the four corners of this 2D box.

The corners have a counter-clockwise order: (left, top), (left, bottom), (right, bottom), (right top).

Parameters
indexThe index of the corner to return, with range [0, 3]
Returns
The requested corner

◆ height()

template<typename T >
T Ocean::BoxT2< T >::height
inline

Returns the height of the box.

Returns
Vertical box dimension

◆ higher()

template<typename T >
const VectorT2< T > & Ocean::BoxT2< T >::higher
inline

Returns the higher corner of this box.

Returns
Higher corner

◆ intersection()

template<typename T >
BoxT2< T > Ocean::BoxT2< T >::intersection ( const BoxT2< T > &  box) const

Returns the intersection of two boxes.

Parameters
boxSecond box for the intersection
Returns
Box defining the intersection

◆ intersects()

template<typename T >
bool Ocean::BoxT2< T >::intersects ( const BoxT2< T > &  box) const
inline

Returns whether a given box intersects this one.

Parameters
boxThe box to check
Returns
True, if so

◆ isEqual()

template<typename T >
bool Ocean::BoxT2< T >::isEqual ( const BoxT2< T > &  box,
const T  epsilon = NumericT<T>::eps() 
) const
inline

Returns whether two box objects are equal up to an epsilon.

Parameters
boxThe box to compare with, can be invalid
epsilonThe accuracy epsilon, with range [0, infinity)
Returns
True, if so

◆ isInside() [1/3]

template<typename T >
bool Ocean::BoxT2< T >::isInside ( const BoxT2< T > &  box) const
inline

Returns whether a given box is entirely inside this box.

Parameters
boxThe box to check
Returns
True, if so

◆ isInside() [2/3]

template<typename T >
bool Ocean::BoxT2< T >::isInside ( const VectorT2< T > &  point) const
inline

Returns whether a given point is inside the box.

Parameters
pointThe point to check
Returns
True, if so

◆ isInside() [3/3]

template<typename T >
bool Ocean::BoxT2< T >::isInside ( const VectorT2< T > &  point,
const T &  epsilon 
) const
inline

Returns whether a given point is inside the box including a thin epsilon boundary.

Parameters
pointThe point to check
epsilonThe accuracy epsilon, with range [0, infinity)
Returns
True, if so

◆ isPoint()

template<typename T >
bool Ocean::BoxT2< T >::isPoint
inline

Returns whether the box holds exactly one point.

Returns
True, if so

◆ isValid()

template<typename T >
bool Ocean::BoxT2< T >::isValid
inline

Returns whether the box holds valid parameters.

A valid box can have a dimension of zero.

Returns
True, if so

◆ left()

template<typename T >
const T & Ocean::BoxT2< T >::left
inline

Returns the horizontal position of the lower corner of this box.

Returns
Left position

◆ lower()

template<typename T >
const VectorT2< T > & Ocean::BoxT2< T >::lower
inline

Returns the lower corner of this box.

Returns
Lower corner

◆ operator bool()

template<typename T >
Ocean::BoxT2< T >::operator bool
inlineexplicit

Returns whether this box is not a default box.

Returns
True, if so

◆ operator!=()

template<typename T >
bool Ocean::BoxT2< T >::operator!= ( const BoxT2< T > &  right) const
inline

Returns whether two boxes are not identical.

Parameters
rightSecond box object
Returns
True, if so

◆ operator*() [1/2]

template<typename T >
BoxT2< T > Ocean::BoxT2< T >::operator* ( const SquareMatrixT3< T > &  transformation) const
inline

Returns a new bounding box enclosing the transformed corners of this bounding box.

The corners of this bounding box will be transformed with a given 3x3 transformation matrix (a homography).

Parameters
transformationThe transformation to be applied to each bounding box corner, must be valid
Returns
The transformed bounding box

◆ operator*() [2/2]

template<typename T >
BoxT2< T > Ocean::BoxT2< T >::operator* ( const T  factor) const
inline

Returns a new bounding box with scaled dimensions.

The corners of this bounding box will be scaled with a scalar defining new scaled corners for the new bounding box object.
This box needs to be valid.

Parameters
factorFactor that is applied to each bounding box corner, with range (-infinity, infinity)
Returns
Scaled bounding box

◆ operator*=() [1/2]

template<typename T >
BoxT2< T > & Ocean::BoxT2< T >::operator*= ( const SquareMatrixT3< T > &  transformation)
inline

Transforms this bounding box with a transformation matrix.

The corners of the bounding box will be transformed with a given 3x3 transformation matrix (a homography).

Parameters
transformationThe transformation to be applied to each bounding box corner, must be valid
Returns
Reference to this transformed bounding box

◆ operator*=() [2/2]

template<typename T >
BoxT2< T > & Ocean::BoxT2< T >::operator*= ( const T  factor)
inline

Scales this bounding box with a scalar factor.

The corners of this bounding box will be scaled with a scalar.
This box needs to be valid.

Parameters
factorFactor that is applied to each bounding box corner, with range (-infinity, infinity)
Returns
Reference to this scaled bounding box

◆ operator+() [1/4]

template<typename T >
BoxT2< T > Ocean::BoxT2< T >::operator+ ( const BoxT2< T > &  right) const

Returns the combined box given by this one and a second box.

Parameters
rightSecond box
Returns
Combined box

◆ operator+() [2/4]

template<typename T >
BoxT2< T > Ocean::BoxT2< T >::operator+ ( const T  signedBorder) const

Extends this box by adding a border around the box.

Parameters
signedBorderThe size of the signed border to extend the box, a positive border increases the box; a negative border decreases the box, with range (-infinity, infinity)
Returns
The modified box

◆ operator+() [3/4]

template<typename T >
BoxT2< T > Ocean::BoxT2< T >::operator+ ( const TriangleT2< T > &  triangle) const

Extends this box by a triangle (by the three points of the triangle).

Parameters
triangleThe triangle that extends this box
Returns
Extended box

◆ operator+() [4/4]

template<typename T >
BoxT2< T > Ocean::BoxT2< T >::operator+ ( const VectorT2< T > &  point) const

Extends this box by another 2D point and returns the result.

If the 2D point fits into this box the box is untouched, otherwise the dimension of the box will be extended.

Parameters
pointThe point to be added
Returns
Extended box

◆ operator+=() [1/4]

template<typename T >
BoxT2< T > & Ocean::BoxT2< T >::operator+= ( const BoxT2< T > &  right)

Adds a box to this box.

Parameters
rightRight box to add
Returns
Reference to this enlarged box

◆ operator+=() [2/4]

template<typename T >
BoxT2< T > & Ocean::BoxT2< T >::operator+= ( const T  signedBorder)

Extends this box by adding a border around the box.

This box needs to be valid.

Parameters
signedBorderThe size of the signed border to extend the box, a positive border increases the box; a negative border decreases the box, with range (-infinity, infinity)
Returns
Reference to this modified box

◆ operator+=() [3/4]

template<typename T >
BoxT2< T > & Ocean::BoxT2< T >::operator+= ( const TriangleT2< T > &  triangle)

Adds a triangle (the three points of the triangle) to this box.

Parameters
triangleTriangle to add
Returns
Reference to this enlarged box

◆ operator+=() [4/4]

template<typename T >
BoxT2< T > & Ocean::BoxT2< T >::operator+= ( const VectorT2< T > &  point)

Extends this box by another 2D point.

If the 2D point fits into this box the box is untouched, otherwise the dimension of the box will be extended.

Parameters
pointPoint to be added
Returns
Reference to this enlarged box

◆ operator==()

template<typename T >
bool Ocean::BoxT2< T >::operator== ( const BoxT2< T > &  right) const
inline

Returns whether two boxes are identical.

Parameters
rightSecond box object
Returns
True, if so

◆ right()

template<typename T >
const T & Ocean::BoxT2< T >::right
inline

Returns the horizontal position of the higher corner of this box.

Returns
Left position

◆ rounded()

template<typename T >
BoxT2< T > Ocean::BoxT2< T >::rounded
inline

Returns this box with corners rounded to integer locations.

Beware: Ensure that this box is valid before calling the function.

Returns
The box with rounded corners

◆ top()

template<typename T >
const T & Ocean::BoxT2< T >::top
inline

Returns the vertical position of the lower corner of this box.

Returns
Top position

◆ width()

template<typename T >
T Ocean::BoxT2< T >::width
inline

Returns the width of the box.

Returns
Horizontal box dimension

◆ xDimension()

template<typename T >
T Ocean::BoxT2< T >::xDimension
inline

Returns the dimension in x axis, which could e.g.

be the width of this box. Beware: The result is undefined for an invalid box.

Returns
Dimension in x axis

◆ yDimension()

template<typename T >
T Ocean::BoxT2< T >::yDimension
inline

Returns the dimension in x axis, which could e.g.

be the height of this box. Beware: The result is undefined for an invalid box.

Returns
Dimension in x axis

Field Documentation

◆ higher_

template<typename T >
VectorT2<T> Ocean::BoxT2< T >::higher_
protected

Higher box corner.

◆ lower_

template<typename T >
VectorT2<T> Ocean::BoxT2< T >::lower_
protected

Lower box corner.


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