Path Class Reference

#include <Pt/Gfx/Path.h>

Vector path for drawing outlines and filled shapes. More...

Public Types

enum  ElementType
 Identifies the command stored in a path element.
 

Public Member Functions

 Path ()
 Constructs an empty path.
 
 Path (const Path &other)
 Copies another path.
 
Pathoperator= (const Path &other)
 Replaces the path contents.
 
 ~Path ()
 Destroys the path.
 
std::size_t size () const
 Returns the number of path elements.
 
bool isEmpty () const
 Returns true if the path has no elements.
 
Iterator begin () const
 Returns an iterator to the first element.
 
Iterator end () const
 Returns an iterator past the last element.
 
void clear ()
 Removes all path elements.
 
RectF boundingRect () const
 Returns the bounding rectangle of the path.
 
bool contains (const PointF &point, FillRule rule=FillRule::NonZero) const
 Returns true if the point lies inside the filled area of the path. More...
 
bool contains (const RectF &rect, FillRule rule=FillRule::NonZero) const
 Returns true if the rectangle lies entirely inside the filled area. More...
 
bool intersects (const RectF &rect, FillRule rule=FillRule::NonZero) const
 Returns true if the filled area of the path overlaps rect. More...
 
const PointFcurrentPosition () const
 Returns the current drawing position.
 
void moveTo (const PointF &p)
 Starts a new subpath at the given point.
 
void lineTo (const PointF &p)
 Adds a straight line to the given point.
 
void quadTo (const PointF &cp, const PointF &to)
 Adds a quadratic Bezier segment.
 
void cubicTo (const PointF &cp1, const PointF &cp2, const PointF &to)
 Adds a cubic Bezier segment.
 
void arcTo (const PointF &topLeft, const SizeF &size, double degBegin, double degEnd)
 Adds an arc segment to the current subpath. More...
 
void close ()
 Closes the current subpath.
 
void addPath (const Path &p)
 Appends all elements of p to this path.
 
void addRect (const RectF &rect)
 Adds a rectangle as a new subpath.
 
void addRoundedRect (const RectF &rect, double radius)
 Adds a rounded rectangle as a new subpath.
 
void addRoundedRect (const RectF &rect, double rx, double ry)
 Adds a rounded rectangle with elliptical corners as a new subpath. More...
 
void addEllipse (const PointF &topLeft, const SizeF &size)
 Adds an ellipse as a new subpath.
 
void addArc (const PointF &topLeft, const SizeF &size, double degBegin, double degEnd)
 Adds an arc as a new subpath. More...
 
void addPie (const PointF &topLeft, const SizeF &size, double degBegin, double degEnd)
 Adds a pie segment as a new subpath.
 
void addChord (const PointF &topLeft, const SizeF &size, double degBegin, double degEnd)
 Adds a chord as a new subpath.
 
void addPolyline (const PointF *points, std::size_t count)
 Adds a polyline as a new subpath.
 
void addPolygon (const PointF *points, std::size_t count)
 Adds a polygon as a new closed subpath.
 
void transform (const Transform &transform)
 Applies a transform to all path coordinates.
 
Path toTransformed (const Transform &transform) const
 Returns a copy of the path with the transform applied.
 
Iterator getPolygon (Iterator it, Polygon &polygon, float tolerance=0.25f) const
 Flattens one subpath into polygon starting at it. More...
 

Detailed Description

Path stores a sequence of drawing commands such as moves, lines and curves. Painters can stroke or fill the current path directly, while helper functions make it easy to append rectangles, ellipses and arc segments.

Member Function Documentation

◆ contains() [1/2]

bool contains ( const PointF point,
FillRule  rule = FillRule::NonZero 
) const

The test uses a horizontal ray cast from the point. The rule parameter controls how overlapping subpaths are handled. A point exactly on an upward-crossing edge is considered outside.

◆ contains() [2/2]

bool contains ( const RectF rect,
FillRule  rule = FillRule::NonZero 
) const

Every point of rect must be covered by the filled area of the path. Returns false if any path segment crosses a rectangle edge or any corner of rect is outside the filled area.

◆ intersects()

bool intersects ( const RectF rect,
FillRule  rule = FillRule::NonZero 
) const

Returns true if any part of the filled path area shares at least one point with the interior of rect. The test covers three cases: a corner of rect lies inside the path, a path segment crosses a rect edge, or the entire path lies inside rect.

◆ arcTo()

void arcTo ( const PointF topLeft,
const SizeF size,
double  degBegin,
double  degEnd 
)

The arc is drawn inside the ellipse bounded by topLeft and size. Angles are measured clockwise from the positive x-axis. A positive sweep (degEnd > degBegin) is clockwise; a negative sweep is counter-clockwise. If the path is empty a MoveTo is added, otherwise a LineTo.

◆ addRoundedRect()

void addRoundedRect ( const RectF rect,
double  rx,
double  ry 
)

rx is the horizontal corner radius, ry the vertical corner radius.

◆ addArc()

void addArc ( const PointF topLeft,
const SizeF size,
double  degBegin,
double  degEnd 
)

Starts a new subpath at the arc start point. Angle and sweep-direction semantics are identical to arcTo().

◆ getPolygon()

Iterator getPolygon ( Iterator  it,
Polygon &  polygon,
float  tolerance = 0.25f 
) const

Skips a leading MoveTo, then flattens elements into polygon until a Close command, the next MoveTo, or end() is reached. No closing point is appended. The caller must clear polygon before each call.

Returns
iterator to the start of the next subpath, or end().