11#include "tiny_skia/PathGeometry.h"
12#include "tiny_skia/Scalar.h"
25 PathBuilder(std::size_t verbsCapacity, std::size_t pointsCapacity) {
26 verbs_.reserve(verbsCapacity);
27 points_.reserve(pointsCapacity);
31 void reserve(std::size_t additionalVerbs, std::size_t additionalPoints) {
32 verbs_.reserve(verbs_.size() + additionalVerbs);
33 points_.reserve(points_.size() + additionalPoints);
36 [[nodiscard]] std::size_t size()
const {
return verbs_.size(); }
37 [[nodiscard]]
bool empty()
const {
return verbs_.empty(); }
61 [[nodiscard]] std::optional<Point> lastPoint()
const;
62 void setLastPoint(
Point pt);
65 [[nodiscard]]
bool isZeroLengthSincePoint(std::size_t startPtIndex)
const;
68 [[nodiscard]]
static std::optional<Path>
fromCircle(
float cx,
float cy,
float radius) {
91 [[nodiscard]] std::optional<Path>
finish();
94 [[nodiscard]]
const std::vector<Point>& points()
const {
return points_; }
96 [[nodiscard]]
const std::vector<PathVerb>& verbs()
const {
return verbs_; }
99 void injectMoveToIfNeeded();
101 std::vector<PathVerb> verbs_;
102 std::vector<Point> points_;
103 std::size_t lastMoveToIndex_ = 0;
104 bool moveToRequired_ =
true;
105 float conicTolerance_ = 0.25f;
Immutable vector path and related types.
Incrementally builds a Path from move/line/quad/cubic/close operations.
Definition PathBuilder.h:20
PathBuilder & pushPathBuilder(const PathBuilder &other)
Appends all segments from another builder.
static std::optional< Path > fromCircle(float cx, float cy, float radius)
Creates a Path from a circle. Returns nullopt for non-positive radius.
Definition PathBuilder.h:68
PathBuilder(std::size_t verbsCapacity, std::size_t pointsCapacity)
Pre-allocates capacity for verbs and points.
Definition PathBuilder.h:25
void clear()
Resets the builder, discarding all segments.
void setConicTolerance(float tolerance)
Sets the tolerance for conic-to-quadratic conversion (default 0.25).
Definition PathBuilder.h:57
PathBuilder & quadTo(float x1, float y1, float x, float y)
Adds a quadratic Bezier to (x, y) with control point (x1, y1).
PathBuilder & pushOval(const Rect &oval)
Appends a closed oval sub-path inscribed in the given rect.
std::optional< Path > finish()
Builds and returns the immutable Path. Returns nullopt if empty or invalid.
PathBuilder & pushPath(const Path &other)
Appends all segments from another path.
PathBuilder & pushRect(const Rect &rect)
Appends a closed rectangle sub-path.
PathBuilder & quadToPt(Point p1, Point p)
Adds a quadratic Bezier using Point arguments.
PathBuilder & conicTo(float x1, float y1, float x, float y, float weight)
Adds a conic (rational quadratic) segment, approximated as quadratics.
PathBuilder & pushCircle(float x, float y, float r)
Appends a closed circle sub-path.
PathBuilder & cubicTo(float x1, float y1, float x2, float y2, float x, float y)
Adds a cubic Bezier to (x, y) with control points (x1,y1) and (x2,y2).
PathBuilder & close()
Closes the current sub-path.
PathBuilder & conicPointsTo(Point pt1, Point pt2, float weight)
Adds a conic segment using Point arguments.
PathBuilder & lineTo(float x, float y)
Adds a line segment to (x, y).
void reserve(std::size_t additionalVerbs, std::size_t additionalPoints)
Reserves additional capacity.
Definition PathBuilder.h:31
PathBuilder & cubicToPt(Point p1, Point p2, Point p)
Adds a cubic Bezier using Point arguments.
PathBuilder & moveTo(float x, float y)
Begins a new sub-path at (x, y).
Immutable vector path — a sequence of lines, quadratics, and cubics.
Definition Path.h:56
Floating-point rectangle (left, top, right, bottom). All components must be finite,...
Definition Geom.h:119
2D point / vector with float components.
Definition Point.h:14