Skip to content

Commit daaa058

Browse files
committed
Allow merging a path into another
1 parent 8297ae3 commit daaa058

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

pathfinder/core/path2d.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,20 @@ void Path2d::add_circle(const Vec2F &center, float radius) {
159159
close_path();
160160
}
161161

162+
void Path2d::add_path(const Path2d &other, const Transform2 &transform) {
163+
flush_current_contour();
164+
165+
// We need to get the outline from the other path.
166+
// Since into_outline() might be destructive/mutating, we'll use a const_cast
167+
// or better, just access the internal outline if we are a member.
168+
Outline other_outline = const_cast<Path2d&>(other).into_outline();
169+
other_outline.transform(transform);
170+
171+
for (const auto &contour : other_outline.contours) {
172+
outline.push_contour(contour);
173+
}
174+
}
175+
162176
Outline Path2d::into_outline() {
163177
flush_current_contour();
164178
return outline;

pathfinder/core/path2d.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ class Path2d {
3131
void add_rect_with_corners(const RectF &rect, const RectF &corner_radius);
3232

3333
void add_circle(const Vec2F &center, float radius);
34+
35+
void add_path(const Path2d &other, const Transform2 &transform = Transform2::from_scale({1.0f, 1.0f}));
3436
// -----------------------------------------------
3537

3638
/// Returns the outline.

0 commit comments

Comments
 (0)