1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 10:27:36 +00:00

LibWeb: Add CanvasPath arcTo support

Adds initial CanvasPath arcTo support for 2D rendering contexts
https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-arcto
This commit is contained in:
Gabriel Nava 2023-09-17 05:15:21 -07:00 committed by Andreas Kling
parent 7cb80c67d8
commit 9a61041941
5 changed files with 94 additions and 7 deletions

View file

@ -72,11 +72,7 @@ void Path::elliptical_arc_to(FloatPoint point, FloatSize radii, float x_axis_rot
double x_axis_rotation_s;
double x_axis_rotation_c;
AK::sincos(static_cast<double>(x_axis_rotation), x_axis_rotation_s, x_axis_rotation_c);
// Find the last point
FloatPoint last_point { 0, 0 };
if (!m_segments.is_empty())
last_point = m_segments.last()->point();
FloatPoint last_point = this->last_point();
// Step 1 of out-of-range radii correction
if (rx == 0.0 || ry == 0.0) {
@ -160,6 +156,13 @@ void Path::elliptical_arc_to(FloatPoint point, FloatSize radii, float x_axis_rot
theta_1,
theta_delta);
}
FloatPoint Path::last_point()
{
FloatPoint last_point { 0, 0 };
if (!m_segments.is_empty())
last_point = m_segments.last()->point();
return last_point;
}
void Path::close()
{
@ -383,6 +386,14 @@ void Path::add_path(Path const& other)
invalidate_split_lines();
}
void Path::ensure_subpath(FloatPoint point)
{
if (m_need_new_subpath && m_segments.is_empty()) {
move_to(point);
m_need_new_subpath = false;
}
}
template<typename T>
struct RoundTrip {
RoundTrip(ReadonlySpan<T> span)

View file

@ -153,6 +153,8 @@ public:
elliptical_arc_to(point, { radius, radius }, 0, large_arc, sweep);
}
FloatPoint last_point();
void close();
void close_all_subpaths();
@ -192,7 +194,7 @@ public:
Path copy_transformed(AffineTransform const&) const;
void add_path(Path const&);
void ensure_subpath(FloatPoint point);
DeprecatedString to_deprecated_string() const;
Path stroke_to_fill(float thickness) const;
@ -217,6 +219,7 @@ private:
Optional<Vector<FloatLine>> m_split_lines {};
Optional<Gfx::FloatRect> m_bounding_box;
bool m_need_new_subpath = { true };
};
}