X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=convert.lisp;h=b73595b56dff828f3ab74490a4d74f983a1118c3;hb=c9e757cf83865138421a9a09a6237fabbff2aab4;hp=8a07ff7d0b2559497aa1081e317a32298aa802c0;hpb=2502270d59bbf71c29d82486997d38a3981b307c;p=cl-photo.git diff --git a/convert.lisp b/convert.lisp old mode 100755 new mode 100644 index 8a07ff7..b73595b --- a/convert.lisp +++ b/convert.lisp @@ -9,25 +9,63 @@ ;;;; ;;;; $Id$ ;;;; -;;;; This file, part of cl-photo, is Copyright (c) 2005 by Kevin Rosenberg. -;;;; Rights of modification and redistribution are in the LICENSE file. +;;;; This file, part of cl-photo, is Copyright (c) 2005 by Kevin M. Rosenberg +;;;; +;;;; cl-photo users are granted the rights to distribute and use this software +;;;; as governed by the terms of the GNU General Public License v2 +;;;; (http://www.gnu.org/licenses/gpl.html) ;;;; ;;;; ************************************************************************* (in-package #:photo) (defconstant +radian->degrees+ (/ 360d0 pi 2)) -(defconstant +inches->mm+ 25.4) +(defconstant +inches->mm+ 25.4d0) +(declaim (inline diagonal)) (defun diagonal (x y) (sqrt (+ (* x x) (* y y)))) +(declaim (inline radians->degrees)) (defun radians->degrees (r) (* +radian->degrees+ r)) +(declaim (inline degrees->radians)) +(defun degrees->radians (r) + (/ r +radian->degrees+)) + +(declaim (inline mm->feet)) (defun mm->feet (d) (/ d +inches->mm+ 12)) +(declaim (inline feet->mm)) (defun feet->mm (d) (* d 12 +inches->mm+)) +(declaim (inline inches->mm)) +(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)))) + +