All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Nimble::Rectangle Class Reference

A rectangle is defined by origin (O), two unit-length axis vectors

(U, V), and two non-negative extents (e1, e2). More...

#include <Nimble/Rectangle.hpp>

Public Member Functions

Nimble::Vector2f axis0 () const
 Returns the first axis of the rectangle.
 
Nimble::Vector2f axis1 () const
 Returns the second axis of the rectangle.
 
Nimble::Rect boundingBox () const
 Get the axis-aligned bounding box of this rectangle. More...
 
Nimble::Vector2f center () const
 Return the center point of the rectangle.
 
void computeCorners (std::array< Nimble::Vector2f, 4 > &corners) const
 Computes the corner vertices of the rectangle and appends the to the given array. More...
 
float extent0 () const
 Returns the extent along axis0.
 
float extent1 () const
 Returns the extent along axis1.
 
bool intersects (const Rectangle &r) const
 Test if two rectangles intersect. More...
 
bool isInside (Nimble::Vector2f p) const
 Test if a point is inside the rectangle. More...
 
bool isInside (const Nimble::Rectangle &r) const
 Test if an another rectangle is fully inside this rectangle. More...
 
 Rectangle ()
 Constructs a new rectangle. Does not initialize values.
 
 Rectangle (Nimble::Vector2f origin, Nimble::Vector2f a0, float e0, Nimble::Vector2f a1, float e1)
 Constructs a new rectangle. More...
 
 Rectangle (Nimble::SizeF size, const Nimble::Matrix3 &m)
 Constructs a new rectangle. More...
 
 Rectangle (const Nimble::Rectf &rect)
 Construct a copy of the given rectangle. More...
 
Nimble::SizeF size () const
 Return the size of the rectangle.
 
void transform (const Nimble::Matrix3 &m)
 Transforms the rectangle with the given matrix. More...
 

Static Public Member Functions

static Nimble::Rectangle merge (const Nimble::Rectangle &a, const Nimble::Rectangle &b)
 Returns a rectangle that contains the two given rectangles. More...
 

Detailed Description

A rectangle is defined by origin (O), two unit-length axis vectors

(U, V), and two non-negative extents (e1, e2).

Point P=O+x*U+y*V is inside or on the rectangle whenever |x|<=e1 and |y|<=e2.

Constructor & Destructor Documentation

Nimble::Rectangle::Rectangle ( Nimble::Vector2f  origin,
Nimble::Vector2f  a0,
float  e0,
Nimble::Vector2f  a1,
float  e1 
)

Constructs a new rectangle.

Parameters
origincenter of the box
a0unit-length axis vector
e0non-negative extent along a0
a1unit-length axis vector
e1non-negative extent along a1
Nimble::Rectangle::Rectangle ( Nimble::SizeF  size,
const Nimble::Matrix3 m 
)

Constructs a new rectangle.

Parameters
sizesize (width & height) of the rectangle
mtransformation matrix defining the center of the rectangle
Nimble::Rectangle::Rectangle ( const Nimble::Rectf rect)

Construct a copy of the given rectangle.

Parameters
rectrectangle to copy

Member Function Documentation

Nimble::Rect Nimble::Rectangle::boundingBox ( ) const

Get the axis-aligned bounding box of this rectangle.

Returns
axis-aligned bounding box
void Nimble::Rectangle::computeCorners ( std::array< Nimble::Vector2f, 4 > &  corners) const

Computes the corner vertices of the rectangle and appends the to the given array.

Parameters
cornersvector of points where the four corners are appended
bool Nimble::Rectangle::intersects ( const Rectangle r) const

Test if two rectangles intersect.

Parameters
rrectangle to test
Returns
true if the rectangles intersect
bool Nimble::Rectangle::isInside ( Nimble::Vector2f  p) const

Test if a point is inside the rectangle.

Parameters
ppoint to test
Returns
true if p is inside or on the rectangle
bool Nimble::Rectangle::isInside ( const Nimble::Rectangle r) const

Test if an another rectangle is fully inside this rectangle.

Parameters
rrectangle to test
Returns
true if r is fully inside or on the rectangle
static Nimble::Rectangle Nimble::Rectangle::merge ( const Nimble::Rectangle a,
const Nimble::Rectangle b 
)
static

Returns a rectangle that contains the two given rectangles.

The result is not guaranteed to be the smallest rectangle containing the input rectangles.

Parameters
arectangle to merge
brectangle to merge
Returns
Bouding rectangle of the two input rectangles
void Nimble::Rectangle::transform ( const Nimble::Matrix3 m)

Transforms the rectangle with the given matrix.

If the matrix is not orthogonal, the results are undefined.

Parameters
mtransformation matrix