80 return width == o.width &&
cap == o.cap &&
join == o.join &&
90 enum class Verb : uint8_t {
128 bool operator==(const
Path& o) const;
129 bool operator!=(const
Path& o)
const {
return !(*
this == o); }
135 Path&
cubic_to(
float c1x,
float c1y,
float c2x,
float c2y,
float x,
float y);
143 Path&
arc_to(
float x1,
float y1,
float x2,
float y2,
float radius);
161 float top_left,
float top_right,
162 float bottom_right,
float bottom_left);
173 float start_angle,
float sweep_angle);
177 float start_angle,
float sweep_angle);
210 bool preserve_proportions)
const;
214 bool preserve_proportions);
217 bool is_empty()
const {
return !data_ || data_->verbs.empty(); }
220 size_t verb_count()
const {
return data_ ? data_->verbs.size() : 0; }
258 : path_(
path), verb_(verb_index), point_(point_index) {}
266 const Path* path_ =
nullptr;
277 template <
typename Sink>
310 std::vector<FlatSubpath>
flatten(
float tolerance = 0.25f)
const;
328 std::vector<Verb> verbs;
329 std::vector<Point2D> points;
333 Data& mutable_data();
340 void append_arc_cubics(
float cx,
float cy,
float rx,
float ry,
341 float start_angle,
float sweep_angle,
350 void append_svg_arc(
Point2D from,
float rx,
float ry,
float x_axis_rotation_deg,
351 bool large_arc,
bool sweep,
Point2D to);
353 std::shared_ptr<Data> data_;
358 mutable bool bounds_valid_ =
false;
359 mutable Rect2D bounds_cache_{};
Forward iterator over the verbs.
Definition path.hpp:254
Element operator*() const
Iterator(const Path *path, size_t verb_index, size_t point_index)
Definition path.hpp:257
bool operator!=(const Iterator &o) const
Definition path.hpp:263
bool operator==(const Iterator &o) const
Definition path.hpp:262
Path & move_to(float x, float y)
Rect2D control_bounds() const
Cheap conservative bounds: the AABB of the control points.
Path(const Path &)=default
void scale_to_fit(float x, float y, float w, float h, bool preserve_proportions)
apply_transform(transform_to_fit(...)).
Iterator end() const
Definition path.hpp:272
Path & add_path(const Path &other, const AffineTransform &transform=AffineTransform::identity())
Append other, optionally transformed.
Path & add_circle(float cx, float cy, float radius)
Definition path.hpp:165
Path & add_rounded_rect(float x, float y, float w, float h, float top_left, float top_right, float bottom_right, float bottom_left)
Per-corner radii, clockwise from the top-left.
std::string to_svg_string() const
Emit a standard SVG d string using absolute commands (M/L/Q/C/Z).
Path & quad_to(float cx, float cy, float x, float y)
Path & line_to(float x, float y)
Path & add_ellipse(float cx, float cy, float rx, float ry)
void replay(Sink &sink) const
Replay this path into any sink that exposes the Canvas path-builder verbs.
Definition path.hpp:278
static Path from_svg_string(const std::string &d)
Parse an SVG path d string.
std::optional< Point2D > current_point() const
The last point of the path, or nullopt if there is no current point.
Path & arc_to(float x1, float y1, float x2, float y2, float radius)
Tangent arc, matching Canvas2D ctx.arcTo(x1, y1, x2, y2, radius): the arc of radius tangent to both t...
void apply_transform(const AffineTransform &t)
Transform every point in place.
std::vector< FlatSubpath > flatten(float tolerance=0.25f) const
AffineTransform transform_to_fit(float x, float y, float w, float h, bool preserve_proportions) const
The transform that would scale this path to fit (x, y, w, h).
Path & add_polygon(const Point2D *points, size_t count)
Closed polygon through count points. Fewer than 2 points draws nothing.
Path & add_arc(float cx, float cy, float rx, float ry, float start_angle, float sweep_angle)
Arc as its own subpath (an implicit move_to to the arc's start).
Path & add_rounded_rect(float x, float y, float w, float h, float radius)
Uniform corner radius, clamped to half the shorter side.
Path & cubic_to(float c1x, float c1y, float c2x, float c2y, float x, float y)
Path & operator=(const Path &)=default
bool contains(Point2D p, FillRule rule=FillRule::nonzero) const
Is p inside the path under rule?
Path transformed(const AffineTransform &t) const
A transformed copy; leaves this path alone.
friend class Iterator
Definition path.hpp:361
Iterator begin() const
Definition path.hpp:271
Path & add_rect(const Rect2D &r)
Definition path.hpp:152
size_t verb_count() const
Number of verbs.
Definition path.hpp:220
static constexpr int points_for(Verb v)
How many points a verb consumes.
Definition path.hpp:99
bool contains(float x, float y, FillRule rule=FillRule::nonzero) const
Definition path.hpp:243
Path & add_rect(float x, float y, float w, float h)
Verb
The closed verb set. Arcs and ellipses flatten to cubic at build time.
Definition path.hpp:90
@ move
1 point: the new subpath's start
Definition path.hpp:91
@ line
1 point: the endpoint
Definition path.hpp:92
@ close
0 points: close the current subpath
Definition path.hpp:95
@ cubic
3 points: control 1, control 2, endpoint
Definition path.hpp:94
@ quad
2 points: control, endpoint
Definition path.hpp:93
Rect2D bounds() const
TIGHT bounds: the true visual bounding box, computed from each curve's extrema (the roots of its deri...
void clear()
Drop every verb. Keeps any allocated capacity for reuse.
Path & add_pie(float cx, float cy, float rx, float ry, float start_angle, float sweep_angle)
A pie slice / wedge: center → arc → back to center, closed.
bool is_empty() const
Definition path.hpp:217
Path(Path &&) noexcept=default
Definition affine_transform.hpp:24
@ count
sentinel: number of real capabilities (keep LAST)
Definition canvas_capability.hpp:38
FillRule
Winding rule used to decide what counts as "inside" a path.
Definition path.hpp:54
@ nonzero
Definition path.hpp:54
@ evenodd
Definition path.hpp:54
LineJoin
Join applied where two segments meet when stroking.
Definition path.hpp:60
@ miter
Definition path.hpp:60
@ bevel
Definition path.hpp:60
@ path
Definition scene_node.hpp:93
LineCap
Line cap applied to the ends of open subpaths when stroking.
Definition path.hpp:57
@ square
Definition path.hpp:57
@ butt
Definition path.hpp:57
@ round
Definition path.hpp:57
One step of an iteration over the path.
Definition path.hpp:111
int count
Definition path.hpp:114
const Point2D * points
count points, or null for close
Definition path.hpp:113
Verb verb
Definition path.hpp:112
Flatten every curve to line segments, within tolerance user units of the true curve.
Definition path.hpp:306
bool closed
Definition path.hpp:308
std::vector< Point2D > points
Definition path.hpp:307
A 2D point.
Definition affine_transform.hpp:37
float x
Definition affine_transform.hpp:38
float y
Definition affine_transform.hpp:39
Axis-aligned rectangle in canvas coordinates.
Definition rectangle_list.hpp:28
Everything needed to stroke a path, as one value.
Definition path.hpp:67
LineCap cap
Definition path.hpp:69
float miter_limit
Definition path.hpp:71
float dash_phase
Definition path.hpp:77
float width
Definition path.hpp:68
bool operator!=(const StrokeStyle &o) const
Definition path.hpp:84
bool operator==(const StrokeStyle &o) const
Definition path.hpp:79
std::vector< float > dash
Dash pattern: alternating on/off lengths in user units.
Definition path.hpp:76
LineJoin join
Definition path.hpp:70