(define (enclosing-rect rects) (when (null? rects) (abort (usage-error "RECTS must be a list of at least one rect" 'enclosing-rect))) (let loop ((x (rect-x (car rects))) (y (rect-y (car rects))) (w (rect-w (car rects))) (h (rect-h (car rects))) (rects (cdr rects))) (if (pair? rects) (let ((rect (car rects))) (loop (min (rect-x rect) x) (min (rect-y rect) y) (max (rect-w rect) w) (max (rect-h rect) h) (cdr rects))) (rect x y w h)))) (define (enclosing-rect rects) (when (null? rects) (abort (usage-error "RECTS must be a list of at least one rect" 'enclosing-rect))) (fold (lambda (current outer) (let ((x (min (rect-x current) (rect-x outer))) (y (min (rect-y current) (rect-y outer))) (w (max (rect-w current) (rect-w outer))) (h (max (rect-h current) (rect-h outer)))) (rect x y w h))) (car rects) (cdr rects)))