Scan Fill Polygons

Is there an easy way to implement all cases?