MIRA
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Rect< T, 2 > Class Template Reference

Specialization for 2D. More...

#include <geometry/Rect.h>

Inheritance diagram for Rect< T, 2 >:
Inheritance graph
[legend]

Public Types

typedef RectBase< T, 2, Rect< T, 2 > > Base
 
typedef Base::PointType PointType
 
typedef Base::SizeType SizeType
 
typedef Base::BoxType BoxType
 

Public Member Functions

std::list< Rect< T, 2 > > operator- (const Rect< T, 2 > &other) const
 Intersects the rectangle with the inverse of the given rectangle, i.e. More...
 
void reflect (Reflector &reflector)
 the method to serialize this object More...
 
SizeType size () const
 return the size of the multidimensional rect More...
 
const Rect< T, 2 > & operator+= (const PointType &displacement)
 Moves the rect (the minCorner and the maxCorner) by the specified displacement. More...
 
Rect< T, 2 > operator+ (const PointType &displacement) const
 Returns a rect that is moved by the specified displacement. More...
 
Constructors
 Rect ()
 The default constructor. More...
 
 Rect (T x, T y, T width, T height)
 A constructor to create a 2D rect. More...
 
 Rect (const PointType &pos, T width, T height)
 A constructor to create a 2D rect. More...
 
 Rect (const PointType &pos, const SizeType &s)
 A constructor to create a 2D rect. More...
 
 Rect (const BoxType &box)
 copy constructor from boost::BoxType More...
 
 Rect (const cv::Rect_< T > &rect)
 copy constructor from OpenCV rect More...
 
 Rect (const PointType &p1, const PointType &p2, bool makeValid=true)
 A constructor to create a 2D rect. More...
 
Implicit conversion operators
 operator cv::Rect_< T > () const
 converts to open cv rect More...
 
Access to corner elements and size
T & x0 ()
 Returns the x-coordinate of the lower corner. More...
 
x0 () const
 Returns the x-coordinate of the lower corner. More...
 
T & y0 ()
 Returns the y-coordinate of the lower corner. More...
 
y0 () const
 Returns the y-coordinate of the lower corner. More...
 
T & x1 ()
 Returns the x-coordinate of the upper corner. More...
 
x1 () const
 Returns the x-coordinate of the upper corner. More...
 
T & y1 ()
 Returns the y-coordinate of the upper corner. More...
 
y1 () const
 Returns the y-coordinate of the upper corner. More...
 
width () const
 Returns the width. More...
 
height () const
 Returns the height. More...
 
Implicit conversion operators
 operator BoxType () const
 converts to boost::geometry::box More...
 
Comparison Operators
bool operator== (const RectBase< T, D, OtherDerived > &other) const
 
bool operator!= (const RectBase< T, D, OtherDerived > &other) const
 
Intersection tests
bool contains (const OtherGeometry &otherGeometry) const
 this method checks if a given geometry is enclosed by this box More...
 
bool intersects (const OtherGeometry &otherGeometry) const
 this method checks for intersections with other geometry More...
 
bool disjoint (const OtherGeometry &otherGeometry) const
 this method checks for non-intersections with other geometry More...
 
Geometric Operators
Rect< T, 2 > operator| (const Rect< T, 2 > &other) const
 Returns the bounding rectangle of this rectangle and the given rectangle. More...
 
const Rect< T, 2 > & operator|= (const Rect< T, 2 > &other)
 Unites this rectangle with the given rectangle. More...
 
const Rect< T, 2 > & operator|= (const PointType &p)
 Unites this rectangle with the given point. More...
 
Rect< T, 2 > operator& (const Rect< T, 2 > &other) const
 Returns the intersection of this rectangle and the given rectangle. More...
 
const Rect< T, 2 > & operator&= (const Rect< T, 2 > &other)
 Intersects the rectangle with the given rectangle. More...
 

Static Public Member Functions

static Rect< T, 2 > 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...
 
Rect< T, 2 > 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 Rect< T, 2 > invalid ()
 Returns an invalid rect with negative extends. More...
 
static Rect< T, 2 > null ()
 Returns a null-Rect which extends are null (minCorner and maxCorner) are set to 0. More...
 
static Rect< T, 2 > zero ()
 Same as null(). More...
 

Detailed Description

template<typename T>
class mira::Rect< T, 2 >

Specialization for 2D.

Member Typedef Documentation

◆ Base

typedef RectBase<T,2, Rect<T,2> > Base

◆ PointType

◆ SizeType

◆ BoxType

Constructor & Destructor Documentation

◆ Rect() [1/7]

Rect ( )
inline

The default constructor.

◆ Rect() [2/7]

Rect ( x,
y,
width,
height 
)
inline

A constructor to create a 2D rect.

Parameters
[in]xthe min corner x-coordinate
[in]ythe min corner y-coordinate
[in]widththe rect width
[in]heightthe rect height

◆ Rect() [3/7]

Rect ( const PointType pos,
width,
height 
)
inline

A constructor to create a 2D rect.

Parameters
[in]posthe min corner of the rect
[in]widththe rect width
[in]heightthe rect height

◆ Rect() [4/7]

Rect ( const PointType pos,
const SizeType s 
)
inline

A constructor to create a 2D rect.

Parameters
[in]posthe min corner of the rect
[in]sthe size of the rect

◆ Rect() [5/7]

Rect ( const BoxType box)
inlineexplicit

copy constructor from boost::BoxType

◆ Rect() [6/7]

Rect ( const cv::Rect_< T > &  rect)
inlineexplicit

copy constructor from OpenCV rect

◆ Rect() [7/7]

Rect ( const PointType p1,
const PointType p2,
bool  makeValid = true 
)
inline

A constructor to create a 2D rect.

Parameters
[in]p1the lower corner of the rect
[in]p2the upper corner of the rect

Member Function Documentation

◆ operator cv::Rect_< T >()

operator cv::Rect_< T > ( ) const
inline

converts to open cv rect

◆ x0() [1/2]

T& x0 ( )
inline

Returns the x-coordinate of the lower corner.

◆ x0() [2/2]

T x0 ( ) const
inline

Returns the x-coordinate of the lower corner.

◆ y0() [1/2]

T& y0 ( )
inline

Returns the y-coordinate of the lower corner.

◆ y0() [2/2]

T y0 ( ) const
inline

Returns the y-coordinate of the lower corner.

◆ x1() [1/2]

T& x1 ( )
inline

Returns the x-coordinate of the upper corner.

◆ x1() [2/2]

T x1 ( ) const
inline

Returns the x-coordinate of the upper corner.

◆ y1() [1/2]

T& y1 ( )
inline

Returns the y-coordinate of the upper corner.

◆ y1() [2/2]

T y1 ( ) const
inline

Returns the y-coordinate of the upper corner.

◆ width()

T width ( ) const
inline

Returns the width.

◆ height()

T height ( ) const
inline

Returns the height.

◆ operator-()

std::list<Rect<T,2> > operator- ( const Rect< T, 2 > &  other) const
inline

Intersects the rectangle with the inverse of the given rectangle, i.e.

"subtracts" the given rectangle. Returns empty vector if other contains this or this is empty (isNull() == true). Returns only this rectangle if there is no intersection with other. Returns 1-4 subrectangles of this otherwise (with minimal fragmentation).

◆ reflect()

void reflect ( Reflector &  reflector)
inlineinherited

the method to serialize this object

◆ operator BoxType()

operator BoxType ( ) const
inlineinherited

converts to boost::geometry::box

◆ size()

SizeType size ( ) const
inlineinherited

return the size of the multidimensional rect

◆ operator==()

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

◆ operator!=()

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

◆ contains()

bool contains ( const OtherGeometry &  otherGeometry) const
inlineinherited

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

◆ intersects()

bool intersects ( const OtherGeometry &  otherGeometry) const
inlineinherited

this method checks for intersections with other geometry

◆ disjoint()

bool disjoint ( const OtherGeometry &  otherGeometry) const
inlineinherited

this method checks for non-intersections with other geometry

◆ isValid()

bool isValid ( ) const
inlineinherited

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 Rect< T, 2 > invalid ( )
inlinestaticinherited

Returns an invalid rect with negative extends.

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

◆ normalized()

Rect< T, 2 > normalized ( ) const
inlineinherited

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
inlineinherited

Returns true, if all extends (i.e.

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

◆ null()

static Rect< T, 2 > null ( )
inlinestaticinherited

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

◆ zero()

static Rect< T, 2 > zero ( )
inlinestaticinherited

Same as null().

Provided for compatibility to Ogre.

◆ operator|()

Rect< T, 2 > operator| ( const Rect< T, 2 > &  other) const
inlineinherited

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 Rect< T, 2 > & operator|= ( const Rect< T, 2 > &  other)
inlineinherited

Unites this rectangle with the given rectangle.

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

◆ operator|=() [2/2]

const Rect< T, 2 > & operator|= ( const PointType p)
inlineinherited

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&()

Rect< T, 2 > operator& ( const Rect< T, 2 > &  other) const
inlineinherited

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 Rect< T, 2 > & operator&= ( const Rect< T, 2 > &  other)
inlineinherited

Intersects the rectangle with the given rectangle.

Returns an invalid rectangle if there is no intersection.

◆ convertFrom()

static Rect< T, 2 > convertFrom ( const RectBase< U, D, OtherDerived > &  other)
inlinestaticinherited

Converts from a Rect of a different type.

◆ operator+=()

const Rect< T, 2 > & operator+= ( const PointType displacement)
inlineinherited

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

◆ operator+()

Rect< T, 2 > operator+ ( const PointType displacement) const
inlineinherited

Returns a rect that is moved by the specified displacement.

Member Data Documentation

◆ minCorner

PointType minCorner
inherited

◆ maxCorner

PointType maxCorner
inherited

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