mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-07 16:49:54 +00:00
LibWeb: Fix rendering of counter-clockwise arcs
This commit is contained in:
parent
40db0848d5
commit
1b8c0cd368
Notes:
github-actions[bot]
2024-09-07 09:38:48 +00:00
Author: https://github.com/Gingeh
Commit: 1b8c0cd368
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1308
1 changed files with 14 additions and 2 deletions
|
@ -107,12 +107,18 @@ WebIDL::ExceptionOr<void> CanvasPath::ellipse(float x, float y, float radius_x,
|
||||||
if (radius_y < 0)
|
if (radius_y < 0)
|
||||||
return WebIDL::IndexSizeError::create(m_self->realm(), MUST(String::formatted("The minor-axis radius provided ({}) is negative.", radius_y)));
|
return WebIDL::IndexSizeError::create(m_self->realm(), MUST(String::formatted("The minor-axis radius provided ({}) is negative.", radius_y)));
|
||||||
|
|
||||||
|
// "If counterclockwise is false and endAngle − startAngle is greater than or equal to 2π,
|
||||||
|
// or, if counterclockwise is true and startAngle − endAngle is greater than or equal to 2π,
|
||||||
|
// then the arc is the whole circumference of this ellipse"
|
||||||
|
// Also draw the full ellipse if making a non-zero whole number of turns.
|
||||||
if (constexpr float tau = M_PI * 2; (!counter_clockwise && (end_angle - start_angle) >= tau)
|
if (constexpr float tau = M_PI * 2; (!counter_clockwise && (end_angle - start_angle) >= tau)
|
||||||
|| (counter_clockwise && (start_angle - end_angle) >= tau)) {
|
|| (counter_clockwise && (start_angle - end_angle) >= tau)
|
||||||
|
|| (start_angle != end_angle && fmodf(start_angle - end_angle, tau) == 0)) {
|
||||||
start_angle = 0;
|
start_angle = 0;
|
||||||
// FIXME: elliptical_arc_to() incorrectly handles the case where the start/end points are very close.
|
// FIXME: elliptical_arc_to() incorrectly handles the case where the start/end points are very close.
|
||||||
// So we slightly fudge the numbers here to correct for that.
|
// So we slightly fudge the numbers here to correct for that.
|
||||||
end_angle = tau * 0.9999f;
|
end_angle = tau * 0.9999f;
|
||||||
|
counter_clockwise = false;
|
||||||
} else {
|
} else {
|
||||||
start_angle = fmodf(start_angle, tau);
|
start_angle = fmodf(start_angle, tau);
|
||||||
end_angle = fmodf(end_angle, tau);
|
end_angle = fmodf(end_angle, tau);
|
||||||
|
@ -154,7 +160,13 @@ WebIDL::ExceptionOr<void> CanvasPath::ellipse(float x, float y, float radius_x,
|
||||||
auto start_point = resolve_point_with_angle(start_angle);
|
auto start_point = resolve_point_with_angle(start_angle);
|
||||||
auto end_point = resolve_point_with_angle(end_angle);
|
auto end_point = resolve_point_with_angle(end_angle);
|
||||||
|
|
||||||
auto delta_theta = end_angle - start_angle;
|
float delta_theta;
|
||||||
|
if (counter_clockwise) {
|
||||||
|
delta_theta = start_angle - end_angle;
|
||||||
|
} else {
|
||||||
|
delta_theta = end_angle - start_angle;
|
||||||
|
}
|
||||||
|
|
||||||
if (delta_theta < 0)
|
if (delta_theta < 0)
|
||||||
delta_theta += AK::Pi<float> * 2;
|
delta_theta += AK::Pi<float> * 2;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue