X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=fov.lisp;h=64bbe80c737aaa71ffce0b2618ec9c7bfae71ae5;hb=50e13cbf899629662bacf8e224b4daeaabc2b054;hp=211820af13e616d9d5b83818b908f84e47eb8a15;hpb=cd49c092c9ede840170af3301b9296cec4b0be3e;p=cl-photo.git diff --git a/fov.lisp b/fov.lisp index 211820a..64bbe80 100644 --- a/fov.lisp +++ b/fov.lisp @@ -159,7 +159,7 @@ focal-length and image-distance are in mm, object-distance is in units" (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) &aux bellows-factor) +(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." @@ -208,3 +208,54 @@ Returns: focal-length object-distance image-distance magnification bellows-facto "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))) + +(defun extension-tube (focal-length &key original-object-distance + original-image-distance original-magnification + new-object-distance new-image-distance + new-magnification extension-length (units :feet)) + "Computes the parameters for using extension tubes. +Requires: 1. original-object-distance, original-image-distance, or original-magnification + 2. new-object-distance, new-image-distance, new-magnification, or extension-length +Returns: original-object-distance, original-image-distance, original-magnification, original-bellows-factor + new-object-distance, new-image-distance, new-magnification, extension-length." + + (when (or (not focal-length) (not units) + (not (n-args-not-nil 1 original-object-distance + original-image-distance + original-magnification)) + (not (n-args-not-nil 1 new-object-distance + new-image-distance + new-magnification + extension-length))) + (error "Invalid arguments. +Must set 1 of the following original-object-distance, original-image-distance, +or original-magnification parameters as well as one of the following parameters +new-object-distance, new-image-distance, new-magnification, or extension-length.")) + + (flet ((ret (ood oid om obf nod nid nm nbf e) + (list :focal-length focal-length :original-object-distance ood + :original-image-distance oid :original-magnification om + :original-bellows-factor obf :new-object-distance nod + :new-image-distance nid :new-magnification nm + :new-bellows-factor nbf :extension-length e))) + + (multiple-value-bind (focal-length-original o-od o-id o-m o-bf) + (close-up :focal-length focal-length :object-distance original-object-distance + :image-distance original-image-distance :magnification original-magnification :units units) + (declare (ignore focal-length-original)) + + (cond + (extension-length + (multiple-value-bind (focal-length-new n-od n-id n-m n-bf) + (close-up :focal-length focal-length :image-distance (+ o-id extension-length) :units units) + (declare (ignore focal-length-new)) + (ret o-od o-id o-m o-bf n-od n-id n-m n-bf extension-length))) + ((not extension-length) + (multiple-value-bind (focal-length-new n-od n-id n-m n-bf) + (close-up :focal-length focal-length :object-distance new-object-distance + :image-distance new-image-distance :magnification new-magnification :units units) + (declare (ignore focal-length-new)) + (ret o-od o-id o-m o-bf n-od n-id n-m n-bf (- n-id o-id))))))))