Space Planning within a Polygon

Hello, I’m trying to use Dynamo and Refinery to create options for laying out rectangles within a polygon (or boundary). The goal is to use generative design to find different options for rectangle placements within a boundary and score the designs based on the rectangles proximity to one another and eventually what is the usability of the leftover space once all the rectangles have been placed. I haven’t built all the scoring criteria out yet, but my main issue is that I cannot get the rectangles to stay within the given boundary - which in my case is a polygon - and results in creating ONLY false options being shown in Refinery. I’ve tried scoring the outputs of the polygon.contains and geometry.doesintersect nodes to try and “maximize” those values in the optimization study in Refinery with no luck. How do I either filter out options which are not within the boundary before going into Refinery, or not allow the options to be created in the first place within the code? Below is my graph, the outputs I’m getting in Refinery (ran multiple ways using Randomize, Optimize, etc and all the results look like this), and and example of the expected outputs.

my graph:

my Refinery outputs (note: it only displays rectangles if they fit within the boundary which in this case is none, so that’s why you only see the 3 points which are the centerpoint of the rectangles):

and what I am trying to achieve by fitting the rectangles within the boundary:
Expected Results dynamo

Any help would be appreciated. I’m still quite new to this :slight_smile: Thank you!