版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wingrez/article/details/82929448
相关资料来源于网络,侵删歉。
如果文章中存在错误,请下方评论告知我,谢谢!
矩形的区域填充
前提
矩形的顶点坐标均为整数。
我们简单地实现一下,思路是在矩形内逐行逐列点亮每个像素,如图。
typedef struct{
int xmin, xmax;
int ymin, ymax;
}Rectangle;
void FillRectangle(Rectangle *rect, int color){
int x, y;
for(y=rect->ymin;y<=rect->ymax;y++)
for(x=rect->xmin;x<=rect->xmax;x++)
WritePixel(x,y,color);
}
注意到矩形的边缘也点亮了。那么对于下面这种情况,共享边界应该点亮哪种颜色呢?
我们规定,选择左边和上边的,即左闭右开,下闭上开。这个规定同样适用于多边形、直线的交点等。