MIRA
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
RectBase< T, D, Derived > Class Template Reference

The base class for rectangles. More...

#include <geometry/Rect.h>

Public Types

typedef Point< T, D > PointType
 
typedef Size< T, D > SizeType
 
typedef boost::geometry::model::box< PointTypeBoxType
 

Public Member Functions

template<typename Reflector >
void reflect (Reflector &reflector)
 the method to serialize this object More...
 
SizeType size () const
 return the size of the multidimensional rect More...
 
const Derived & operator+= (const PointType &displacement)
 Moves the rect (the minCorner and the maxCorner) by the specified displacement. More...
 
Derived operator+ (const PointType &displacement) const
 Returns a rect that is moved by the specified displacement. More...
 
Constructors
 RectBase ()
 The default constructor, creates an invalid rect with negative extends. More...
 
 RectBase (T x, T y, T z, T width, T height, T depth)
 A constructor for the 3D case. More...
 
 RectBase (T x, T y, T width, T height)
 A constructor for the 2D case. More...
 
 RectBase (const PointType &pos, T width, T height)
 A constructor for the 2D case. More...
 
 RectBase (const PointType &pos, T width, T height, T depth)
 A constructor for the 3D case. More...
 
 RectBase (const PointType &pos, const SizeType &s)
 a constructor to construct the rect, cube or whatever by defining the lower corner and specifying an n-dimensional size. More...
 
 RectBase (const BoxType &box)
 Creating an n-dimensional object from boost::model::box. More...
 
 RectBase (const PointType &p1, const PointType &p2, bool makeValid)
 Create an n-dimensional object from specifying two corners. More...
 
Implicit conversion operators
 operator BoxType () const
 converts to boost::geometry::box More...
 
Comparison Operators
template<typename OtherDerived >
bool operator== (const RectBase< T, D, OtherDerived > &other) const
 
template<typename OtherDerived >
bool operator!= (const RectBase< T, D, OtherDerived > &other) const
 
Intersection tests
template<typename OtherGeometry >
bool contains (const OtherGeometry &otherGeometry) const
 this method checks if a given geometry is enclosed by this box More...
 
template<typename OtherGeometry >
bool intersects (const OtherGeometry &otherGeometry) const
 this method checks for intersections with other geometry More...
 
template<typename OtherGeometry >
bool disjoint (const OtherGeometry &otherGeometry) const
 this method checks for non-intersections with other geometry More...
 
Geometric Operators
Derived operator| (const Derived &other) const
 Returns the bounding rectangle of this rectangle and the given rectangle. More...
 
const Derived & operator|= (const Derived &other)
 Unites this rectangle with the given rectangle. More...
 
const Derived & operator|= (const PointType &p)
 Unites this rectangle with the given point. More...
 
Derived operator & (const Derived &other) const
 Returns the intersection of this rectangle and the given rectangle. More...
 
const Derived & operator &= (const Derived &other)
 Intersects the rectangle with the given rectangle. More...
 

Static Public Member Functions

template<typename U , typename OtherDerived >
static Derived convertFrom (const RectBase< U, D, OtherDerived > &other)
 Converts from a Rect of a different type. More...
 

Public Attributes

PointType minCorner
 
PointType maxCorner
 

Invalid and null Rects

bool isValid () const
 Returns true if this is a valid Rect where the maxCorner's components are not smaller than the minCorner, i.e. More...
 
Derived normalized () const
 Returns the normalized Rect, where the maxCorner and minCorner components are swapped if necessary to produce a valid Rect, where all maxCorner's components are larger than the minCorner. More...
 
bool isNull () const
 Returns true, if all extends (i.e. More...
 
static Derived invalid ()
 Returns an invalid rect with negative extends. More...
 
static Derived null ()
 Returns a null-Rect which extends are null (minCorner and maxCorner) are set to 0. More...
 
static Derived zero ()
 Same as null(). More...
 

Detailed Description

template<typename T, int D, typename Derived>
class mira::RectBase< T, D, Derived >

The base class for rectangles.

Rectangles are also template objects and could be created with different data types (like floats, integer) and different dimensions. In 2D it is the classical rectangle while in 1D it is essentially a line and in 3D it is a box. Again Boost::geometry is used to perform geometrical tasks like intersection, union or enclosure tests. The base class implements a lot of constructors, operators and type converters.

Member Typedef Documentation

◆ PointType

typedef Point<T,D> PointType

◆ SizeType

typedef Size<T,D> SizeType

◆ BoxType

typedef boost::geometry::model::box<PointType> BoxType

Constructor & Destructor Documentation

◆ RectBase() [1/8]

RectBase ( )
inline

The default constructor, creates an invalid rect with negative extends.

◆ RectBase() [2/8]

RectBase ( x,
y,
z,
width,
height,
depth 
)
inline

A constructor for the 3D case.

◆ RectBase() [3/8]

RectBase ( x,
y,
width,
height 
)
inline

A constructor for the 2D case.

◆ RectBase() [4/8]

RectBase ( const PointType pos,
width,
height 
)
inlineexplicit

A constructor for the 2D case.

◆ RectBase() [5/8]

RectBase ( const PointType pos,
width,
height,
depth 
)
inlineexplicit

A constructor for the 3D case.

◆ RectBase() [6/8]

RectBase ( const PointType pos,
const SizeType s 
)
inlineexplicit

a constructor to construct the rect, cube or whatever by defining the lower corner and specifying an n-dimensional size.

◆ RectBase() [7/8]

RectBase ( const BoxType box)
inlineexplicit

Creating an n-dimensional object from boost::model::box.

◆ RectBase() [8/8]

RectBase ( const PointType p1,
const PointType p2,
bool  makeValid 
)
inlineexplicit

Create an n-dimensional object from specifying two corners.

Parameters
[in]p1The lower corner.
[in]p2The upper corner.
[in]makeValidIf true, switch the specific dimension if p1[i] > p2[i].

Member Function Documentation

◆ reflect()

void reflect ( Reflector &  reflector)
inline

the method to serialize this object

◆ operator BoxType()

operator BoxType ( ) const
inline

converts to boost::geometry::box

◆ size()

SizeType size ( ) const
inline

return the size of the multidimensional rect

◆ operator==()

bool operator== ( const RectBase< T, D, OtherDerived > &  other) const
inline

◆ operator!=()

bool operator!= ( const RectBase< T, D, OtherDerived > &  other) const
inline

◆ contains()

bool contains ( const OtherGeometry &  otherGeometry) const
inline

this method checks if a given geometry is enclosed by this box

◆ intersects()

bool intersects ( const OtherGeometry &  otherGeometry) const
inline

this method checks for intersections with other geometry

◆ disjoint()

bool disjoint ( const OtherGeometry &  otherGeometry) const
inline

this method checks for non-intersections with other geometry

◆ isValid()

bool isValid ( ) const
inline

Returns true if this is a valid Rect where the maxCorner's components are not smaller than the minCorner, i.e.

the width and height is not negative. Note: a null-Rect is valid.

◆ invalid()

static Derived invalid ( )
inlinestatic

Returns an invalid rect with negative extends.

Provided for backward compatibility (the default constructor does exactly this).

◆ normalized()

Derived normalized ( ) const
inline

Returns the normalized Rect, where the maxCorner and minCorner components are swapped if necessary to produce a valid Rect, where all maxCorner's components are larger than the minCorner.

◆ isNull()

bool isNull ( ) const
inline

Returns true, if all extends (i.e.

width, height, etc) of this Rect are null.

◆ null()

static Derived null ( )
inlinestatic

Returns a null-Rect which extends are null (minCorner and maxCorner) are set to 0.

◆ zero()

static Derived zero ( )
inlinestatic

Same as null().

Provided for compatibility to Ogre.

◆ operator|()

Derived operator| ( const Derived &  other) const
inline

Returns the bounding rectangle of this rectangle and the given rectangle.

Moreover:
  a | invalid = a
  invalid | b = b
  invalid | invalid = invalid

◆ operator|=() [1/2]

const Derived& operator|= ( const Derived &  other)
inline

Unites this rectangle with the given rectangle.

Moreover:
  a |= invalid, leaves a unchanged
  invalid |= b, previous null becomes b

◆ operator|=() [2/2]

const Derived& operator|= ( const PointType p)
inline

Unites this rectangle with the given point.

Using this operator bounding boxes around single points can be created:

r |= point1;
r |= point2;
r |= point3;
...

Moreover:

invalid |= point

creates an empty rect as bounding box at the position of the single point

Note
This will put the rectangle border at the outermost points. However, contains() returns false for points on the border! Thus, to make all points added to actually be contained in the rect, an extra margin must be added to min/maxCorner.

◆ operator &()

Derived operator& ( const Derived &  other) const
inline

Returns the intersection of this rectangle and the given rectangle.

Returns an invalid rectangle if there is no intersection.

Moreover:
  a & invalid = invalid
  invalid & b = invalid
  invalid & invalid = invalid
  a & b = invalid, only if a and b do not intersect at all.

◆ operator &=()

const Derived& operator&= ( const Derived &  other)
inline

Intersects the rectangle with the given rectangle.

Returns an invalid rectangle if there is no intersection.

◆ convertFrom()

static Derived convertFrom ( const RectBase< U, D, OtherDerived > &  other)
inlinestatic

Converts from a Rect of a different type.

◆ operator+=()

const Derived& operator+= ( const PointType displacement)
inline

Moves the rect (the minCorner and the maxCorner) by the specified displacement.

◆ operator+()

Derived operator+ ( const PointType displacement) const
inline

Returns a rect that is moved by the specified displacement.

Member Data Documentation

◆ minCorner

PointType minCorner

◆ maxCorner

PointType maxCorner

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