KanoopCommonQt 2.1.1
Kanoop foundational Qt utility library
Loading...
Searching...
No Matches
Rectangle Class Reference

A 2D rectangle extending QRectF with edge, corner, and geometric query helpers. More...

#include <rectangle.h>

+ Inheritance diagram for Rectangle:
+ Collaboration diagram for Rectangle:

Classes

class  List
 A simple list type for Rectangle objects. More...
 

Public Member Functions

 Rectangle ()
 Default constructor — creates a null rectangle.
 
 Rectangle (const QRectF &other)
 Construct from a QRectF.
 
 Rectangle (const QRect &other)
 Construct from a QRect (integer coordinates).
 
 Rectangle (const QPointF &topLeft, const QSizeF &size)
 Construct from a top-left point and size.
 
 Rectangle (double x, double y, int w, int h)
 Construct from explicit position and dimensions.
 
Point closestCorner (const Point &origin) const
 Return the corner of this rectangle closest to an origin point.
 
Point::List corners () const
 Return all four corners of the rectangle.
 
Line::List edges () const
 Return all four edges of the rectangle as lines.
 
QMap< Geo::Side, LineedgeMap () const
 Return a map from Side to edge Line for all four edges.
 
Line::List verticalLines () const
 Return the two vertical edges.
 
Line::List horizontalLines () const
 Return the two horizontal edges.
 
Line topEdge () const
 Return the top edge as a Line.
 
Line bottomEdge () const
 Return the bottom edge as a Line.
 
Line leftEdge () const
 Return the left edge as a Line.
 
Line rightEdge () const
 Return the right edge as a Line.
 
Line closestEdge (const Point &point)
 Return the edge closest to a given point.
 
bool isPointOnEdge (const Point &point, Line &foundEdge) const
 Test whether a point lies on any edge, outputting the edge.
 
bool isPointOnEdge (const Point &point) const
 Test whether a point lies on any edge.
 
bool containsAnyPoint (const Line &line) const
 Test whether a line's endpoints include any point within this rectangle.
 
Point centerPoint () const
 Return the geometric centre point of the rectangle.
 
Geo::Side closestSideToPoint (const Point &point) const
 Return which side of the rectangle is closest to a point.
 
Rectanglescale (double scale)
 Scale the rectangle dimensions by a factor, keeping the top-left corner fixed.
 
Rectangle scaled (double scale) const
 Return a scaled copy of this rectangle.
 
Rectanglegrow (double amount)
 Grow the rectangle by expanding all edges outward.
 
Rectangle grown (double amount) const
 Return a grown copy of this rectangle.
 
Rectangleshrink (double amount)
 Shrink the rectangle by contracting all edges inward.
 
Rectangle shrunk (double amount) const
 Return a shrunk copy of this rectangle.
 
QString toString () const
 Format this rectangle as a human-readable string.
 

Static Public Member Functions

static Rectangle fromPoints (const Point::List &points)
 Build the bounding rectangle of a list of points.
 
static Rectangle fromPoints (const Point &p1, const Point &p2)
 Build the bounding rectangle of two points.
 
static Rectangle fromCenterLine (const Line &centerLine, double expand)
 Create a rectangle centred on a line with a given width.
 
static Rectangle fromCenterPoint (const Point &centerPoint, double expand)
 Create a rectangle centred on a point with a given half-size.
 
static Rectangle fromString (const QString &value)
 Parse a Rectangle from a string produced by toString().
 

Detailed Description

A 2D rectangle extending QRectF with edge, corner, and geometric query helpers.

Extends QRectF with edge and corner accessors, containment tests, and scale/grow/shrink operations.

Definition at line 15 of file rectangle.h.

Constructor & Destructor Documentation

◆ Rectangle() [1/5]

Rectangle::Rectangle ( )
inline

Default constructor — creates a null rectangle.

Definition at line 19 of file rectangle.h.

◆ Rectangle() [2/5]

Rectangle::Rectangle ( const QRectF &  other)
inline

Construct from a QRectF.

Parameters
otherSource QRectF

Definition at line 22 of file rectangle.h.

◆ Rectangle() [3/5]

Rectangle::Rectangle ( const QRect &  other)
inline

Construct from a QRect (integer coordinates).

Parameters
otherSource QRect

Definition at line 25 of file rectangle.h.

◆ Rectangle() [4/5]

Rectangle::Rectangle ( const QPointF &  topLeft,
const QSizeF &  size 
)
inline

Construct from a top-left point and size.

Parameters
topLeftTop-left corner
sizeDimensions of the rectangle

Definition at line 31 of file rectangle.h.

◆ Rectangle() [5/5]

Rectangle::Rectangle ( double  x,
double  y,
int  w,
int  h 
)
inline

Construct from explicit position and dimensions.

Parameters
xLeft edge X coordinate
yTop edge Y coordinate
wWidth
hHeight

Definition at line 39 of file rectangle.h.

Member Function Documentation

◆ bottomEdge()

Line Rectangle::bottomEdge ( ) const

Return the bottom edge as a Line.

Returns
Bottom edge Line

◆ centerPoint()

Point Rectangle::centerPoint ( ) const

Return the geometric centre point of the rectangle.

Returns
Centre Point

◆ closestCorner()

Point Rectangle::closestCorner ( const Point origin) const

Return the corner of this rectangle closest to an origin point.

Parameters
originReference point
Returns
Closest corner Point

◆ closestEdge()

Line Rectangle::closestEdge ( const Point point)

Return the edge closest to a given point.

Parameters
pointReference point
Returns
Closest edge Line

◆ closestSideToPoint()

Geo::Side Rectangle::closestSideToPoint ( const Point point) const

Return which side of the rectangle is closest to a point.

Parameters
pointReference point
Returns
Closest Geo::Side value

◆ containsAnyPoint()

bool Rectangle::containsAnyPoint ( const Line line) const

Test whether a line's endpoints include any point within this rectangle.

Parameters
lineLine to test
Returns
true if either endpoint is inside the rectangle

◆ corners()

Point::List Rectangle::corners ( ) const

Return all four corners of the rectangle.

Returns
List of the four corner Points (top-left, top-right, bottom-right, bottom-left)

◆ edgeMap()

QMap< Geo::Side, Line > Rectangle::edgeMap ( ) const

Return a map from Side to edge Line for all four edges.

Returns
Map keyed by Geo::Side containing each edge

◆ edges()

Line::List Rectangle::edges ( ) const

Return all four edges of the rectangle as lines.

Returns
Line list of the four edges

◆ fromCenterLine()

static Rectangle Rectangle::fromCenterLine ( const Line centerLine,
double  expand 
)
static

Create a rectangle centred on a line with a given width.

Parameters
centerLineCentre line of the rectangle
expandHalf-width of the rectangle (perpendicular to the line)
Returns
Rectangle enclosing the line

◆ fromCenterPoint()

static Rectangle Rectangle::fromCenterPoint ( const Point centerPoint,
double  expand 
)
static

Create a rectangle centred on a point with a given half-size.

Parameters
centerPointCentre of the rectangle
expandHalf-dimension in each direction
Returns
Square rectangle centred on centerPoint

◆ fromPoints() [1/2]

static Rectangle Rectangle::fromPoints ( const Point p1,
const Point p2 
)
static

Build the bounding rectangle of two points.

Parameters
p1First corner point
p2Opposite corner point
Returns
Rectangle with p1 and p2 as opposite corners

◆ fromPoints() [2/2]

static Rectangle Rectangle::fromPoints ( const Point::List points)
static

Build the bounding rectangle of a list of points.

Parameters
pointsList of points to enclose
Returns
Bounding Rectangle

◆ fromString()

static Rectangle Rectangle::fromString ( const QString &  value)
static

Parse a Rectangle from a string produced by toString().

Parameters
valueString representation
Returns
Parsed Rectangle

◆ grow()

Rectangle & Rectangle::grow ( double  amount)

Grow the rectangle by expanding all edges outward.

Parameters
amountAmount to expand each edge
Returns
Reference to this rectangle

◆ grown()

Rectangle Rectangle::grown ( double  amount) const

Return a grown copy of this rectangle.

Parameters
amountAmount to expand each edge
Returns
New grown Rectangle

◆ horizontalLines()

Line::List Rectangle::horizontalLines ( ) const

Return the two horizontal edges.

Returns
Line list containing the top and bottom edges

◆ isPointOnEdge() [1/2]

bool Rectangle::isPointOnEdge ( const Point point) const

Test whether a point lies on any edge.

Parameters
pointPoint to test
Returns
true if the point is on an edge

◆ isPointOnEdge() [2/2]

bool Rectangle::isPointOnEdge ( const Point point,
Line foundEdge 
) const

Test whether a point lies on any edge, outputting the edge.

Parameters
pointPoint to test
foundEdgeOutput set to the edge containing the point
Returns
true if the point is on an edge

◆ leftEdge()

Line Rectangle::leftEdge ( ) const

Return the left edge as a Line.

Returns
Left edge Line

◆ rightEdge()

Line Rectangle::rightEdge ( ) const

Return the right edge as a Line.

Returns
Right edge Line

◆ scale()

Rectangle & Rectangle::scale ( double  scale)

Scale the rectangle dimensions by a factor, keeping the top-left corner fixed.

Parameters
scaleScale factor
Returns
Reference to this rectangle

◆ scaled()

Rectangle Rectangle::scaled ( double  scale) const

Return a scaled copy of this rectangle.

Parameters
scaleScale factor
Returns
New scaled Rectangle

◆ shrink()

Rectangle & Rectangle::shrink ( double  amount)
inline

Shrink the rectangle by contracting all edges inward.

Parameters
amountAmount to contract each edge
Returns
Reference to this rectangle

Definition at line 197 of file rectangle.h.

◆ shrunk()

Rectangle Rectangle::shrunk ( double  amount) const
inline

Return a shrunk copy of this rectangle.

Parameters
amountAmount to contract each edge
Returns
New shrunk Rectangle

Definition at line 204 of file rectangle.h.

◆ topEdge()

Line Rectangle::topEdge ( ) const

Return the top edge as a Line.

Returns
Top edge Line

◆ toString()

QString Rectangle::toString ( ) const

Format this rectangle as a human-readable string.

Returns
String representation

◆ verticalLines()

Line::List Rectangle::verticalLines ( ) const

Return the two vertical edges.

Returns
Line list containing the left and right edges

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