diff options
author | Andreas Kling <kling@serenityos.org> | 2021-09-15 19:54:33 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-09-15 20:57:43 +0200 |
commit | 09d13e437badde4437f6b58852fb5623a573f614 (patch) | |
tree | 43c61a7eb8da390e787e641be8d4ce7e1ec934ae /Userland/Libraries | |
parent | 139fdcc2cfb82ff2adb1a4d762ccde5bd59bbac0 (diff) | |
download | serenity-09d13e437badde4437f6b58852fb5623a573f614.zip |
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.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibGfx/Path.cpp | 11 | ||||
-rw-r--r-- | Userland/Libraries/LibGfx/Path.h | 2 |
2 files changed, 13 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGfx/Path.cpp b/Userland/Libraries/LibGfx/Path.cpp index b629c46ce5..fcbb38510c 100644 --- a/Userland/Libraries/LibGfx/Path.cpp +++ b/Userland/Libraries/LibGfx/Path.cpp @@ -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); + } +} + } diff --git a/Userland/Libraries/LibGfx/Path.h b/Userland/Libraries/LibGfx/Path.h index 5820306dff..f5f3988a83 100644 --- a/Userland/Libraries/LibGfx/Path.h +++ b/Userland/Libraries/LibGfx/Path.h @@ -134,6 +134,8 @@ public: invalidate_split_lines(); } + void cubic_bezier_curve_to(FloatPoint const& c1, FloatPoint const& c2, FloatPoint const& p2); + void elliptical_arc_to(const FloatPoint& point, const FloatPoint& radii, double x_axis_rotation, bool large_arc, bool sweep); void arc_to(const FloatPoint& point, float radius, bool large_arc, bool sweep) { |