add: Rect

This commit is contained in:
2022-03-04 00:14:27 +01:00
parent 7fbad9a90d
commit 10c8a1fbf7
3 changed files with 67 additions and 19 deletions

View File

@@ -81,15 +81,7 @@ namespace frame::render
int32_t const r_2 = radius * radius;
Vector pos{0, -radius};
DrawPixel(center + pos, color);
DrawPixel(center + Vector{pos.x, pos.y * -1}, color);
DrawPixel(center + Vector{pos.x * -1, pos.y * -1}, color);
DrawPixel(center + Vector{pos.x * -1, pos.y}, color);
DrawPixel(center + Vector{pos.y, pos.x}, color);
DrawPixel(center + Vector{pos.y, pos.x * -1}, color);
DrawPixel(center + Vector{pos.y * -1, pos.x * -1}, color);
DrawPixel(center + Vector{pos.y * -1, pos.x}, color);
DrawPointsMirrorCircle(center, pos, color);
while(pos.x <= radius / std::sqrt(2.f))
{
@@ -108,16 +100,52 @@ namespace frame::render
E += 2 * pos.x - 2 * pos.y + 5;
}
DrawPixel(center + pos, color);
DrawPixel(center + Vector{pos.x, pos.y * -1}, color);
DrawPixel(center + Vector{pos.x * -1, pos.y * -1}, color);
DrawPixel(center + Vector{pos.x * -1, pos.y}, color);
DrawPixel(center + Vector{pos.y, pos.x}, color);
DrawPixel(center + Vector{pos.y, pos.x * -1}, color);
DrawPixel(center + Vector{pos.y * -1, pos.x * -1}, color);
DrawPixel(center + Vector{pos.y * -1, pos.x}, color);
DrawPointsMirrorCircle(center, pos, color);
}
}
void RenderTarget::DrawRectFilled(Vector const& LeftTop, Vector const& BottomRight, Color color)
{
auto pos = LeftTop;
while(pos.y <= BottomRight.y)
{
while(pos.x <= BottomRight.x)
{
DrawPixel(pos, color);
pos.x++;
}
pos.x = LeftTop.x;
pos.y++;
}
}
void RenderTarget::DrawRect(Vector const& TopLeft, Vector const& BottomRight, uint8_t LineWidth, Color color)
{
auto pos = TopLeft;
auto const lw = LineWidth - 1;
DrawRectFilled(TopLeft, {BottomRight.x, TopLeft.y + lw}, color);
DrawRectFilled({TopLeft.x, BottomRight.y - lw}, BottomRight);
DrawRectFilled({TopLeft.x , TopLeft.y + lw},
{TopLeft.x + lw, BottomRight.y - lw});
DrawRectFilled({BottomRight.x - lw, TopLeft.y + lw},
{BottomRight.x , BottomRight.y - lw});
}
void RenderTarget::DrawPointsMirrorCircle(Vector const& center, Vector const& pos, Color color)
{
DrawPixel(center + pos, color);
DrawPixel(center + Vector{pos.x, pos.y * -1}, color);
DrawPixel(center + Vector{pos.x * -1, pos.y * -1}, color);
DrawPixel(center + Vector{pos.x * -1, pos.y}, color);
DrawPixel(center + Vector{pos.y, pos.x}, color);
DrawPixel(center + Vector{pos.y, pos.x * -1}, color);
DrawPixel(center + Vector{pos.y * -1, pos.x * -1}, color);
DrawPixel(center + Vector{pos.y * -1, pos.x}, color);
}
} // namespace frame::render