Skip to content

Commit 1b8c0cd

Browse files
Gingehawesomekling
authored andcommitted
LibWeb: Fix rendering of counter-clockwise arcs
1 parent 40db084 commit 1b8c0cd

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Userland/Libraries/LibWeb/HTML/Canvas/CanvasPath.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,18 @@ WebIDL::ExceptionOr<void> CanvasPath::ellipse(float x, float y, float radius_x,
107107
if (radius_y < 0)
108108
return WebIDL::IndexSizeError::create(m_self->realm(), MUST(String::formatted("The minor-axis radius provided ({}) is negative.", radius_y)));
109109

110+
// "If counterclockwise is false and endAngle − startAngle is greater than or equal to 2π,
111+
// or, if counterclockwise is true and startAngle − endAngle is greater than or equal to 2π,
112+
// then the arc is the whole circumference of this ellipse"
113+
// Also draw the full ellipse if making a non-zero whole number of turns.
110114
if (constexpr float tau = M_PI * 2; (!counter_clockwise && (end_angle - start_angle) >= tau)
111-
|| (counter_clockwise && (start_angle - end_angle) >= tau)) {
115+
|| (counter_clockwise && (start_angle - end_angle) >= tau)
116+
|| (start_angle != end_angle && fmodf(start_angle - end_angle, tau) == 0)) {
112117
start_angle = 0;
113118
// FIXME: elliptical_arc_to() incorrectly handles the case where the start/end points are very close.
114119
// So we slightly fudge the numbers here to correct for that.
115120
end_angle = tau * 0.9999f;
121+
counter_clockwise = false;
116122
} else {
117123
start_angle = fmodf(start_angle, tau);
118124
end_angle = fmodf(end_angle, tau);
@@ -154,7 +160,13 @@ WebIDL::ExceptionOr<void> CanvasPath::ellipse(float x, float y, float radius_x,
154160
auto start_point = resolve_point_with_angle(start_angle);
155161
auto end_point = resolve_point_with_angle(end_angle);
156162

157-
auto delta_theta = end_angle - start_angle;
163+
float delta_theta;
164+
if (counter_clockwise) {
165+
delta_theta = start_angle - end_angle;
166+
} else {
167+
delta_theta = end_angle - start_angle;
168+
}
169+
158170
if (delta_theta < 0)
159171
delta_theta += AK::Pi<float> * 2;
160172

0 commit comments

Comments
 (0)