Core 1.0
Rectangles2 Class Reference

Rectangles in the plane. More...

#include <rectangle.h>

Public Member Functions

 Rectangles2 ()
 Empty.
 Rectangles2 (const Vector2 &, const Vector2 &, const double &, const double &)
 Create a rectangle in the xy-plane.
 Rectangles2 (const Box2 &)
 Create a rectangle from a box.
 ~Rectangles2 ()
 Empty.
Vector2 Center () const
 Return the center of the rectangle.
Vector2 Vertex (int) const
 Returns the k-th vertex of the rectangle.
double Width () const
 Return the half width.
double Height () const
 Return the half height.
double Area () const
 Compute the area of the rectangle.
double R (const Vector2 &) const
 Compute the squared distance between a point and the rectangle.
Vector2 Normal (const Vector2 &) const
 Compute the vector distance between the box and a point.
Box2 GetBox () const
 Compute the embedding box.
Rectangles ToRectangles () const
 Convert to a rectangle.
bool Intersect (const Circle2 &) const
 Check the interscetion with a circle.
bool Intersect (const Rectangles2 &) const
 Check the intersection with another rectangle.
void Rotate (const Matrix2 &)
 Rotate the rectangle.
void Translate (const Vector2 &)
 Translate the rectangle.
void Scale (const double &)
 Scale the rectangle.
Rectangles2 Transformed (const Frame2 &) const
 Return a rectangle transformed by a frame.
QPolygonF GetQt () const
 Convert the rectangle into a Qt polygon.
void Draw (QGraphicsScene &, const QPen &=QPen(), const QBrush &=QBrush()) const
 Draw a polygon.

Protected Member Functions

bool Overlap (const Rectangles2 &) const
 Overlapping test for intersection algorithm.

Protected Attributes

Vector2 x = Vector2::X
 Base horizontal vector.
Vector2 c = Vector2::Null
 Center.
double b = 1.0
 Half side lengths.

Static Protected Attributes

static double epsilon = 1.0e-8
 Internal \( \varepsilon \) constant.

Detailed Description

Rectangles in the plane.

Constructor & Destructor Documentation

◆ Rectangles2() [1/2]

Rectangles2::Rectangles2 ( const Vector2 & c,
const Vector2 & x,
const double & a,
const double & b )
explicit

Create a rectangle in the xy-plane.

Parameters
cCenter.
xBase vector.
a,bHalf side lengths.

◆ Rectangles2() [2/2]

Rectangles2::Rectangles2 ( const Box2 & box)
explicit

Create a rectangle from a box.

Parameters
boxThe box.

Member Function Documentation

◆ Draw()

void Rectangles2::Draw ( QGraphicsScene & scene,
const QPen & pen = QPen(),
const QBrush & brush = QBrush() ) const

Draw a polygon.

Parameters
sceneGraphics scene.
penThe pen.
brushThe brush.

◆ Intersect() [1/2]

bool Rectangles2::Intersect ( const Circle2 & circle) const

Check the interscetion with a circle.

Parameters
circleThe circle.

◆ Intersect() [2/2]

bool Rectangles2::Intersect ( const Rectangles2 & rectangle) const

Check the intersection with another rectangle.

Parameters
rectangleThe rectangle.

◆ Normal()

Vector2 Rectangles2::Normal ( const Vector2 & p) const

Compute the vector distance between the box and a point.

The vector goes from the nearest point of the rectangle to the point, and is null inside the rectangle. It is expressed in the frame of the scene.

Parameters
pPoint.

◆ Overlap()

bool Rectangles2::Overlap ( const Rectangles2 & other) const
protected

Overlapping test for intersection algorithm.

Parameters
otherOther rectangle.

◆ R()

double Rectangles2::R ( const Vector2 & p) const

Compute the squared distance between a point and the rectangle.

Parameters
pPoint.

◆ Rotate()

void Rectangles2::Rotate ( const Matrix2 & r)

Rotate the rectangle.

Parameters
rRotation matrix.

◆ Scale()

void Rectangles2::Scale ( const double & s)

Scale the rectangle.

Parameters
sScaling factor.

◆ Transformed()

Rectangles2 Rectangles2::Transformed ( const Frame2 & f) const

Return a rectangle transformed by a frame.

Parameters
fTransformation.

◆ Translate()

void Rectangles2::Translate ( const Vector2 & t)

Translate the rectangle.

Parameters
tTranslation vector.

◆ Vertex()

Vector2 Rectangles2::Vertex ( int k) const
inline

Returns the k-th vertex of the rectangle.

Parameters
kIndex.
See also
Box2::Vertex(int) const