Automated commit for upstream build of version 0.13
[cl-photo.git] / dof.lisp
index f1cd7b245a71b07bd95e1afdcfcf81a5bc15bcce..55b7b2a3696db4595a03c82a5046d97bc9addf6e 100644 (file)
--- a/dof.lisp
+++ b/dof.lisp
@@ -87,7 +87,8 @@ Default resolving power is 5 lpm at 25cm."
   "Returns depth of field based on focal-length, f-stop, distance, and coc.
 Six values are returned:
 near point, far point, total dof, magnification, blur size at infinity (mm).
-Circle of confusion can either be a number or keyword designating format."
+Circle of confusion can either be a number or keyword designating format.
+Reference: http://www.vanwalree.com/optics/dofderivation.html"
   (let* ((aperture (/ focal-length f-stop))
          (numerator-1 (* (- pupil-factor 1) (- distance focal-length)
                          coc focal-length))
@@ -101,25 +102,30 @@ Circle of confusion can either be a number or keyword designating format."
          (mag (float (/ focal-length (- distance focal-length))))
          (infinity-blur-diameter (/ (* mag focal-length) f-stop))
          (depth (- far near)))
+    (when (and (< far 0) (> distance focal-length))
+      (setq far most-positive-short-float)
+      (setq depth most-positive-short-float))
     (values near far depth mag infinity-blur-diameter)))
 
 ;; Simplified calculation for symmetric lens
 (defun dof-symmetric-mm (focal-length f-stop distance coc)
   "Returns depth of field based on focal-length, f-stop, distance, and coc.
 Six values are returned:
-near dof, far dof, total dof, near point, far point, magnification,
+near point, far point, total dof, near point, far point, magnification,
 blur size at infinity (mm).
-Circle of confusion can either be a number or keyword designating format.
-Pupil factor is the ratio of the exit to enterance pupil diameters."
+Circle of confusion can either be a number or keyword designating format."
   (let* ((aperture (/ focal-length f-stop))
          (numerator (* distance coc (- distance focal-length)))
          (factor-1 (* focal-length aperture))
          (factor-2 (* coc (- distance focal-length)))
          (near (- distance (/ numerator (+ factor-1 factor-2))))
          (far (+ distance (/ numerator (- factor-1 factor-2))))
-         (mag (magnification focal-length distance))
+         (mag (magnification :focal-length focal-length :object-distance distance :units :mm))
          (infinity-blur-diameter (/ (* mag focal-length) f-stop))
          (depth (- far near)))
+    (when (and (< far 0) (> distance focal-length))
+      (setq far most-positive-short-float)
+      (setq depth most-positive-short-float))
     (values near far depth mag infinity-blur-diameter)))
 
 (defun dof (focal-length f-stop distance coc &key (units :mm) (pupil-factor 1))