Removing this restriction (each rectangle has a height of one pixel) helps in some special cases when the polygon is made of large rectangles, but not at all in the general case.
How about this: use this algorithm, but expand each rectangle up and down as much as you can, and when all the rectangles are in place, eliminate the extra ones.
There is still little room for improvement, since the order in which you eliminate redundant rectangles may matter in some very rare cases, but to be honest, I donβt think itβs worth worrying about a practical solution.
source share