--- a/coding-math.asd Sun Apr 17 21:57:14 2016 +0000
+++ b/coding-math.asd Mon Apr 18 22:58:22 2016 +0000
@@ -19,9 +19,12 @@
:components ((:file "quickutils") ; quickutils package ordering crap
(:file "package")
(:module "src"
+ :serial t
:components ((:file "utils")
(:file "math")
(:file "vectors")
(:file "particles")
- (:file "main")))))
+ (:file "main")
+ (:file "ballistics")
+ ))))
--- a/package.lisp Sun Apr 17 21:57:14 2016 +0000
+++ b/package.lisp Mon Apr 18 22:58:22 2016 +0000
@@ -4,10 +4,81 @@
#:mulf
#:dividesp))
+(defpackage #:coding-math.math
+ (:use #:cl
+ #:coding-math.quickutils
+ #:coding-math.utils)
+ (:export
+ #:tau
+ #:random-range
+ #:random-around
+ #:norm
+ #:lerp
+ #:precise-lerp
+ #:map-range
+ #:clamp
+ #:wrap-zero
+ #:wrap-range
+ #:outside-p))
+
+(defpackage #:coding-math.vectors
+ (:use #:cl
+ #:coding-math.quickutils
+ #:coding-math.utils)
+ (:export
+ #:vec
+ #:vec-x
+ #:vec-y
+ #:make-vec
+ #:make-vec-md
+ #:make-vec-ma
+ #:vec-magnitude
+ #:vec-direction
+ #:vec-angle
+ #:vec-add
+ #:vec-sub
+ #:vec-mul
+ #:vec-div
+ #:vec-add!
+ #:vec-sub!
+ #:vec-mul!
+ #:vec-div!
+ #:vec-to-string))
+
+(defpackage #:coding-math.particles
+ (:use #:cl
+ #:coding-math.vectors
+ #:coding-math.quickutils
+ #:coding-math.utils)
+ (:export
+ #:particle
+ #:particle-vel
+ #:particle-pos
+ #:particle-grv
+ #:particle-radius
+ #:particle-mass
+ #:make-particle
+ #:particle-x
+ #:particle-y
+ #:particle-wrap!
+ #:particle-update!
+ #:particle-accelerate!
+ #:particle-angle-to
+ #:particle-distance-to
+ #:particle-gravitate-to!))
+
(defpackage #:coding-math
(:use #:cl
#:sketch
#:coding-math.quickutils
- #:coding-math.utils)
- (:shadow
- #:normalize))
+ #:coding-math.utils
+ #:coding-math.math
+ #:coding-math.vectors
+ #:coding-math.particles
+ ))
+
+(defpackage #:coding-math.ballistics
+ (:use #:cl
+ #:sketch
+ #:coding-math.quickutils
+ #:coding-math.utils))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ballistics.lisp Mon Apr 18 22:58:22 2016 +0000
@@ -0,0 +1,1 @@
+(in-package #:coding-math.ballistics)
--- a/src/main.lisp Sun Apr 17 21:57:14 2016 +0000
+++ b/src/main.lisp Mon Apr 18 22:58:22 2016 +0000
@@ -1,8 +1,8 @@
(in-package #:coding-math)
-(declaim (optimize (speed 3)
- (safety 2)
- (debug 0)))
+(declaim (optimize (speed 0)
+ (safety 3)
+ (debug 3)))
;;;; Config
(defparameter *width* 600)
@@ -142,4 +142,4 @@
;;;; Run
-(defparameter *demo* (make-instance 'cm))
+; (defparameter *demo* (make-instance 'cm))
--- a/src/math.lisp Sun Apr 17 21:57:14 2016 +0000
+++ b/src/math.lisp Mon Apr 18 22:58:22 2016 +0000
@@ -1,4 +1,4 @@
-(in-package #:coding-math)
+(in-package #:coding-math.math)
;; Constants
(defconstant tau (* pi 2))
@@ -14,7 +14,7 @@
;; Number range mapping
-(defun normalize (min max val)
+(defun norm (min max val)
(/ (- val min)
(- max min)))
@@ -41,7 +41,7 @@
(defun map-range (source-from source-to dest-from dest-to source-val)
"Map `source-val` from the source range to the destination range."
(lerp dest-from dest-to
- (normalize source-from source-to source-val)))
+ (norm source-from source-to source-val)))
(defun clamp (min max n)
(cond
--- a/src/particles.lisp Sun Apr 17 21:57:14 2016 +0000
+++ b/src/particles.lisp Mon Apr 18 22:58:22 2016 +0000
@@ -1,4 +1,4 @@
-(in-package #:coding-math)
+(in-package #:coding-math.particles)
(defclass particle ()
((pos :type 'vec
--- a/src/vectors.lisp Sun Apr 17 21:57:14 2016 +0000
+++ b/src/vectors.lisp Mon Apr 18 22:58:22 2016 +0000
@@ -1,4 +1,4 @@
-(in-package #:coding-math)
+(in-package #:coding-math.vectors)
(defclass vec ()
((x :type 'real :initarg :x :accessor vec-x)
@@ -14,6 +14,9 @@
(vec-angle v) angle)
v))
+(defun make-vec-ma (magnitude angle)
+ (make-vec-md magnitude angle))
+
(defun vec-magnitude (vec)
(with-slots (x y) vec
@@ -24,6 +27,9 @@
(with-slots (x y) vec
(atan y x)))
+(defun vec-direction (vec)
+ (vec-angle vec))
+
(defun (setf vec-angle) (angle vec)
(let ((magnitude (vec-magnitude vec)))