mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:47:34 +00:00
Tidy up the h/v line drawing loops a bit.
This commit is contained in:
parent
b4bd4f4b29
commit
8d78b0a8df
1 changed files with 6 additions and 2 deletions
|
@ -144,7 +144,9 @@ void Painter::drawLine(const Point& p1, const Point& p2, Color color)
|
|||
return;
|
||||
if (point1.y() > point2.y())
|
||||
swap(point1, point2);
|
||||
for (int y = max(point1.y(), m_clipRect.top()); y <= min(point2.y(), m_clipRect.bottom()); ++y)
|
||||
int min_y = max(point1.y(), m_clipRect.top());
|
||||
int max_y = min(point2.y(), m_clipRect.bottom());
|
||||
for (int y = min_y; y <= max_y; ++y)
|
||||
set_pixel_with_draw_op(m_target->scanline(y)[x], color);
|
||||
return;
|
||||
}
|
||||
|
@ -159,8 +161,10 @@ void Painter::drawLine(const Point& p1, const Point& p2, Color color)
|
|||
return;
|
||||
if (point1.x() > point2.x())
|
||||
swap(point1, point2);
|
||||
int min_x = max(point1.x(), m_clipRect.left());
|
||||
int max_x = min(point2.x(), m_clipRect.right());
|
||||
auto* pixels = m_target->scanline(point1.y());
|
||||
for (int x = max(point1.x(), m_clipRect.left()); x <= min(point2.x(), m_clipRect.right()); ++x)
|
||||
for (int x = min_x; x <= max_x; ++x)
|
||||
set_pixel_with_draw_op(pixels[x], color);
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue