Add simple maths functions
lerp, clamp, deg-to-rad and rad-to-deg
This commit is contained in:
parent
3f317bb1da
commit
e47f9c7c05
1 changed files with 19 additions and 1 deletions
|
|
@ -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)))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue