How it works
The usable area is the roof plane minus the ridge, eave and side setbacks. Panels are then packed in rows and columns with the clamp gap between them, once in portrait (long side up the slope) and once in landscape, and the layout with more panels wins.
Setbacks: the International Residential Code (R324.6) and Fire Code (1205) call for 36 in access pathways from eave to ridge on residential roofs and a clear strip below the ridge, often 18 in when the array covers a third of the roof or less, 36 in above that. Local rules vary, so use your AHJ's numbers.
The count is geometric. Vents, skylights, chimneys, shade and the racking maker's edge zones can reduce it.