Update domain name to kpe.io
[cl-photo.git] / convert.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10; Package: photo -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          convert.lisp
6 ;;;; Purpose:       Conversions functions for cl-photo
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  April 2005
9 ;;;;
10 ;;;; $Id$
11 ;;;;
12 ;;;; This file, part of cl-photo, is Copyright (c) 2005 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; cl-photo users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the GNU General Public License v2
16 ;;;; (http://www.gnu.org/licenses/gpl.html)
17 ;;;;
18 ;;;; *************************************************************************
19
20 (in-package #:photo)
21
22 (defconstant +radian->degrees+ (/ 360d0 pi 2))
23 (defconstant +inches->mm+ 25.4d0)
24
25 (declaim (inline diagonal))
26 (defun diagonal (x y)
27   (sqrt (+ (* x x) (* y y))))
28
29 (declaim (inline radians->degrees))
30 (defun radians->degrees (r)
31   (* +radian->degrees+ r))
32
33 (declaim (inline degrees->radians))
34 (defun degrees->radians (r)
35   (/ r +radian->degrees+))
36
37 (declaim (inline mm->feet))
38 (defun mm->feet (d)
39   (/ d +inches->mm+ 12))
40
41 (declaim (inline feet->mm))
42 (defun feet->mm (d)
43   (* d 12 +inches->mm+))
44
45 (declaim (inline inches->mm))
46 (defun inches->mm (d)
47   (* d +inches->mm+))
48
49 (declaim (inline mm->inches))
50 (defun mm->inches (d)
51   (/ d +inches->mm+))
52
53 (defun length->mm (d units)
54   "Convert a length in units to mm."
55   (ecase units
56     (:mm d)
57     (:inches (inches->mm d))
58     (:feet (inches->mm (* d 12)))
59     (:yards (inches->mm (* d 36)))
60     (:meters (* 1000 d))))
61
62 (defun mm->length (d units)
63   "Convert a number of mm to units."
64   (ecase units
65     (:mm d)
66     (:inches (mm->inches d))
67     (:feet (/ (mm->inches d) 12))
68     (:yards (/ (mm->inches d) 36))
69     (:meters (/ d 1000))))
70
71