Path

class Path

General-purpose 2D vector path.

A path is a sequence of verbs (move, line, quad, cubic, conic, close) and associated control points. Paths can be filled or stroked.

Path building

Path &moveTo(f32 x, f32 y)
inline Path &moveTo(Point p)
Path &lineTo(f32 x, f32 y)
inline Path &lineTo(Point p)
Path &quadTo(f32 x1, f32 y1, f32 x2, f32 y2)
inline Path &quadTo(Point cp, Point end)
Path &cubicTo(f32 x1, f32 y1, f32 x2, f32 y2, f32 x3, f32 y3)
inline Path &cubicTo(Point c1, Point c2, Point end)
Path &conicTo(f32 x1, f32 y1, f32 x2, f32 y2, f32 weight)
inline Path &conicTo(Point cp, Point end, f32 w)
Path &close()

Relative building commands

Path &rLineTo(f32 dx, f32 dy)
Path &rQuadTo(f32 dx1, f32 dy1, f32 dx2, f32 dy2)
Path &rCubicTo(f32 dx1, f32 dy1, f32 dx2, f32 dy2, f32 dx3, f32 dy3)

Convenience shape builders

Path &addRect(Rect r, PathDirection dir = PathDirection::CW)
Path &addOval(Rect bounds, PathDirection dir = PathDirection::CW)
Path &addCircle(f32 cx, f32 cy, f32 radius, PathDirection dir = PathDirection::CW)
Path &addRoundRect(Rect r, f32 rx, f32 ry, PathDirection dir = PathDirection::CW)
Path &addArc(Rect oval, f32 startAngleDeg, f32 sweepAngleDeg)
Path &addPoly(const Point *pts, i32 count, bool doClose)
Path &addPath(const Path &other)

Accessors

inline const std::vector<Verb> &verbs() const
inline const std::vector<Point> &points() const
inline const std::vector<f32> &conicWeights() const
inline FillRule fillRule() const
inline void setFillRule(FillRule rule)
Rect bounds() const

Return the bounds of the flattened path geometry.

bool contains(Point p) const

Return true if the point is inside the path using the current fill rule.

inline bool contains(f32 x, f32 y) const
bool getDirection(PathDirection *direction) const

Compute the dominant winding direction of the path.

Returns:

False for empty or degenerate paths with no measurable area.

PathDirection direction() const

Return the dominant winding direction, defaulting to CW for degenerate paths.

inline bool isEmpty() const
inline i32 countVerbs() const
inline i32 countPoints() const
bool isConvex() const

Mutation

void reset()
void transform(const Matrix &m)
Path transformed(const Matrix &m) const
void offset(f32 dx, f32 dy)

Public Types

enum class Verb : u8

Values:

enumerator Move

Start a new contour (1 point).

enumerator Line

Line segment (1 point — endpoint).

enumerator Quad

Quadratic Bezier (2 points — control, end).

enumerator Cubic

Cubic Bezier (3 points — control1, control2, end).

enumerator Conic

Conic (rational quadratic, 2 points + weight).

enumerator Close

Close current contour (0 points).

Public Functions

Path() = default
enum class ink::FillRule : u8

Fill rule for path rendering.

Values:

enumerator Winding

Non-zero winding rule.

enumerator EvenOdd

Even-odd (parity) rule.

enum class ink::PathDirection : u8

Winding direction for shape builders.

Values:

enumerator CW

Clockwise.

enumerator CCW

Counter-clockwise.

enum class ink::LineCap : u8

Line cap style for stroked paths.

Values:

enumerator Butt

Flat cap at the endpoint.

enumerator Round

Semicircular cap.

enumerator Square

Extended flat cap (half stroke width).

enum class ink::LineJoin : u8

Line join style for stroked paths.

Values:

enumerator Miter

Sharp corner (extended to miter limit).

enumerator Round

Rounded corner.

enumerator Bevel

Flat corner.

class PathEffect

Abstract path effect that transforms geometry before drawing.

Public Functions

virtual ~PathEffect() = default
virtual Path filterPath(const Path &src) const = 0

Return a transformed copy of the source path.

namespace PathEffects

Factory functions for creating path effects.

Functions

std::shared_ptr<PathEffect> MakeDash(const f32 *intervals, i32 count, f32 phase = 0.0f)

Create a dash effect from alternating on/off intervals.

Parameters:
  • intervals – Positive interval lengths. Odd counts are repeated to form an even pattern.

  • count – Number of interval entries.

  • phase – Initial distance into the pattern.

Returns:

Shared pointer to the effect, or nullptr for invalid intervals.