. , , :
have a NY * 2 array of x positions: int x[NY][2]
foreach polygon
clear the array to -1
for each edge line
foreach horizontal raster line iy intersecting the line
generate ix, the x position where the raster intersects the line
if x[iy][0] == -1, set it to ix, else set x[iy][1] to ix
end foreach iy
end foreach edge
foreach iy
fill the pixels between x[iy][0] and x[iy][1] with the polygons label
end foreach iy
end foreach polygon
, , , , , . .
, , , A B A, . - , 2 , - 2 , 4 .
If the polygons are NOT convex, this is a little different. Wherever the edge crosses the raster line, switch all the pixels from there to some randomly chosen X coordinate, such as the left edge of the βscreenβ. When you finish all the edges, only the internal pixels will switch an odd number of times.
source
share