Despite the way this question sounds, this is not a homework or exam
question. I'm working on some research on the side on maximizing the
use of certain UI areas and thought it would be easier to offload this
Assume you have X and Y, which represent a rectangular space starting
from 0,0. This represents a rectanglular piece of "real estate" you
see on the screen.
You are now given a list of values, each representing a percentage of
"ownership" of that rectangular space (eg. 50%, 7%, 13% ...always
whole percentages). Each value is tied to an image/graphic that we
want to put into this rectangular space. The graphic is always
*square* in shape.
You can assume that each graphic can be scaled larger or smaller as
much as needed. There is another input that designates the smallest
possible graphic we allow, therefore avoiding the problem of
infinitessimally smaller squares. Example is 1%, which means that no
graphic will ever be smaller than 1% of the rectangular space.
I am okay with replicating the square graphic as many times as needed
in the given space, but want to minimize this as much as possible.
That is, I want to use a graphic as few times as possible, by scaling
the original square graphic larger to fill a square space and
repeating this until the overall space used equals its corresponding
percentage that was specified originally.
The output should be an array for each graphic. In each array will be
a list of the x,y coordinates of the top left and bottom right of
every specific graphic to maximally fill it's percentage of real
estate. (Using the least number of graphics possible, per graphic)
An example. Suppose the overall rectangular space is square. (0,0)
and (100,100). We have three owners
Alpha owns 50% space
Beta owns 25%
Charlie owns 25%
Alpha would be
(0,50), (50, 100)
Beta would be
(50,0), (100, 50)
Charlie would be
(50,50), (100, 100)
This is an overly simple example, there will be cases where the area
for each owner will not be square, so you need to split it into
smaller and smaller squares to cover the screen real estate.
For an answer, we would like it preferably in PHP but will accept