Add simple maths functions

lerp, clamp, deg-to-rad and rad-to-deg
This commit is contained in:
Renaud Casenave-Péré 2014-01-02 20:27:01 +09:00
parent 3f317bb1da
commit e47f9c7c05

View file

@ -6,5 +6,23 @@
(in-package :cl-user)
(defpackage stoe.maths
(:nicknames :maths)
(:use :cl))
(:use :cl)
(:export :lerp :clamp
:deg-to-rad :rad-to-deg))
(in-package :stoe.maths)
(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."
(/ deg (/ (* (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)))