src/coordinates.lisp @ 19aeb5ea3df9

Switch to 3d-vectors (partially)
author Steve Losh <steve@stevelosh.com>
date Wed, 04 Apr 2018 23:37:07 -0400
parents d5b02d8c4803
children (none)
(in-package :flax.coordinates)

(defstruct (coord (:conc-name "")
                  (:constructor make-coord (x y)))
  (x (error "Required") :type single-float)
  (y (error "Required") :type single-float))

(defun coord (x y)
  (make-coord (coerce x 'single-float)
              (coerce y 'single-float)))

(defun radial (angle magnitude)
  (coord (* magnitude (cos angle))
         (* magnitude (sin angle))))

(defun distance (c1 c2)
  (sqrt (+ (square (- (x c2) (x c1)))
           (square (- (y c2) (y c1))))))

(defun clerp (from to n)
  (coord (lerp (x from) (x to) n)
         (lerp (y from) (y to) n)))

(defun coord+ (a b)
  (coord (+ (x a) (x b))
         (+ (y a) (y b))))

(defun coord-to-cons (c)
  (cons (x c) (y c)))