Prechádzať zdrojové kódy

LibGfx: Use the Midpoint Ellipse Algorithm for filled ellipses

Lucas CHOLLET 2 rokov pred
rodič
commit
2eeaba3f1d
1 zmenil súbory, kde vykonal 8 pridanie a 5 odobranie
  1. 8 5
      Userland/Libraries/LibGfx/Painter.cpp

+ 8 - 5
Userland/Libraries/LibGfx/Painter.cpp

@@ -531,11 +531,14 @@ void Painter::fill_ellipse(IntRect const& a_rect, Color color)
 
 
     VERIFY(m_target->rect().contains(rect));
     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)
 void Painter::draw_ellipse_intersecting(IntRect const& rect, Color color, int thickness)