Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've managed to come up with a 'relatively' optimal solution. Partially based on Zac's pseudocode answer.</p> <pre><code> //total number of tiles var tile_count : Number = numberOfSlides; //height of rectangle var b : Number = unscaledHeight; //width of rectanlge var a : Number = unscaledWidth; //divide the area but the number of tiles to get the max area a tile could cover //this optimal size for a tile will more often than not make the tiles overlap, but //a tile can never be bigger than this size var maxSize : Number = Math.sqrt((b * a) / tile_count); //find the number of whole tiles that can fit into the height var numberOfPossibleWholeTilesH : Number = Math.floor(b / maxSize); //find the number of whole tiles that can fit into the width var numberOfPossibleWholeTilesW : Number = Math.floor(a / maxSize); //works out how many whole tiles this configuration can hold var total : Number = numberOfPossibleWholeTilesH * numberOfPossibleWholeTilesW; //if the number of number of whole tiles that the max size tile ends up with is less than the require number of //tiles, make the maxSize smaller and recaluate while(total &lt; tile_count){ maxSize--; numberOfPossibleWholeTilesH = Math.floor(b / maxSize); numberOfPossibleWholeTilesW = Math.floor(a / maxSize); total = numberOfPossibleWholeTilesH * numberOfPossibleWholeTilesW; } return maxSize; </code></pre> <p>What this does is to work out the total area of the rectanlge, then divide it by the required number of tiles. As each tile is a square I can SQRT this so that I get the max size of the optimal tile.</p> <p>With this optimal size I then check to see how many WHOLE tiles I can fit into the width &amp; height. Multiply these together and if it is less than the required number of tiles then I reduce the optimal size and perform the checking again until all of the tiles fit the rectanlge.</p> <p>I could optimise this further by doing something like reduce the optimal size by -2 insted of -1 each time and then if all the tiles fit increase by 1 just to make sure that I've not missed a valid size. or I could jump back more than -2, say -10 then if they all tiles fit increase by 5, then if the don't fit reduce by -2 etc until I get an optimal fit.</p> <p>Check out <a href="http://kennethsutherland.com/flex/stackover/SlideSorterOK.html" rel="nofollow noreferrer">http://kennethsutherland.com/flex/stackover/SlideSorterOK.html</a> for my example. Thanks for all the various info.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload