| | 91 | |
|---|
| | 92 | (defun bounding-box (objects &key (key #'identity)) |
|---|
| | 93 | (let (min-x min-y max-x max-y) |
|---|
| | 94 | (dolist (obj objects) |
|---|
| | 95 | (let ((point (funcall key obj))) |
|---|
| | 96 | (with-point point |
|---|
| | 97 | (setf min-x (min point-x (or min-x point-x))) |
|---|
| | 98 | (setf min-y (min point-y (or min-y point-y))) |
|---|
| | 99 | (setf max-x (max point-x (or max-x point-x))) |
|---|
| | 100 | (setf max-y (max point-y (or max-y point-y)))))) |
|---|
| | 101 | (list min-x min-y (1+ (- max-x min-x)) (1+ (- max-y min-y))))) |
|---|
| | 102 | |
|---|
| | 103 | (defmacro with-bounding-box-collect ((collect) &body body) |
|---|
| | 104 | `(let (min-x min-y max-x max-y) |
|---|
| | 105 | (flet ((,collect (point) |
|---|
| | 106 | (with-point point |
|---|
| | 107 | (setf min-x (min point-x (or min-x point-x))) |
|---|
| | 108 | (setf min-y (min point-y (or min-y point-y))) |
|---|
| | 109 | (setf max-x (max point-x (or max-x point-x))) |
|---|
| | 110 | (setf max-y (max point-y (or max-y point-y)))))) |
|---|
| | 111 | ,@body) |
|---|
| | 112 | (list min-x min-y (1+ (- max-x min-x)) (1+ (- max-y min-y))))) |
|---|