mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
LibGfx: Use the Midpoint Ellipse Algorithm for filled ellipses
This commit is contained in:
parent
d2372464a2
commit
2eeaba3f1d
1 changed files with 8 additions and 5 deletions
|
@ -531,11 +531,14 @@ void Painter::fill_ellipse(IntRect const& a_rect, Color color)
|
|||
|
||||
VERIFY(m_target->rect().contains(rect));
|
||||
|
||||
for (int i = 1; i < a_rect.height(); i++) {
|
||||
float y = a_rect.height() * 0.5 - i;
|
||||
float x = a_rect.width() * AK::sqrt(0.25f - y * y / a_rect.height() / a_rect.height());
|
||||
draw_line({ a_rect.x() + a_rect.width() / 2 - (int)x, a_rect.y() + i }, { a_rect.x() + a_rect.width() / 2 + (int)x - 1, a_rect.y() + i }, color);
|
||||
}
|
||||
auto const center = a_rect.center();
|
||||
|
||||
on_each_ellipse_point(rect, [this, &color, center](IntPoint position) {
|
||||
IntPoint const directions[4] = { { position.x(), position.y() }, { -position.x(), position.y() }, { position.x(), -position.y() }, { -position.x(), -position.y() } };
|
||||
|
||||
draw_line(center + directions[0], center + directions[1], color);
|
||||
draw_line(center + directions[2], center + directions[3], color);
|
||||
});
|
||||
}
|
||||
|
||||
void Painter::draw_ellipse_intersecting(IntRect const& rect, Color color, int thickness)
|
||||
|
|
Loading…
Reference in a new issue