r10421: major development
[cl-photo.git] / convert.lisp
index 5327d58ae7b898acd4256667aefc32b4d46ebc54..f663cf8fc98e1651357ea99a0cc8edb70b8ded8f 100755 (executable)
 (defun inches->mm (d)
   (* d +inches->mm+))
 
+(declaim (inline mm->inches))
+(defun mm->inches (d)
+  (/ d +inches->mm+))
+
+(defun length->mm (d units)
+  "Convert a length in units to mm."
+  (ecase units
+    (:mm d)
+    (:inches (inches->mm d))
+    (:feet (* 12 (inches->mm d)))
+    (:yards (* 36 (inches->mm d)))
+    (:meters (* 1000 d))))
+
+(defun mm->length (d units)
+  "Convert a number of mm to units."
+  (ecase units
+    (:mm d)
+    (:inches (mm->inches d))
+    (:feet (/ (mm->inches d) 12))
+    (:yards (/ (mm->inches d) 36))
+    (:meters (/ d 1000))))
+
 (defun format-dimensions (format)
   "Returns format dimensions in mm."
   (ecase format