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

A 2D polygon defined by an ordered list of vertices. More...

#include <polygon.h>

Public Member Functions

 Polygon ()
 Default constructor — creates an empty (invalid) polygon.
 
void appendPoint (const Point &point)
 Append a vertex to the polygon.
 
double area () const
 Compute the area of the polygon using the shoelace formula.
 
void move (double bearing, double distance)
 Move all vertices by a bearing and distance.
 
void rotate (const Point &centroid, double angle)
 Rotate all vertices around a centroid by an angle.
 
Point centroid () const
 Compute the centroid (geometric centre) of the polygon.
 
bool contains (const Point &point) const
 Test whether a point lies inside the polygon.
 
Line::List lines () const
 Return the edges of the polygon as a list of lines.
 
Rectangle boundingRectangle () const
 Return the bounding rectangle of this polygon.
 
bool isValid () const
 Test whether this polygon has at least 3 vertices.
 

Static Public Member Functions

static Polygon fromLine (const Line &line, int expandBy)
 Construct a rectangle-shaped polygon from a line expanded by a width.
 

Detailed Description

A 2D polygon defined by an ordered list of vertices.

Represents a 2D polygon as an ordered list of Point vertices.

Provides area, centroid, containment, and movement operations.

Definition at line 14 of file polygon.h.

Constructor & Destructor Documentation

◆ Polygon()

Polygon::Polygon ( )
inline

Default constructor — creates an empty (invalid) polygon.

Definition at line 18 of file polygon.h.

Member Function Documentation

◆ appendPoint()

void Polygon::appendPoint ( const Point point)
inline

Append a vertex to the polygon.

Parameters
pointVertex to add

Definition at line 32 of file polygon.h.

◆ area()

double Polygon::area ( ) const

Compute the area of the polygon using the shoelace formula.

Returns
Signed area (positive for counter-clockwise winding)

◆ boundingRectangle()

Rectangle Polygon::boundingRectangle ( ) const

Return the bounding rectangle of this polygon.

Returns
Smallest Rectangle enclosing all vertices

◆ centroid()

Point Polygon::centroid ( ) const

Compute the centroid (geometric centre) of the polygon.

Returns
Centroid Point

◆ contains()

bool Polygon::contains ( const Point point) const

Test whether a point lies inside the polygon.

Parameters
pointPoint to test
Returns
true if the point is inside the polygon boundary

◆ fromLine()

static Polygon Polygon::fromLine ( const Line line,
int  expandBy 
)
static

Construct a rectangle-shaped polygon from a line expanded by a width.

Parameters
lineCentre line of the polygon
expandByHalf-width of the resulting rectangular polygon
Returns
Rectangular Polygon centred on the line

◆ isValid()

bool Polygon::isValid ( ) const
inline

Test whether this polygon has at least 3 vertices.

Returns
true if the polygon has enough vertices to be valid

Definition at line 83 of file polygon.h.

◆ lines()

Line::List Polygon::lines ( ) const

Return the edges of the polygon as a list of lines.

Returns
Line list connecting consecutive vertices

◆ move()

void Polygon::move ( double  bearing,
double  distance 
)

Move all vertices by a bearing and distance.

Parameters
bearingDirection of movement in degrees
distanceDistance to move

◆ rotate()

void Polygon::rotate ( const Point centroid,
double  angle 
)

Rotate all vertices around a centroid by an angle.

Parameters
centroidCentre of rotation
angleRotation angle in degrees

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