Algorithm implementation for filling a polygon