stoe/maths/utils.lisp

26 lines
747 B
Common Lisp

#|
This file is a part of stoe project.
Copyright (c) 2015 Renaud Casenave-Péré (renaud@casenave-pere.fr)
|#
(uiop:define-package :stoe/maths/utils
(:use :cl)
(:export #:lerp #:clamp
#:deg-to-rad #:rad-to-deg))
(in-package :stoe/maths/utils)
(defun lerp (a b ratio)
"Linear interpolation of `a' and `b' based on `ratio'."
(+ (* b ratio) (* a (- 1.0 ratio))))
(defun deg-to-rad (deg)
"Convert an angle from degree to radian."
(* deg (/ (* (coerce pi 'single-float) 2.0) 360.0)))
(defun rad-to-deg (rad)
"Convert an angle from radian to degree."
(/ rad (/ (* (coerce pi 'single-float) 2.0) 360.0)))
(defun clamp (number min max)
"Clamp a `number' between `min' and `max'."
(min max (max min number)))