factorize fill_rectangle()