Scanline-fill algorithm in Ruby