diff --git a/Libraries/LibDraw/Painter.cpp b/Libraries/LibDraw/Painter.cpp index fd46e51ab4..5e966fde83 100644 --- a/Libraries/LibDraw/Painter.cpp +++ b/Libraries/LibDraw/Painter.cpp @@ -140,6 +140,24 @@ void Painter::fill_rect_with_gradient(const Rect& a_rect, Color gradient_start, } } +void Painter::draw_ellipse_intersecting(const Rect& rect, Color color, int thickness) +{ + constexpr int number_samples = 100; // FIXME: dynamically work out the number of samples based upon the rect size + double increment = M_PI / number_samples; + + auto ellipse_x = [&](double theta) -> int { + return (cos(theta) * rect.width() / sqrt(2)) + rect.center().x(); + }; + + auto ellipse_y = [&](double theta) -> int { + return (sin(theta) * rect.height() / sqrt(2)) + rect.center().y(); + }; + + for (float theta = 0; theta < 2 * M_PI; theta += increment) { + draw_line({ ellipse_x(theta), ellipse_y(theta) }, { ellipse_x(theta + increment), ellipse_y(theta + increment) }, color, thickness); + } +} + void Painter::draw_rect(const Rect& a_rect, Color color, bool rough) { Rect rect = a_rect.translated(translation()); diff --git a/Libraries/LibDraw/Painter.h b/Libraries/LibDraw/Painter.h index 575f69373f..ce88595c2d 100644 --- a/Libraries/LibDraw/Painter.h +++ b/Libraries/LibDraw/Painter.h @@ -25,6 +25,7 @@ public: void draw_rect(const Rect&, Color, bool rough = false); void draw_bitmap(const Point&, const CharacterBitmap&, Color = Color()); void draw_bitmap(const Point&, const GlyphBitmap&, Color = Color()); + void draw_ellipse_intersecting(const Rect&, Color, int thickness = 1); void set_pixel(const Point&, Color); void draw_line(const Point&, const Point&, Color, int thickness = 1, bool dotted = false); void draw_scaled_bitmap(const Rect& dst_rect, const GraphicsBitmap&, const Rect& src_rect);