Constrain to a cube

Continuing with isometric shapes, I tried to build a system where all the branches were all constrained to a cube. All the branching shapes have a starting point on the bottom left or right of the container cube. I found a function on Stack overflow that I used to check if any of the shapes passed outside the base container. At any time the branching shape’s escaped from the base cube the system would start over. Since the chance of starting over is pretty high the number of iterations had to be high in order to fill the space.