Given X number of rectangular windows, what is the best packing on the screen to maximize window size and have no window totally obstructed by another?

First I start with a simple problem and then extrapolate to the general solution:

If we had four windows then the solution is:

Window A: 0, 0, W-1, H-1

Window B: 0, 1, W-1, H

Window C: 1, 0, W, H-1

Window D: 1, 1, W, H

W=Width of screen

H=Height of screen

Solution sets are composed of {X,Y,W,H}.

Seems simple enough. What about five windows?

First I start with a simple problem and then extrapolate to the general solution:

If we had four windows then the solution is:

Window A: 0, 0, W-1, H-1

Window B: 0, 1, W-1, H

Window C: 1, 0, W, H-1

Window D: 1, 1, W, H

W=Width of screen

H=Height of screen

Solution sets are composed of {X,Y,W,H}.

Seems simple enough. What about five windows?

I think that for five, we just add the window

;-- ---------------------\

a equ W-1

b equ H

.if W<H

a equ W

b equ H-1

.endif

{1,2,a,b} or {2,1,a,b}

;-----------------------/

;-- ---------------------\

a equ W-1

b equ H

.if W<H

a equ W

b equ H-1

.endif

{1,2,a,b} or {2,1,a,b}

;-----------------------/

**Ultrano**, that is not correct because there are only four pixels not obstructed by more than one window (the corners). So, at least one other window needs to be moved -- just placing the new window is not sufficient.

Five Windows

Window A: 0, 0, W-1, H-2

Window B: 0, 1, W-1, H-1

Window C: 1, 0, W, H-2

Window D: 1, 1, W, H-1

Window E: 1, 1, W-1. H

Six Windows

Window A: 0, 1, W-1, H-2

Window B: 0, 2, W-1, H-1

Window C: 1, 1, W, H-2

Window D: 1, 2, W, H-1

Window E: 1, 1, W-1. H

Window F: 1, 0, W-1, H-1

Window A: 0, 0, W-1, H-2

Window B: 0, 1, W-1, H-1

Window C: 1, 0, W, H-2

Window D: 1, 1, W, H-1

Window E: 1, 1, W-1. H

Six Windows

Window A: 0, 1, W-1, H-2

Window B: 0, 2, W-1, H-1

Window C: 1, 1, W, H-2

Window D: 1, 2, W, H-1

Window E: 1, 1, W-1. H

Window F: 1, 0, W-1, H-1

Very good

**V Coder**, so now we begin to see a pattern?I don't :o think V Coder's correct. The answer should vary with (W-H).

Assuming W>=H and N (number of windows) is even,

N<=2*(W+1)/(H+1): window extents = (W+1-N) by H

N>2*(W+1)/(H+1): window extents = (W+1-N/2) by (H-1)

Guess it should be so.

N<=2*(W+1)/(H+1): window extents = (W+1-N) by H

N>2*(W+1)/(H+1): window extents = (W+1-N/2) by (H-1)

Guess it should be so.