Comment by sltkr

Comment by sltkr 7 days ago

3 replies

For the rectangle minimization problem: your problem seems to differ from the one discussed on StackOverflow in that the SO thread discusses partitioning into non-overlapping rectangles, while your Vim project allows overlap.

I wouldn't be surprised if your problem turns out to be much easier to solve optimally.

rav 7 days ago

Actually, from an algorithmic standpoint it's the opposite: the minimum cover problem (where overlap is allowed) is NP-hard whereas the minimum partition problem (where overlap is NOT allowed) has polynomial-time algorithms. "An Algorithm for Covering Polygons with Rectangles" by Franzblau and Kleitman 1984: https://core.ac.uk/download/pdf/82333912.pdf

However, that's of course just an academic tangent - the theoretical results don't necessarily imply that one problem is easier than the other when you're just getting something to work for an afternoon project.

eieio 7 days ago

oh this is a really good point! You're totally right, I had completely skipped over the fact that the rectangles were allowed to overlap. I think I'm probably done with this project / I'm pretty happy with the solution as it stands, but I think you're right that this simplifies the problem considerably. Thanks!

  • vidarh 7 days ago

    I think my attempt would've been to flood fill to create an ordered list of spans, then use roughly the same method as the Lebesque integral, using the data from the flood fill as the function.