This is the Feedback loop I was talking about:
If you sort the prims by increasing rotate attribute, you can pack them tight against each others like this, by repeatedly Ray SOP'ing the latest prims against the prims already in place, and translating by the minimal distance
This is an approximation to keep the Feedback look simple, there are a few intersections, but it's acceptable. If you want to pack exactly, you would have to ray SOP the points of the prims that are already in place against the candidate primitive, and handle the possible problematic cases, which I'm sure exist
If the candidate book is taller than the rightmost book that's already in place, it will not lean against the top right corner of the rightmost book,there is some slight collision. If the book is shorter however, this is always exact.
book_shelf.hipnc