+ (let ((dim (imager-dimensions format)))
+ (aov focal-length (car dim) (cdr dim) :projection projection)))
+
+(defun magnification (&key focal-length object-distance image-distance (units :feet))
+ "Returns the image magnification: the ratio of image size to object size.
+focal-length and image-distance are in mm, object-distance is in units"
+ (when object-distance
+ (setq object-distance (length->mm object-distance units)))
+ (cond
+ ((and (not focal-length) object-distance image-distance)
+ (if (zerop object-distance)
+ :error
+ (float (/ image-distance object-distance))))
+ ((and focal-length object-distance (not image-distance))
+ (cond
+ ((eql object-distance focal-length)
+ most-positive-double-float)
+ ((< object-distance focal-length)
+ :error)
+ (t
+ (float (/ focal-length (- object-distance focal-length))))))
+ ((and focal-length (not object-distance) image-distance)
+ (cond
+ ((eql image-distance focal-length)
+ most-positive-double-float)
+ ((< image-distance focal-length)
+ :error)
+ (t
+ (float (1- (/ image-distance focal-length))))))
+ (t
+ (error "Must set two, and only two, of the parameters: image-distance, object-distance, and focal-length."))))
+
+(defun close-up (&key focal-length object-distance image-distance magnification (units :feet))
+ "Computes the parameters for focusing closer than infinity.
+Requires two, and only two, of the input parameters.
+Returns: focal-length object-distance image-distance magnification bellows-factor."
+ (cond
+ ((and focal-length object-distance (not image-distance) (not magnification))
+ (setq magnification (magnification :focal-length focal-length
+ :object-distance object-distance
+ :units units))
+ (setq image-distance (gaussian-lens :focal-length focal-length
+ :object-distance object-distance
+ :units units)))
+ ((and focal-length (not object-distance) image-distance (not magnification))
+ (setq magnification (magnification :focal-length focal-length
+ :image-distance image-distance
+ :units units))
+ (setq object-distance (gaussian-lens :focal-length focal-length
+ :image-distance image-distance
+ :units units)))
+ ((and (not focal-length) object-distance image-distance (not magnification))
+ (setq magnification (magnification :object-distance object-distance
+ :image-distance image-distance
+ :units units))
+ (setq focal-length (gaussian-lens :object-distance object-distance
+ :image-distance image-distance
+ :units units)))
+ ((and focal-length (not object-distance) (not image-distance) magnification)
+ (setq image-distance (image-distance-magnification focal-length magnification))
+ (setq object-distance (gaussian-lens :focal-length focal-length
+ :image-distance image-distance
+ :units units)))
+ ((and (not focal-length) object-distance (not image-distance) magnification)
+ (setq image-distance (* magnification (length->mm object-distance units)))
+ (setq focal-length (gaussian-lens :image-distance image-distance
+ :object-distance object-distance
+ :units units)))
+ ((and (not focal-length) (not object-distance) image-distance magnification)
+ (setq object-distance (mm->length (float (/ image-distance magnification)) units))
+ (setq focal-length (gaussian-lens :image-distance image-distance
+ :object-distance object-distance
+ :units units)))
+ (t
+ (error "Must set two, and only two input parameters: focal-length, image-distance, object-distance, magnifcation.")))
+ (values focal-length object-distance image-distance magnification (1+ magnification)))
+
+(defun bellows-factor (focal-length object-distance)
+ "Returns the bellows factor, the ratio of effective aperature to actual aperture."
+ (1+ (magnification :focal-length focal-length :object-distance object-distance)))
+
+(defun n-args-not-nil (n &rest args)
+ "Returns T when count N of input args are not nil."
+ (= n (count-if-not #'null args)))