All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Nimble::RectT< T > Class Template Reference

An axis-aligned rectangle. More...

#include <Nimble/Rect.hpp>

Public Member Functions

area () const
 Returns the surface area of the rectangle.
 
template<typename S >
RectT< S > cast () const
 Cast the rectangle to different basic type.
 
Vector2T< T > center () const
 Returns the center of the rectangle.
 
Vector2T< T > clamp (const Vector2T< T > &) const
 Clamps the argument vector to be inside this rectangle.
 
RectT clamp (const RectT &) const
 Clamps the argument rectangle to be inside this rectangle.
 
void clear ()
 Resets both low and high point to origin.
 
void clear (const Vector2T< T > &v)
 Resets both low and high point to the given argument point.
 
bool contains (T x, T y) const
 Check if the rectangle contains the given point.
 
bool contains (Vector2T< T > v) const
 Check if the rectangle contains the given point.
 
bool contains (const RectT &b) const
 Check if the rectangle contains the given rectangle.
 
const T * data () const
 Returns a pointer to the rectangle corner data. More...
 
T * data ()
 Returns a pointer to the rectangle corner data. More...
 
distance (const RectT &b) const
 Compute the X or Y distance to the other rectangle.
 
distance (const Vector2T< T > &p) const
 Compute the X or Y distance to the given point.
 
void expand (const Vector2T< T > &v)
 Expands this rectangle to include the argument point.
 
void expand (const Vector2T< T > &v, T radius)
 Expands this rectangle to include the argument circle.
 
void expand (const RectT &b)
 Expands this rectangle to include the argument rectangle.
 
RectT fitContent (float aspectRatio) const
 Fit calculate space for pictures or video to be place inside this rectangle. More...
 
void grow (T v)
 Increases the size of the rectangle uniformly. More...
 
void grow (const Frame4f &b)
 Increases the size of the rectangle with the argument frame.
 
height () const
 Returns the height of the rectangle.
 
Vector2T< T > & high ()
 Returns the high X/Y vector.
 
const Vector2T< T > & high () const
 Returns the high X/Y vector.
 
Vector2T< T > highLow () const
 Returns the high x value combined with low y value. More...
 
RectT intersection (const RectT &) const
 Calculates the intersection area of two rectangles.
 
bool intersects (const RectT &) const
 Check if two rectangles intersect.
 
bool isEmpty () const
 Returns true if the rectangle is empty.
 
Vector2T< T > & low ()
 Returns the low X/Y vector.
 
const Vector2T< T > & low () const
 Returns the low X/Y vector.
 
Vector2T< T > lowHigh () const
 Returns the low x value combined with high y value. More...
 
void move (const Vector2T< T > &v)
 Translate the rectangle by v.
 
void moveHighClamped (const Vector2T< T > &v)
 Translate the higher corner by v but make sure it never goes below the lower corner.
 
bool operator!= (const RectT< T > &o) const
 Check if two rects are not equal. More...
 
bool operator== (const RectT< T > &o) const
 Check if two rectangles are identical. More...
 
RectT quarter (int row, int col) const
 Returns one quarter of the rectangle. More...
 
 RectT (const QRectF &qrect)
 Convert QRectF to Nimble::RectT.
 
 RectT (const QRect &qrect)
 Convert QRect to Nimble::RectT.
 
 RectT (const Vector2T< T > &low, const Vector2T< T > &high)
 Constructs a rectangle and initializes it to the given points.
 
 RectT (const Vector2T< T > &low, const SizeT< T > &size)
 Constructs a rectangle and initializes it with the low point and a size.
 
 RectT (T xlow, T ylow, T xhigh, T yhigh)
 Constructs a rectangle and initializes it to the given points.
 
void scale (T v)
 Scales the rectangle uniformly.
 
void scale (const Vector2T< T > &v)
 Scales the rectangle.
 
void set (T lx, T ly, T hx, T hy)
 Sets the corner to given values.
 
void set (const Vector2T< T > &low, const Vector2T< T > &high)
 Sets the corner to given values.
 
void set (const Vector2T< T > &point)
 Sets both corners to the given value.
 
void setHigh (const Vector2T< T > &high)
 Sets the high corner.
 
void setHighX (const T highX)
 Sets the x of the high corner.
 
void setHighY (const T highY)
 Sets the y of the high corner.
 
void setLow (const Vector2T< T > &low)
 Sets the low corner.
 
void setLowX (const T lowX)
 Sets the x of the low corner.
 
void setLowY (const T lowY)
 Sets the y of the low corner.
 
void shrink (T v)
 Uniformly shrinks the rectangle by the specified amount. More...
 
void shrinkRelative (float xs, float ys)
 Scales the rectangle.
 
SizeT< T > size () const
 Returns the size of the rectangle (= high - low)
 
Vector2T< T > span () const
 Returns the vector between low and high corners.
 
Vector2T< T > topCenter () const
 Returns the top-center point of the rectangle. More...
 
QRect toQRect () const
 Convert the rect to QRect. More...
 
QRectF toQRectF () const
 Convert the rect to floating-point precision. More...
 
void transform (const Matrix3T< T > &m)
 Transforms the rectangle with the given matrix.
 
width () const
 Returns the width of the rectangle.
 

Detailed Description

template<typename T>
class Nimble::RectT< T >

An axis-aligned rectangle.

The ractangle is stored as a pair of 2D vectors. The vectors represent the corner points of the rectangle. The "low" vector contains the lower X/Y values while the "high" vector contains the higher X/Y values.

RectT does not really care how the coordinates are orginized (which way is up and so on). Some rare functions assume that one is using normal GUI coordinates (Y increases from top to bottom).

Template Parameters
TTemplate parameter for the vectors used to describe the rectangle.

Member Function Documentation

template<typename T>
const T* Nimble::RectT< T >::data ( ) const
inline

Returns a pointer to the rectangle corner data.

Returns
pointer to the corner data
template<typename T>
T* Nimble::RectT< T >::data ( )
inline

Returns a pointer to the rectangle corner data.

Returns
pointer to the corner data
template<class T >
RectT< T > Nimble::RectT< T >::fitContent ( float  aspectRatio) const
inline

Fit calculate space for pictures or video to be place inside this rectangle.

Parameters
aspectRatioThe aspect ratio of the content.
Returns
Returns the largest possible rectangle that can fit inside this rectangle, with the given aspect ratio. The content is centered both horizontally, and vertically.
template<typename T>
void Nimble::RectT< T >::grow ( v)
inline

Increases the size of the rectangle uniformly.

Parameters
vamount to enlarge
template<typename T>
Vector2T<T> Nimble::RectT< T >::highLow ( ) const
inline

Returns the high x value combined with low y value.

Returns
(high.x, low.y)
template<typename T>
Vector2T<T> Nimble::RectT< T >::lowHigh ( ) const
inline

Returns the low x value combined with high y value.

Returns
(low.x, high.y)
template<typename T>
bool Nimble::RectT< T >::operator!= ( const RectT< T > &  o) const
inline

Check if two rects are not equal.

Parameters
orect to compare
Returns
true if the rectangles are not equal; otherwise false
template<typename T>
bool Nimble::RectT< T >::operator== ( const RectT< T > &  o) const
inline

Check if two rectangles are identical.

Parameters
orect to compare
Returns
true if the rects are equal; otherwise false
template<class T >
RectT< T > Nimble::RectT< T >::quarter ( int  row,
int  col 
) const
inline

Returns one quarter of the rectangle.

Parameters
rowThe row of the quarter (0-1)
colThe column of the quarter (0-1)
Returns
One quarter
template<typename T>
void Nimble::RectT< T >::shrink ( v)
inline

Uniformly shrinks the rectangle by the specified amount.

Parameters
vamount to shrink
template<class T >
Vector2T< T > Nimble::RectT< T >::topCenter ( ) const
inline

Returns the top-center point of the rectangle.

This function assume that we are dealing with normal GUI-coordinates where x increases from left to right, and y increases from top to bottom.

Returns
Location of top-center point
template<typename T>
QRect Nimble::RectT< T >::toQRect ( ) const
inline

Convert the rect to QRect.

Returns
QRect matching the rect
template<typename T>
QRectF Nimble::RectT< T >::toQRectF ( ) const
inline

Convert the rect to floating-point precision.

Returns
converted rect