1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 22:08:10 +00:00

LibGfx: Add Path::cubic_bezier_curve_to()

This is pretty unsophisticated as it will simply add a fixed number of
of line segments approximating the curve. Still better than nothing.
This commit is contained in:
Andreas Kling 2021-09-15 19:54:33 +02:00
parent 139fdcc2cf
commit 09d13e437b
2 changed files with 13 additions and 0 deletions

View file

@ -311,4 +311,15 @@ void Path::segmentize_path()
m_bounding_box = Gfx::FloatRect { min_x, min_y, max_x - min_x, max_y - min_y };
}
void Path::cubic_bezier_curve_to(FloatPoint const& c1, FloatPoint const& c2, FloatPoint const& p2)
{
// FIXME: I'm sure there's a faster and more elegant way to do this.
// FIXME: We should divide it into enough segments to stay within some tolerance.
auto p1 = segments().last().point();
for (float t = 0; t <= 1.0f; t += 0.02f) {
auto p = cubic_interpolate(p1, p2, c1, c2, t);
line_to(p);
}
}
}