. . Hi there, everybody.
. . I have a canvas defined by many points (x,y)--it's not rectangular, but at least it will follow some almost-hexagonal shape (like a distorted hexagon, with angles that are always < 180 degrees). I also have a big collection of different rectangles (more or less 140 of them, with different widths and heights) and I need to position them inside the shape. They must be positioned as if they were being pushed by gravity (I mean... the top of the shape doesn't needs to be filled, but the bottom needs). . . Right now my only idea is to store the min and max "x" position for every "y" position (something like: limits[300] = [30,30]; limits[299] = [29, 32]; ...), loop through the rectangles, get their area and then compare the values to find the best position. The biggest issued I have right now is that they need to be organized in a "organic" way, not like a table (I can't have rows and columns and position them inside cells. they need to be positioned as good as they can be, like fluidly, side by side, one above other...). I'm not sure how to manage the positioning. . . I know some good examples of "auto-balanced" objects (a good one is the "Ball Pool" Chrome Experiment: http://mrdoob.com/projects/chromeexperiments/ball_pool/), but they use rectangular canvas and circular objects, which are much easier to compare the limits. . . Right now my best idea is to check the objects for every possible x/y combination, from bottom to up, from left to right, checking if any area would overlap, but this would probably lock the whole computer for the calculations for minutes (the more itens on the screen, the more calculations would be needed).
. . The project is running on Flash, but any example, tip, algorithm, paper or pseudo-code will be of great help.