1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:57:44 +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)