summary refs log tree commit diff
path: root/lib/vec.fnl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/vec.fnl')
-rw-r--r--lib/vec.fnl27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/vec.fnl b/lib/vec.fnl
new file mode 100644
index 0000000..cce9627
--- /dev/null
+++ b/lib/vec.fnl
@@ -0,0 +1,27 @@
+(fn ilerp* [a b c d x]
+  (+ c (* (/ (- x a) (- b a)) (- d c))))
+
+(fn add [a b]
+  {:x (+ a.x b.x)
+   :y (+ a.y b.y)})
+
+(fn sub [a b]
+  {:x (- a.x b.x)
+   :y (- a.y b.y)})
+
+(fn mul [v n]
+  {:x (* v.x n)
+   :y (* v.y n)})
+
+(fn mag [v]
+  (math.sqrt (+ (* v.x v.x) (* v.y v.y))))
+
+(fn wrap [a b]
+  {:x (% a.x b.x)
+   :y (% a.y b.y)})
+
+(fn lerp [a b c d x]
+  {:x (ilerp* a.x b.x c.x d.x x.x)
+   :y (ilerp* a.y b.y c.y d.y x.y)})
+
+{: lerp : add : sub : mul : mag : wrap}