I did some playing with this a while back, taking a different approach. I wanted all windows to have the same aspect ratio, and all to be the same size except for (optionally) one "selected" window which would be bigger by some factor. Options were scored by percentage of total space used, deviation from desired aspect ratio, and optionally preferring solutions that magnified the selected window. https://observablehq.com/@tomcburke/rectangle-packing