Restore painter's and reverse painter's algorithm.