Working on generics.

- Added Generics module.
- Some Geometry/Vector* functions hardcoded parameters to Double.
This commit is contained in:
Jorge Acereda 2019-09-08 13:02:04 +02:00
parent 3763312cd1
commit 08af49dc62
20 changed files with 849 additions and 377 deletions

View File

@ -238,7 +238,7 @@ If the element is not found, returns `Nothing`")
(for [i 0 n] (aset-uninitialized! &a i (~f)))
a))
(doc repeat-indexed "repeats function `f` `n `times and stores the results in an array.
(doc repeat-indexed "repeats function `f` `n` times and stores the results in an array.
This is similar to [`repeat`](#repeat), but the function `f` will be supplied with the index of the element.")
(defn repeat-indexed [n f]

View File

@ -1,4 +1,5 @@
(load "Interfaces.carp")
(load "Generics.carp")
(load "Macros.carp")
(load "Maybe.carp")
(load "Result.carp")

View File

@ -3,6 +3,7 @@
(defmodule Double
(def pi 3.141592653589793)
(def e 2.718281828459045)
(register MAX Double "CARP_DBL_MAX")
(register = (Fn [Double Double] Bool))
(register < (Fn [Double Double] Bool))
(register > (Fn [Double Double] Bool))
@ -18,44 +19,36 @@
(register to-long (Fn [Double] Long))
(register from-long (Fn [Long] Double))
(register to-bytes (Fn [Double] Long))
(register sin (Fn [Double] Double))
(register cos (Fn [Double] Double))
(register tan (Fn [Double] Double))
(register copy (Fn [(Ref Double)] Double))
(register abs (Fn [Double] Double))
(register acos (Fn [Double] Double))
(register asin (Fn [Double] Double))
(register atan (Fn [Double] Double))
(register atan2 (Fn [Double Double] Double))
(register ceil (Fn [Double] Double))
(register cos (Fn [Double] Double))
(register cosh (Fn [Double] Double))
(register sinh (Fn [Double] Double))
(register tanh (Fn [Double] Double))
(register exp (Fn [Double] Double))
(register floor (Fn [Double] Double))
(register frexp (Fn [Double (Ref Int)] Double))
(register ldexp (Fn [Double Int] Double))
(register log (Fn [Double] Double))
(register log10 (Fn [Double] Double))
(register mod (Fn [Double Double] Double))
(register modf (Fn [Double (Ref Double)] Double))
(register pow (Fn [Double Double] Double))
(register sin (Fn [Double] Double))
(register sinh (Fn [Double] Double))
(register sqrt (Fn [Double] Double))
(register floor (Fn [Double] Double))
(register ceil (Fn [Double] Double))
(register mod (Fn [Double Double] Double))
(register copy (Fn [(Ref Double)] Double))
(register abs (Fn [Double] Double))
(defn clamp [min, max, val]
(if (> val max)
max
(if (< val min)
min
val)))
(register tan (Fn [Double] Double))
(register tanh (Fn [Double] Double))
(doc approx "checks whether `x` and `y` are approximately equal.
The margin of error is `0.00001`.")
(defn approx [x y]
(if (> x y)
(< (- x y) 0.00001)
(< (- y x) 0.00001)))
(Generics.approx x y))
(defn /= [x y]
(not (Double.= x y)))
@ -64,6 +57,12 @@ The margin of error is `0.00001`.")
(defn zero []
0.0)
(defn inc [x]
(+ 1.0 x))
(defn dec [x]
(- x 1.0))
(defn add-ref [x y]
(Double.+ @x @y))
)

View File

@ -2,6 +2,7 @@
(defmodule Float
(def pi 3.1415926536f)
(register MAX Float "CARP_FLT_MAX")
(register neg (Fn [Float] Float))
(register + (Fn [Float Float] Float))
(register - (Fn [Float Float] Float))
@ -29,38 +30,43 @@
The margin of error is 0.00001.")
(defn approx [x y]
(if (> x y)
(< (- x y) 0.00001f)
(< (- y x) 0.00001f)))
(Generics.approx x y))
(register sin (Fn [Float] Float))
(register cos (Fn [Float] Float))
(register tan (Fn [Float] Float))
(register copy (Fn [(Ref Float)] Float))
(register abs (Fn [Float] Float))
(register acos (Fn [Float] Float))
(register asin (Fn [Float] Float))
(register atan (Fn [Float] Float))
(register atan2 (Fn [Float Float] Float))
(register ceil (Fn [Float] Float))
(register cos (Fn [Float] Float))
(register cosh (Fn [Float] Float))
(register sinh (Fn [Float] Float))
(register tanh (Fn [Float] Float))
(register exp (Fn [Float] Float))
(register floor (Fn [Float] Float))
(register frexp (Fn [Float (Ref Int)] Float))
(register ldexp (Fn [Float Int] Float))
(register log (Fn [Float] Float))
(register log10 (Fn [Float] Float))
(register mod (Fn [Float Float] Float))
(register modf (Fn [Float (Ref Float)] Float))
(register pow (Fn [Float Float] Float))
(register sin (Fn [Float] Float))
(register sinh (Fn [Float] Float))
(register sqrt (Fn [Float] Float))
(register floor (Fn [Float] Float))
(register ceil (Fn [Float] Float))
(register mod (Fn [Float Float] Float))
(register copy (Fn [(Ref Float)] Float))
(register abs (Fn [Float] Float))
(register tan (Fn [Float] Float))
(register tanh (Fn [Float] Float))
(doc zero "returns `0.0f`.")
(defn zero []
0.0f)
(defn inc [x]
(+ 1.0f x))
(defn dec [x]
(- x 1.0f))
(defn add-ref [x y]
(Float.+ @x @y))
)

106
core/Generics.carp Normal file
View File

@ -0,0 +1,106 @@
;; The following generic functions make use of the interfaces
(defmodule Generics
(defn one [] (inc (zero)))
(defn minus-one [] (dec (zero)))
(defn two [] (inc (one)))
(defn three [] (inc (two)))
(defn minus-two [] (* (two) (minus-one)))
(defn four [] (+ (two) (two)))
(defn five [] (+ (four) (one)))
(defn ten [] (+ (five) (five)))
(defn hundred [] (* (ten) (ten)))
(defn thousand [] (* (hundred) (ten)))
(defn hundred-thousand [] (* (hundred) (thousand)))
(defn million [] (* (thousand) (thousand)))
(defn minus-four [] (* (four) (minus-one)))
(defn twice [x] (* (two) x))
(defn halved [x] (/ x (two)))
(defn squared [x] (* x x))
(defn inverse [x] (/ (one) x))
(defn half [] (halved (one)))
(defn half-pi [] (halved pi))
(defn tau [] (twice pi))
(defn ninety [] (* (two) (* (* (three) (three)) (five))))
(defn one-hundred-eighty [] (* (two) (ninety)))
(defn small [] (inverse (hundred-thousand)))
(doc approx-margin "checks whether `x` and `y` are approximately equal within a `margin`.")
(defn approx-margin [x y margin]
(if (> x y)
(< (- x y) margin)
(< (- y x) margin)))
(doc approx-margin "checks whether `x` and `y` are approximately equal with a margin.
The margin of error is 0.00001.")
(defn approx [a b]
(approx-margin a b (small)))
)
;; These are defined in the global scope.
(use Generics)
(defn <= [a b]
(or (< a b)
(= a b)))
(defn >= [a b]
(or (> a b)
(= a b)))
(defn cmp [a b]
(if (= a b)
0
(if (< a b) -1 1)))
(defn max [a b]
(if (> a b) a b))
(defn min [a b]
(if (< a b) a b))
(defn zero? [x]
(= (zero) x))
(defn pos? [x]
(< (zero) x))
(defn neg? [x]
(< x (zero)))
(defn not-neg? [x]
(not (neg? x)))
(defn id [x] x)
(defn null? [p]
(Pointer.eq NULL (the (Ptr t) p)))
(defn not-null? [p]
(not (null? p)))
(defn clamp [min, max, val]
(if (> val max)
max
(if (< val min)
min
val)))
(defn clamp--1-1 [v]
(clamp (minus-one) (one) v))
(defn lerp [from to amount]
(+ from (* (- to from) amount)))
(defn between [x l u]
(and (>= x l) (<= x u)))
(defn random-0-1 []
(random-between (zero) (one)))
(defn random--1-1 []
(random-between (minus-one) (one)))

View File

@ -1,9 +1,9 @@
(defmodule Geometry
(doc degree-to-radians "converts degrees expressed as a double `n` into radians.")
(defn degree-to-radians [n]
(Double.* n (Double./ Double.pi 180.0)))
(* n (/ pi (one-hundred-eighty))))
(doc radians-to-degree "converts radians expressed as a double `n` into degrees.")
(defn radians-to-degree [n]
(Double.* n (Double./ 180.0 Double.pi)))
(* n (/ (one-hundred-eighty) pi)))
)

View File

@ -21,8 +21,10 @@
(definterface < (λ [a a] Bool))
(definterface > (λ [a a] Bool))
(definterface zero (λ [] a))
(definterface inc (λ [a] a))
(definterface dec (λ [a] a))
(definterface neg (λ [a] a))
(definterface to-int (λ [a] Int))
(definterface from-int (λ [Int] a))
@ -30,50 +32,30 @@
(definterface format (λ [&String a] String))
(definterface from-string (λ [&String] a))
(definterface zero (λ [] a))
(definterface random (Fn [] a))
(definterface random-between (Fn [a a] a))
(definterface pi a)
(definterface neg (λ [a] a))
;; The following functions make use of the interfaces
(defn <= [a b]
(or (< a b)
(= a b)))
(defn >= [a b]
(or (> a b)
(= a b)))
(defn cmp [a b]
(if (= a b)
0
(if (< a b) -1 1)))
(defn max [a b]
(if (> a b) a b))
(defn min [a b]
(if (< a b) a b))
(defn zero? [x]
(= (zero) x))
(defn pos? [x]
(< (zero) x))
(defn neg? [x]
(< x (zero)))
(defn id [x] x)
(defn null? [p]
(Pointer.eq NULL (the (Ptr t) p)))
(defn not-null? [p]
(not (null? p)))
(definterface abs (λ [a] a))
(definterface acos (λ [a] a))
(definterface asin (λ [a] a))
(definterface atan (λ [a] a))
(definterface atan2 (λ [a a] a))
(definterface ceil (λ [a] a))
(definterface cos (λ [a] a))
(definterface cosh (λ [a] a))
(definterface exp (λ [a] a))
(definterface floor (λ [a] a))
(definterface frexp (λ [a (Ref Int)] a))
(definterface ldexp (λ [a Int] a))
(definterface log (λ [a] a))
(definterface log10 (λ [a] a))
(definterface mod (λ [a a] a))
(definterface modf (λ [a (Ref a)] a))
(definterface pow (λ [a a] a))
(definterface sin (λ [a] a))
(definterface sinh (λ [a] a))
(definterface sqrt (λ [a] a))
(definterface tan (λ [a] a))
(definterface tanh (λ [a] a))

View File

@ -1,19 +1,28 @@
(deftype (Vector2 a) [x a, y a])
(deftype (Vector2 f) [x f, y f])
(defmodule Vector2
(defn map [f v]
(init (f @(x v))
(f @(y v))))
(defn zip [f a b]
(init (f @(x a) @(x b))
(f @(y a) @(y b))))
(defn vreduce [f i v]
(f (f i @(x v)) @(y v)))
(defn zero []
(init 0.0 0.0))
(init (zero) (zero)))
(defn random []
(init (random-between 0.0 1.0) (random-between 0.0 1.0)))
(init (random-0-1) (random-0-1)))
(defn add [a b]
(init (+ @(x a) @(x b))
(+ @(y a) @(y b))))
(zip + a b))
(defn sub [a b]
(init (- @(x a) @(x b))
(- @(y a) @(y b))))
(zip - a b))
(defn mul [a n]
(init (* @(x a) n)
@ -24,31 +33,34 @@
(/ @(y a) n)))
(defn = [a b]
(and (Double.= @(x a) @(x b))
(Double.= @(y a) @(y b))))
(vreduce (fn [i v] (and i v)) true &(zip = a b)))
(defn /= [a b]
(not (= a b)))
(doc approx "Check whether the vectors a and b are approximately equal.")
(defn approx [a b]
(and (Double.approx @(x a) @(x b))
(Double.approx @(y a) @(y b))))
(doc vapprox "Check whether the vectors a and b are approximately equal.")
(defn vapprox [a b]
(vreduce (fn [i v] (and i v)) true &(zip approx a b)))
(defn sum [o]
(vreduce + (zero) o))
(doc dot "Get the dot product of the two vectors x and y.")
(defn dot [a b]
(sum &(zip * a b)))
(doc mag-sq "Get the squared magnitude of a vector.")
(defn mag-sq [o]
(let [x @(x o)
y @(y o)]
(+ (* x x) (* y y))))
(dot o o))
(doc mag "Get the magnitude of a vector.")
(defn mag [o]
(Double.sqrt (mag-sq o)))
(sqrt (mag-sq o)))
(doc normalize "Normalize a vector.")
(defn normalize [o]
(let [m (mag o)]
(if (= m 0.0)
(if (zero? m)
@o
(div o m))))
@ -59,97 +71,113 @@
(doc heading "Get the heading of the vector a.")
(defn heading [a]
(Double.atan2 @(y a) @(x a)))
(atan2 @(y a) @(x a)))
(doc rotate "Rotate the vector a by the radians n.")
(defn rotate [a n]
(let [h (+ (heading a) n)
m (mag a)]
(init (* (Double.cos h) m) (* (Double.sin h) m))))
(init (* (cos h) m) (* (sin h) m))))
(doc dot "Get the dot product of the two vectors x and y.")
(defn dot [a b]
(+ (* @(x a) @(x b))
(* @(y a) @(y b))))
(doc angle-between "Get the angle between to vectors a and b.")
(doc angle-between "Get the angle between two vectors a and b.")
(defn angle-between [a b]
(let [dmm (/ (dot a b) (* (mag a) (mag b)))]
(Double.acos (Double.clamp -1.0 1.0 dmm))))
(acos (clamp--1-1 dmm))))
(doc anti-parallel? "Check whether the two vectors a and b are anti-parallel.")
(defn anti-parallel? [a b]
(= (angle-between a b) Double.pi))
(= (angle-between a b) pi))
(doc parallel? "Check whether the two vectors a and b are parallel.")
(defn parallel? [a b]
(= (angle-between a b) 0.0))
(zero? (angle-between a b)))
(doc perpendicular? "Check whether the two vectors a and b are perpendicular.")
(defn perpendicular? [a b]
(= (angle-between a b) (/ Double.pi 2.0)))
(= (angle-between a b) (half-pi)))
(doc lerp "Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).")
(defn lerp [a b amnt]
(init (* (- @(x b) @(x a)) amnt)
(* (- @(y b) @(y a)) amnt)))
(doc vlerp "Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).")
(defn vlerp [a b amnt]
(zip (fn [a b] (lerp a b amnt)) a b))
)
(deftype (Vector3 a) [x a, y a, z a])
(deftype (Vector3 f) [x f, y f, z f])
(defmodule Vector3
(defn map [f v]
(init (f @(x v))
(f @(y v))
(f @(z v))))
(defn zip [f a b]
(init (f @(x a) @(x b))
(f @(y a) @(y b))
(f @(z a) @(z b))))
(defn vreduce [f i v]
(f (f (f i @(x v)) @(y v)) @(z v)))
(defn zero []
(init 0.0 0.0 0.0))
(init (zero) (zero) (zero)))
(defn random []
(init (random-between 0.0 1.0) (random-between 0.0 1.0) (random-between 0.0 1.0)))
(init (random-0-1) (random-0-1) (random-0-1)))
(defn = [a b]
(and (Double.= @(x a) @(x b))
(and (Double.= @(y a) @(y b))
(Double.= @(z a) @(z b)))))
(vreduce (fn [i v] (and i v)) true &(zip = a b)))
(defn /= [a b]
(not (= a b)))
(doc vapprox "Check whether the vectors a and b are approximately equal.")
(defn vapprox [a b]
(vreduce (fn [i v] (and i v)) true &(zip approx a b)))
(defn add [a b]
(init (+ @(x a) @(x b))
(+ @(y a) @(y b))
(+ @(z a) @(z b))))
(zip + a b))
(defn sub [a b]
(init (- @(x a) @(x b))
(- @(y a) @(y b))
(- @(z a) @(z b))))
(zip - a b))
(defn mul [a n]
(init (* @(x a) n)
(* @(y a) n)
(* @(z a) n)))
(defn cmul [a b]
(zip * a b))
(defn div [a n]
(init (/ @(x a) n)
(/ @(y a) n)
(/ @(z a) n)))
(defn neg [a]
(map neg a))
(defn mul [v n]
(map (fn [c] (* n c)) v))
(defn div [v n]
(map (fn [c] (/ c n)) v))
(defn sum [o]
(vreduce + (zero) o))
(doc dot "Get the dot product of the two vectors x and y.")
(defn dot [a b]
(sum &(zip * a b)))
(doc mag-sq "Get the squared magnitude of a vector.")
(defn mag-sq [o]
(let [x @(x o)
y @(y o)
z @(z o)]
(+ (* x x) (+ (* y y) (* z z)))))
(dot o o))
(doc mag "Get the magnitude of a vector.")
(defn mag [o]
(Double.sqrt (mag-sq o)))
(sqrt (mag-sq o)))
(doc normalize "Normalize a vector.")
(defn normalize [o]
(let [m (mag o)]
(if (= m 0.0)
(if (= m (zero))
@o
(div o m))))
(doc dist "Get the distance between the vectors a and b.")
(defn dist [a b]
(let [s (sub b a)]
(mag &s)))
(doc cross "Compute the cross product of the two vectors x and y.")
(defn cross [a b]
(init
@ -160,50 +188,38 @@
(- (* @(x a) @(y b))
(* @(y a) @(x b)))))
(doc dot "Get the dot product of the two vectors x and y.")
(defn dot [a b]
(+ (* @(x a) @(x b))
(+ (* @(y a) @(y b))
(* @(z a) @(z b)))))
(doc angle-between "Get the angle between to vectors a and b.")
(doc angle-between "Get the angle between two vectors a and b.")
(defn angle-between [a b]
(let [dmm (/ (dot a b) (* (mag a) (mag b)))]
(Double.acos (Double.clamp -1.0 1.0 dmm))))
(acos (clamp--1-1 dmm))))
(doc anti-parallel? "Check whether the two vectors a and b are anti-parallel.")
(defn anti-parallel? [a b]
(= (angle-between a b) Double.pi))
(= (angle-between a b) pi))
(doc parallel? "Check whether the two vectors a and b are parallel.")
(defn parallel? [a b]
(= (angle-between a b) 0.0))
(zero? (angle-between a b)))
(doc perpendicular? "Check whether the two vectors a and b are perpendicular.")
(defn perpendicular? [a b]
(= (angle-between a b) (/ Double.pi 2.0)))
(= (angle-between a b) (half-pi)))
(doc lerp "Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).")
(defn lerp [a b amnt]
(init (* (- @(x b) @(x a)) amnt)
(* (- @(y b) @(y a)) amnt)
(* (- @(z b) @(z a)) amnt)))
(doc vlerp "Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).")
(defn vlerp [a b amnt]
(zip (fn [a b] (lerp a b amnt)) a b))
)
(deftype (VectorN a) [n Int, v (Array a)])
(deftype (VectorN f) [n Int, v (Array f)])
(defmodule VectorN
(defn zero-sized [n]
(let [z 0.0]
(let [z (zero)]
(init n (Array.replicate n &z))))
(private unit-random)
(hidden unit-random)
(defn unit-random []
(random-between 0.0 1.0))
(defn random-sized [n]
(init n (Array.repeat n &unit-random)))
(init n (Array.repeat n &random-0-1)))
(defn zip- [f a b]
(let [total (Array.allocate (Array.length a))]
@ -237,14 +253,18 @@
(defn div [a n]
(zip- / (v a) &(Array.replicate @(VectorN.n a) &n)))
(doc dot "Get the dot product of the two vectors x and y.")
(defn dot [x y]
(Maybe.apply (zip * x y)
(fn [x] (Array.reduce &(fn [x y] (+ x @y)) (zero) (v &x)))))
(doc mag-sq "Get the squared magnitude of a vector.")
(defn mag-sq [o]
(Array.reduce &(fn [x y] (+ x @y)) 0.0
&(Array.copy-map &(fn [x] (* @x @x)) (v o))))
(Maybe.unsafe-from (dot o o)))
(doc mag "Get the magnitude of a vector.")
(defn mag [o]
(Double.sqrt (mag-sq o)))
(sqrt (mag-sq o)))
(doc dist "Get the distance between the vectors a and b.")
(defn dist [a b]
@ -253,37 +273,35 @@
(doc normalize "Normalize a vector.")
(defn normalize [o]
(let [m (mag o)]
(if (= m 0.0)
(if (zero? m)
@o
(div o m))))
(doc dot "Get the dot product of the two vectors x and y.")
(defn dot [x y]
(Maybe.apply (zip * x y)
(fn [x] (Array.reduce &(fn [x y] (+ x @y)) 0.0 (v &x)))))
(doc angle-between "Get the angle between to vectors a and b.")
(doc angle-between "Get the angle between two vectors a and b.")
(defn angle-between [a b]
(Maybe.apply (dot a b)
(Maybe.apply (VectorN.dot a b)
(fn [x]
(let [dmm (/ x (* (mag a) (mag b)))]
(Double.acos (Double.clamp -1.0 1.0 dmm))))))
(let [dmm (/ x (* (VectorN.mag a) (VectorN.mag b)))]
(acos (clamp--1-1 dmm))))))
(doc anti-parallel? "Check whether the two vectors a and b are anti-parallel.")
(defn anti-parallel? [a b]
(Maybe.apply (angle-between a b) (fn [x] (= x Double.pi))))
(Maybe.apply (angle-between a b) (fn [x] (= x pi))))
(doc parallel? "Check whether the two vectors a and b are parallel.")
(defn parallel? [a b]
(Maybe.apply (angle-between a b) (fn [x] (= x 0.0))))
(Maybe.apply (angle-between a b) (fn [x] (zero? x))))
(doc perpendicular? "Check whether the two vectors a and b are perpendicular.")
(defn perpendicular? [a b]
(Maybe.apply (angle-between a b) (fn [x] (= x (/ Double.pi 2.0)))))
(Maybe.apply (angle-between a b) (fn [x] (= x (half-pi)))))
(doc lerp "Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).")
(defn lerp [a b amnt]
(Maybe.apply (zip - b a)
(fn [x] (init @(n a) @(v &(zip- * &(Array.replicate @(n a) &amnt)
(v &x)))))))
(doc vlerp "Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).")
(defn vlerp [a b amnt]
(zip (fn [a b] (lerp a b amnt)) a b))
(defn workaround-516 []
(match (Maybe.Nothing)
(Maybe.Just x) (if x 0 1)
(Maybe.Nothing) 2))
)

View File

@ -1,7 +1,10 @@
#include <float.h>
#include <limits.h>
#include <math.h>
#include "carp_stdbool.h"
const double CARP_DBL_MAX = DBL_MAX;
double Double__PLUS_(double x, double y) { return x + y; }
double Double__MINUS_(double x, double y) { return x - y; }
double Double__MUL_(double x, double y) { return x * y; }

View File

@ -1,7 +1,10 @@
#include <float.h>
#include <limits.h>
#include <math.h>
#include "carp_stdbool.h"
const float CARP_FLT_MAX = FLT_MAX;
float Float__PLUS_(float x, float y) { return x + y; }
float Float__MINUS_(float x, float y) { return x - y; }
float Float__MUL_(float x, float y) { return x * y; }

View File

@ -1010,7 +1010,7 @@
(repeat-indexed n f)
</pre>
<p class="doc">
<p>repeats function <code>f</code> <code>n</code>times and stores the results in an array.</p>
<p>repeats function <code>f</code> <code>n</code> times and stores the results in an array.</p>
<p>This is similar to <a href="#repeat"><code>repeat</code></a>, but the function <code>f</code> will be supplied with the index of the element.</p>
</p>

View File

@ -293,6 +293,25 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#MAX">
<h3 id="MAX">
MAX
</h3>
</a>
<div class="description">
external
</div>
<p class="sig">
Double
</p>
<span>
</span>
<p class="doc">
</p>
</div>
<div class="binder">
<a class="anchor" href="#abs">
<h3 id="abs">
@ -360,7 +379,7 @@
defn
</div>
<p class="sig">
(λ [Double, Double] Bool)
(λ [a, a] Bool)
</p>
<pre class="args">
(approx x y)
@ -447,25 +466,6 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#clamp">
<h3 id="clamp">
clamp
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [a, a, a] a)
</p>
<pre class="args">
(clamp min max val)
</pre>
<p class="doc">
</p>
</div>
<div class="binder">
<a class="anchor" href="#copy">
<h3 id="copy">
@ -523,6 +523,25 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#dec">
<h3 id="dec">
dec
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [Double] Double)
</p>
<pre class="args">
(dec x)
</pre>
<p class="doc">
</p>
</div>
<div class="binder">
<a class="anchor" href="#e">
<h3 id="e">
@ -694,6 +713,25 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#inc">
<h3 id="inc">
inc
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [Double] Double)
</p>
<pre class="args">
(inc x)
</pre>
<p class="doc">
</p>
</div>
<div class="binder">
<a class="anchor" href="#ldexp">
<h3 id="ldexp">

View File

@ -293,6 +293,25 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#MAX">
<h3 id="MAX">
MAX
</h3>
</a>
<div class="description">
external
</div>
<p class="sig">
Float
</p>
<span>
</span>
<p class="doc">
</p>
</div>
<div class="binder">
<a class="anchor" href="#abs">
<h3 id="abs">
@ -360,7 +379,7 @@
defn
</div>
<p class="sig">
(λ [Float, Float] Bool)
(λ [a, a] Bool)
</p>
<pre class="args">
(approx x y)
@ -523,6 +542,25 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#dec">
<h3 id="dec">
dec
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [Float] Float)
</p>
<pre class="args">
(dec x)
</pre>
<p class="doc">
</p>
</div>
<div class="binder">
<a class="anchor" href="#exp">
<h3 id="exp">
@ -637,6 +675,25 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#inc">
<h3 id="inc">
inc
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [Float] Float)
</p>
<pre class="args">
(inc x)
</pre>
<p class="doc">
</p>
</div>
<div class="binder">
<a class="anchor" href="#ldexp">
<h3 id="ldexp">

View File

@ -151,7 +151,7 @@
defn
</div>
<p class="sig">
(λ [Double] Double)
(λ [a] a)
</p>
<pre class="args">
(degree-to-radians n)
@ -171,7 +171,7 @@
defn
</div>
<p class="sig">
(λ [Double] Double)
(λ [a] a)
</p>
<pre class="args">
(radians-to-degree n)

View File

@ -170,7 +170,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (Vector2 Double)), (Ref (Vector2 Double))] Bool)
(λ [(Ref (Vector2 a)), (Ref (Vector2 a))] Bool)
</p>
<pre class="args">
(= a b)
@ -208,13 +208,13 @@
defn
</div>
<p class="sig">
(λ [(Ref (Vector2 Double)), (Ref (Vector2 Double))] Double)
(λ [(Ref (Vector2 a)), (Ref (Vector2 a))] a)
</p>
<pre class="args">
(angle-between a b)
</pre>
<p class="doc">
<p>Get the angle between to vectors a and b.</p>
<p>Get the angle between two vectors a and b.</p>
</p>
</div>
@ -228,7 +228,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (Vector2 Double)), (Ref (Vector2 Double))] Bool)
(λ [(Ref (Vector2 a)), (Ref (Vector2 a))] Bool)
</p>
<pre class="args">
(anti-parallel? a b)
@ -238,26 +238,6 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#approx">
<h3 id="approx">
approx
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(Ref (Vector2 Double)), (Ref (Vector2 Double))] Bool)
</p>
<pre class="args">
(approx a b)
</pre>
<p class="doc">
<p>Check whether the vectors a and b are approximately equal.</p>
</p>
</div>
<div class="binder">
<a class="anchor" href="#copy">
<h3 id="copy">
@ -268,7 +248,7 @@
template
</div>
<p class="sig">
(λ [(Ref (Vector2 a))] (Vector2 a))
(λ [(Ref (Vector2 f))] (Vector2 f))
</p>
<span>
@ -288,7 +268,7 @@
template
</div>
<p class="sig">
(λ [(Vector2 a)] ())
(λ [(Vector2 f)] ())
</p>
<span>
@ -308,7 +288,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (Vector2 Double)), (Ref (Vector2 Double))] Double)
(λ [(Ref (Vector2 a)), (Ref (Vector2 a))] a)
</p>
<pre class="args">
(dist a b)
@ -367,7 +347,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (Vector2 Double))] Double)
(λ [(Ref (Vector2 a))] a)
</p>
<pre class="args">
(heading a)
@ -387,7 +367,7 @@
template
</div>
<p class="sig">
(λ [a, a] (Vector2 a))
(λ [f, f] (Vector2 f))
</p>
<span>
@ -397,26 +377,6 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#lerp">
<h3 id="lerp">
lerp
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(Ref (Vector2 a)), (Ref (Vector2 a)), a] (Vector2 a))
</p>
<pre class="args">
(lerp a b amnt)
</pre>
<p class="doc">
<p>Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).</p>
</p>
</div>
<div class="binder">
<a class="anchor" href="#mag">
<h3 id="mag">
@ -427,7 +387,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (Vector2 Double))] Double)
(λ [(Ref (Vector2 a))] a)
</p>
<pre class="args">
(mag o)
@ -457,6 +417,25 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#map">
<h3 id="map">
map
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(λ [a] b), (Ref (Vector2 a))] (Vector2 b))
</p>
<pre class="args">
(map f v)
</pre>
<p class="doc">
</p>
</div>
<div class="binder">
<a class="anchor" href="#mul">
<h3 id="mul">
@ -486,7 +465,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (Vector2 Double))] (Vector2 Double))
(λ [(Ref (Vector2 a))] (Vector2 a))
</p>
<pre class="args">
(normalize o)
@ -506,7 +485,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (Vector2 Double)), (Ref (Vector2 Double))] Bool)
(λ [(Ref (Vector2 a)), (Ref (Vector2 a))] Bool)
</p>
<pre class="args">
(parallel? a b)
@ -526,7 +505,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (Vector2 Double)), (Ref (Vector2 Double))] Bool)
(λ [(Ref (Vector2 a)), (Ref (Vector2 a))] Bool)
</p>
<pre class="args">
(perpendicular? a b)
@ -546,7 +525,7 @@
template
</div>
<p class="sig">
(λ [(Ref (Vector2 a))] String)
(λ [(Ref (Vector2 f))] String)
</p>
<span>
@ -566,7 +545,7 @@
defn
</div>
<p class="sig">
(λ [] (Vector2 Double))
(λ [] (Vector2 a))
</p>
<pre class="args">
(random)
@ -585,7 +564,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (Vector2 Double)), Double] (Vector2 Double))
(λ [(Ref (Vector2 a)), a] (Vector2 a))
</p>
<pre class="args">
(rotate a n)
@ -605,7 +584,7 @@
template
</div>
<p class="sig">
(λ [(Vector2 a), a] (Vector2 a))
(λ [(Vector2 f), f] (Vector2 f))
</p>
<span>
@ -625,7 +604,7 @@
instantiate
</div>
<p class="sig">
(λ [(Ref (Vector2 a)), a] ())
(λ [(Ref (Vector2 f)), f] ())
</p>
<span>
@ -645,7 +624,7 @@
template
</div>
<p class="sig">
(λ [(Vector2 a), a] (Vector2 a))
(λ [(Vector2 f), f] (Vector2 f))
</p>
<span>
@ -665,7 +644,7 @@
instantiate
</div>
<p class="sig">
(λ [(Ref (Vector2 a)), a] ())
(λ [(Ref (Vector2 f)), f] ())
</p>
<span>
@ -685,7 +664,7 @@
template
</div>
<p class="sig">
(λ [(Ref (Vector2 a))] String)
(λ [(Ref (Vector2 f))] String)
</p>
<span>
@ -714,6 +693,25 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#sum">
<h3 id="sum">
sum
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(Ref (Vector2 a))] a)
</p>
<pre class="args">
(sum o)
</pre>
<p class="doc">
</p>
</div>
<div class="binder">
<a class="anchor" href="#update-x">
<h3 id="update-x">
@ -724,7 +722,7 @@
instantiate
</div>
<p class="sig">
(λ [(Vector2 a), (Ref (λ [a] a))] (Vector2 a))
(λ [(Vector2 f), (Ref (λ [f] f))] (Vector2 f))
</p>
<span>
@ -744,7 +742,7 @@
instantiate
</div>
<p class="sig">
(λ [(Vector2 a), (Ref (λ [a] a))] (Vector2 a))
(λ [(Vector2 f), (Ref (λ [f] f))] (Vector2 f))
</p>
<span>
@ -754,6 +752,65 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#vapprox">
<h3 id="vapprox">
vapprox
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(Ref (Vector2 a)), (Ref (Vector2 a))] Bool)
</p>
<pre class="args">
(vapprox a b)
</pre>
<p class="doc">
<p>Check whether the vectors a and b are approximately equal.</p>
</p>
</div>
<div class="binder">
<a class="anchor" href="#vlerp">
<h3 id="vlerp">
vlerp
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(Ref (Vector2 a)), (Ref (Vector2 a)), a] (Vector2 a))
</p>
<pre class="args">
(vlerp a b amnt)
</pre>
<p class="doc">
<p>Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).</p>
</p>
</div>
<div class="binder">
<a class="anchor" href="#vreduce">
<h3 id="vreduce">
vreduce
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(λ [a, b] a), a, (Ref (Vector2 b))] a)
</p>
<pre class="args">
(vreduce f i v)
</pre>
<p class="doc">
</p>
</div>
<div class="binder">
<a class="anchor" href="#x">
<h3 id="x">
@ -764,7 +821,7 @@
instantiate
</div>
<p class="sig">
(λ [(Ref (Vector2 a))] &amp;a)
(λ [(Ref (Vector2 f))] &amp;f)
</p>
<span>
@ -784,7 +841,7 @@
instantiate
</div>
<p class="sig">
(λ [(Ref (Vector2 a))] &amp;a)
(λ [(Ref (Vector2 f))] &amp;f)
</p>
<span>
@ -804,13 +861,32 @@
defn
</div>
<p class="sig">
(λ [] (Vector2 Double))
(λ [] (Vector2 a))
</p>
<pre class="args">
(zero)
</pre>
<p class="doc">
</p>
</div>
<div class="binder">
<a class="anchor" href="#zip">
<h3 id="zip">
zip
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(λ [a, b] c), (Ref (Vector2 a)), (Ref (Vector2 b))] (Vector2 c))
</p>
<pre class="args">
(zip f a b)
</pre>
<p class="doc">
</p>
</div>
</div>

View File

@ -170,7 +170,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (Vector3 Double)), (Ref (Vector3 Double))] Bool)
(λ [(Ref (Vector3 a)), (Ref (Vector3 a))] Bool)
</p>
<pre class="args">
(= a b)
@ -208,13 +208,13 @@
defn
</div>
<p class="sig">
(λ [(Ref (Vector3 Double)), (Ref (Vector3 Double))] Double)
(λ [(Ref (Vector3 a)), (Ref (Vector3 a))] a)
</p>
<pre class="args">
(angle-between a b)
</pre>
<p class="doc">
<p>Get the angle between to vectors a and b.</p>
<p>Get the angle between two vectors a and b.</p>
</p>
</div>
@ -228,7 +228,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (Vector3 Double)), (Ref (Vector3 Double))] Bool)
(λ [(Ref (Vector3 a)), (Ref (Vector3 a))] Bool)
</p>
<pre class="args">
(anti-parallel? a b)
@ -238,6 +238,25 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#cmul">
<h3 id="cmul">
cmul
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(Ref (Vector3 a)), (Ref (Vector3 a))] (Vector3 a))
</p>
<pre class="args">
(cmul a b)
</pre>
<p class="doc">
</p>
</div>
<div class="binder">
<a class="anchor" href="#copy">
<h3 id="copy">
@ -248,7 +267,7 @@
template
</div>
<p class="sig">
(λ [(Ref (Vector3 a))] (Vector3 a))
(λ [(Ref (Vector3 f))] (Vector3 f))
</p>
<span>
@ -288,7 +307,7 @@
template
</div>
<p class="sig">
(λ [(Vector3 a)] ())
(λ [(Vector3 f)] ())
</p>
<span>
@ -298,6 +317,26 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#dist">
<h3 id="dist">
dist
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(Ref (Vector3 a)), (Ref (Vector3 a))] a)
</p>
<pre class="args">
(dist a b)
</pre>
<p class="doc">
<p>Get the distance between the vectors a and b.</p>
</p>
</div>
<div class="binder">
<a class="anchor" href="#div">
<h3 id="div">
@ -311,7 +350,7 @@
(λ [(Ref (Vector3 a)), a] (Vector3 a))
</p>
<pre class="args">
(div a n)
(div v n)
</pre>
<p class="doc">
@ -347,7 +386,7 @@
template
</div>
<p class="sig">
(λ [a, a, a] (Vector3 a))
(λ [f, f, f] (Vector3 f))
</p>
<span>
@ -357,26 +396,6 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#lerp">
<h3 id="lerp">
lerp
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(Ref (Vector3 a)), (Ref (Vector3 a)), a] (Vector3 a))
</p>
<pre class="args">
(lerp a b amnt)
</pre>
<p class="doc">
<p>Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).</p>
</p>
</div>
<div class="binder">
<a class="anchor" href="#mag">
<h3 id="mag">
@ -387,7 +406,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (Vector3 Double))] Double)
(λ [(Ref (Vector3 a))] a)
</p>
<pre class="args">
(mag o)
@ -417,6 +436,25 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#map">
<h3 id="map">
map
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(λ [a] b), (Ref (Vector3 a))] (Vector3 b))
</p>
<pre class="args">
(map f v)
</pre>
<p class="doc">
</p>
</div>
<div class="binder">
<a class="anchor" href="#mul">
<h3 id="mul">
@ -430,7 +468,26 @@
(λ [(Ref (Vector3 a)), a] (Vector3 a))
</p>
<pre class="args">
(mul a n)
(mul v n)
</pre>
<p class="doc">
</p>
</div>
<div class="binder">
<a class="anchor" href="#neg">
<h3 id="neg">
neg
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(Ref (Vector3 a))] (Vector3 a))
</p>
<pre class="args">
(neg a)
</pre>
<p class="doc">
@ -446,7 +503,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (Vector3 Double))] (Vector3 Double))
(λ [(Ref (Vector3 a))] (Vector3 a))
</p>
<pre class="args">
(normalize o)
@ -466,7 +523,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (Vector3 Double)), (Ref (Vector3 Double))] Bool)
(λ [(Ref (Vector3 a)), (Ref (Vector3 a))] Bool)
</p>
<pre class="args">
(parallel? a b)
@ -486,7 +543,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (Vector3 Double)), (Ref (Vector3 Double))] Bool)
(λ [(Ref (Vector3 a)), (Ref (Vector3 a))] Bool)
</p>
<pre class="args">
(perpendicular? a b)
@ -506,7 +563,7 @@
template
</div>
<p class="sig">
(λ [(Ref (Vector3 a))] String)
(λ [(Ref (Vector3 f))] String)
</p>
<span>
@ -526,7 +583,7 @@
defn
</div>
<p class="sig">
(λ [] (Vector3 Double))
(λ [] (Vector3 a))
</p>
<pre class="args">
(random)
@ -545,7 +602,7 @@
template
</div>
<p class="sig">
(λ [(Vector3 a), a] (Vector3 a))
(λ [(Vector3 f), f] (Vector3 f))
</p>
<span>
@ -565,7 +622,7 @@
instantiate
</div>
<p class="sig">
(λ [(Ref (Vector3 a)), a] ())
(λ [(Ref (Vector3 f)), f] ())
</p>
<span>
@ -585,7 +642,7 @@
template
</div>
<p class="sig">
(λ [(Vector3 a), a] (Vector3 a))
(λ [(Vector3 f), f] (Vector3 f))
</p>
<span>
@ -605,7 +662,7 @@
instantiate
</div>
<p class="sig">
(λ [(Ref (Vector3 a)), a] ())
(λ [(Ref (Vector3 f)), f] ())
</p>
<span>
@ -625,7 +682,7 @@
template
</div>
<p class="sig">
(λ [(Vector3 a), a] (Vector3 a))
(λ [(Vector3 f), f] (Vector3 f))
</p>
<span>
@ -645,7 +702,7 @@
instantiate
</div>
<p class="sig">
(λ [(Ref (Vector3 a)), a] ())
(λ [(Ref (Vector3 f)), f] ())
</p>
<span>
@ -665,7 +722,7 @@
template
</div>
<p class="sig">
(λ [(Ref (Vector3 a))] String)
(λ [(Ref (Vector3 f))] String)
</p>
<span>
@ -694,6 +751,25 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#sum">
<h3 id="sum">
sum
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(Ref (Vector3 a))] a)
</p>
<pre class="args">
(sum o)
</pre>
<p class="doc">
</p>
</div>
<div class="binder">
<a class="anchor" href="#update-x">
<h3 id="update-x">
@ -704,7 +780,7 @@
instantiate
</div>
<p class="sig">
(λ [(Vector3 a), (Ref (λ [a] a))] (Vector3 a))
(λ [(Vector3 f), (Ref (λ [f] f))] (Vector3 f))
</p>
<span>
@ -724,7 +800,7 @@
instantiate
</div>
<p class="sig">
(λ [(Vector3 a), (Ref (λ [a] a))] (Vector3 a))
(λ [(Vector3 f), (Ref (λ [f] f))] (Vector3 f))
</p>
<span>
@ -744,7 +820,7 @@
instantiate
</div>
<p class="sig">
(λ [(Vector3 a), (Ref (λ [a] a))] (Vector3 a))
(λ [(Vector3 f), (Ref (λ [f] f))] (Vector3 f))
</p>
<span>
@ -754,6 +830,65 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#vapprox">
<h3 id="vapprox">
vapprox
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(Ref (Vector3 a)), (Ref (Vector3 a))] Bool)
</p>
<pre class="args">
(vapprox a b)
</pre>
<p class="doc">
<p>Check whether the vectors a and b are approximately equal.</p>
</p>
</div>
<div class="binder">
<a class="anchor" href="#vlerp">
<h3 id="vlerp">
vlerp
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(Ref (Vector3 a)), (Ref (Vector3 a)), a] (Vector3 a))
</p>
<pre class="args">
(vlerp a b amnt)
</pre>
<p class="doc">
<p>Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).</p>
</p>
</div>
<div class="binder">
<a class="anchor" href="#vreduce">
<h3 id="vreduce">
vreduce
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(λ [a, b] a), a, (Ref (Vector3 b))] a)
</p>
<pre class="args">
(vreduce f i v)
</pre>
<p class="doc">
</p>
</div>
<div class="binder">
<a class="anchor" href="#x">
<h3 id="x">
@ -764,7 +899,7 @@
instantiate
</div>
<p class="sig">
(λ [(Ref (Vector3 a))] &amp;a)
(λ [(Ref (Vector3 f))] &amp;f)
</p>
<span>
@ -784,7 +919,7 @@
instantiate
</div>
<p class="sig">
(λ [(Ref (Vector3 a))] &amp;a)
(λ [(Ref (Vector3 f))] &amp;f)
</p>
<span>
@ -804,7 +939,7 @@
instantiate
</div>
<p class="sig">
(λ [(Ref (Vector3 a))] &amp;a)
(λ [(Ref (Vector3 f))] &amp;f)
</p>
<span>
@ -824,13 +959,32 @@
defn
</div>
<p class="sig">
(λ [] (Vector3 Double))
(λ [] (Vector3 a))
</p>
<pre class="args">
(zero)
</pre>
<p class="doc">
</p>
</div>
<div class="binder">
<a class="anchor" href="#zip">
<h3 id="zip">
zip
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(λ [a, b] c), (Ref (Vector3 a)), (Ref (Vector3 b))] (Vector3 c))
</p>
<pre class="args">
(zip f a b)
</pre>
<p class="doc">
</p>
</div>
</div>

View File

@ -208,13 +208,13 @@
defn
</div>
<p class="sig">
(λ [(Ref (VectorN Double)), (Ref (VectorN Double))] (Maybe Double))
(λ [(Ref (VectorN a)), (Ref (VectorN a))] (Maybe a))
</p>
<pre class="args">
(angle-between a b)
</pre>
<p class="doc">
<p>Get the angle between to vectors a and b.</p>
<p>Get the angle between two vectors a and b.</p>
</p>
</div>
@ -228,7 +228,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (VectorN Double)), (Ref (VectorN Double))] (Maybe Bool))
(λ [(Ref (VectorN a)), (Ref (VectorN a))] (Maybe Bool))
</p>
<pre class="args">
(anti-parallel? a b)
@ -248,7 +248,7 @@
template
</div>
<p class="sig">
(λ [(Ref (VectorN a))] (VectorN a))
(λ [(Ref (VectorN f))] (VectorN f))
</p>
<span>
@ -268,7 +268,7 @@
template
</div>
<p class="sig">
(λ [(VectorN a)] ())
(λ [(VectorN f)] ())
</p>
<span>
@ -288,7 +288,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (VectorN Double)), (Ref (VectorN Double))] (Maybe Double))
(λ [(Ref (VectorN a)), (Ref (VectorN a))] (Maybe a))
</p>
<pre class="args">
(dist a b)
@ -327,7 +327,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (VectorN Double)), (Ref (VectorN Double))] (Maybe Double))
(λ [(Ref (VectorN a)), (Ref (VectorN a))] (Maybe a))
</p>
<pre class="args">
(dot x y)
@ -347,7 +347,7 @@
template
</div>
<p class="sig">
(λ [Int, (Array a)] (VectorN a))
(λ [Int, (Array f)] (VectorN f))
</p>
<span>
@ -357,26 +357,6 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#lerp">
<h3 id="lerp">
lerp
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(Ref (VectorN a)), (Ref (VectorN a)), a] (Maybe (VectorN a)))
</p>
<pre class="args">
(lerp a b amnt)
</pre>
<p class="doc">
<p>Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).</p>
</p>
</div>
<div class="binder">
<a class="anchor" href="#mag">
<h3 id="mag">
@ -387,7 +367,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (VectorN Double))] Double)
(λ [(Ref (VectorN a))] a)
</p>
<pre class="args">
(mag o)
@ -407,7 +387,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (VectorN Double))] Double)
(λ [(Ref (VectorN a))] a)
</p>
<pre class="args">
(mag-sq o)
@ -446,7 +426,7 @@
instantiate
</div>
<p class="sig">
(λ [(Ref (VectorN a))] &amp;Int)
(λ [(Ref (VectorN f))] &amp;Int)
</p>
<span>
@ -466,7 +446,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (VectorN Double))] (VectorN Double))
(λ [(Ref (VectorN a))] (VectorN a))
</p>
<pre class="args">
(normalize o)
@ -486,7 +466,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (VectorN Double)), (Ref (VectorN Double))] (Maybe Bool))
(λ [(Ref (VectorN a)), (Ref (VectorN a))] (Maybe Bool))
</p>
<pre class="args">
(parallel? a b)
@ -506,7 +486,7 @@
defn
</div>
<p class="sig">
(λ [(Ref (VectorN Double)), (Ref (VectorN Double))] (Maybe Bool))
(λ [(Ref (VectorN a)), (Ref (VectorN a))] (Maybe Bool))
</p>
<pre class="args">
(perpendicular? a b)
@ -526,7 +506,7 @@
template
</div>
<p class="sig">
(λ [(Ref (VectorN a))] String)
(λ [(Ref (VectorN f))] String)
</p>
<span>
@ -546,7 +526,7 @@
defn
</div>
<p class="sig">
(λ [Int] (VectorN Double))
(λ [Int] (VectorN a))
</p>
<pre class="args">
(random-sized n)
@ -565,7 +545,7 @@
instantiate
</div>
<p class="sig">
(λ [(VectorN a), Int] (VectorN a))
(λ [(VectorN f), Int] (VectorN f))
</p>
<span>
@ -585,7 +565,7 @@
instantiate
</div>
<p class="sig">
(λ [(Ref (VectorN a)), Int] ())
(λ [(Ref (VectorN f)), Int] ())
</p>
<span>
@ -605,7 +585,7 @@
template
</div>
<p class="sig">
(λ [(VectorN a), (Array a)] (VectorN a))
(λ [(VectorN f), (Array f)] (VectorN f))
</p>
<span>
@ -625,7 +605,7 @@
instantiate
</div>
<p class="sig">
(λ [(Ref (VectorN a)), (Array a)] ())
(λ [(Ref (VectorN f)), (Array f)] ())
</p>
<span>
@ -645,7 +625,7 @@
template
</div>
<p class="sig">
(λ [(Ref (VectorN a))] String)
(λ [(Ref (VectorN f))] String)
</p>
<span>
@ -684,7 +664,7 @@
instantiate
</div>
<p class="sig">
(λ [(VectorN a), (Ref (λ [Int] Int))] (VectorN a))
(λ [(VectorN f), (Ref (λ [Int] Int))] (VectorN f))
</p>
<span>
@ -704,7 +684,7 @@
instantiate
</div>
<p class="sig">
(λ [(VectorN a), (Ref (λ [(Array a)] (Array a)))] (VectorN a))
(λ [(VectorN f), (Ref (λ [(Array f)] (Array f)))] (VectorN f))
</p>
<span>
@ -724,7 +704,7 @@
instantiate
</div>
<p class="sig">
(λ [(Ref (VectorN a))] (Ref (Array a)))
(λ [(Ref (VectorN f))] (Ref (Array f)))
</p>
<span>
@ -734,6 +714,45 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#vlerp">
<h3 id="vlerp">
vlerp
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [(Ref (VectorN a)), (Ref (VectorN a)), a] (Maybe (VectorN a)))
</p>
<pre class="args">
(vlerp a b amnt)
</pre>
<p class="doc">
<p>Linearly interpolate between the two vectors a and b by amnt (between 0 and 1).</p>
</p>
</div>
<div class="binder">
<a class="anchor" href="#workaround-516">
<h3 id="workaround-516">
workaround-516
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [] Int)
</p>
<pre class="args">
(workaround-516)
</pre>
<p class="doc">
</p>
</div>
<div class="binder">
<a class="anchor" href="#zero-sized">
<h3 id="zero-sized">
@ -744,7 +763,7 @@
defn
</div>
<p class="sig">
(λ [Int] (VectorN Double))
(λ [Int] (VectorN a))
</p>
<pre class="args">
(zero-sized n)

View File

@ -6,7 +6,7 @@
(deftest test
(assert-equal test
&(init 0.0 0.0) &(zero)
&(init 0.0 0.0) &(Vector2.zero)
"zero works")
(assert-equal test
&(init 1.0 2.0) &(init 1.0 2.0)
@ -55,7 +55,7 @@
&(init -2.0 1.0)
&(rotate &(init 1.0 2.0) (degree-to-radians 90.0))
"rotate works"
approx)
vapprox)
(assert-equal test
90.0
(radians-to-degree (Vector2.angle-between &(init 1.0 0.0) &(init 0.0 1.0)))
@ -75,6 +75,6 @@
"dot works")
(assert-equal test
&(init 2.5 5.0)
&(lerp &(init 0.0 0.0) &(init 5.0 10.0) 0.5)
"lerp works")
&(vlerp &(Vector2.zero) &(init 5.0 10.0) 0.5)
"vlerp works")
)

View File

@ -6,7 +6,7 @@
(deftest test
(assert-equal test
&(init 0.0 0.0 0.0) &(zero)
&(init 0.0 0.0 0.0) &(Vector3.zero)
"zero works")
(assert-equal test
&(init 1.0 2.0 3.0) &(init 1.0 2.0 3.0)
@ -15,6 +15,10 @@
&(init 1.0 2.0 3.0) &(init 1.0 1.0 3.0)
"/= operator works"
Vector3./=)
(assert-op test
&(init 1.0 2.0 3.0) &(init 1.000001 2.000001 3.000001)
"approx works"
vapprox)
(assert-equal test
&(init 3.0 3.0 4.5)
&(add &(init 2.0 1.0 2.0) &(init 1.0 2.0 2.5))
@ -27,6 +31,10 @@
&(init 4.0 2.0 2.2)
&(mul &(init 2.0 1.0 1.1) 2.0)
"mul operator works")
(assert-equal test
&(init 4.0f 2.0f 2.2f)
&(mul &(init 2.0f 1.0f 1.1f) 2.0f)
"float mul operator works")
(assert-equal test
&(init 1.0 0.5 0.25)
&(div &(init 2.0 1.0 0.5) 2.0)
@ -63,7 +71,9 @@
(dot &(init 10.0 2.0 3.0) &(init 2.0 12.0 3.0))
"dot works")
(assert-equal test
&(init 2.5 5.0 0.75)
&(lerp &(init 0.0 0.0 0.5) &(init 5.0 10.0 2.0) 0.5)
"lerp works")
&(init 2.5 5.0 1.0)
&(vlerp &(Vector3.zero) &(init 5.0 10.0 2.0) 0.5)
"vlerp works")
)

View File

@ -79,6 +79,6 @@
"dot works")
(assert-equal test
&(init 1 [2.0])
&(Maybe.unsafe-from (lerp &(init 1 [0.0]) &(init 1 [5.0]) 0.4))
"lerp works")
&(Maybe.unsafe-from (vlerp &(init 1 [0.0]) &(init 1 [5.0]) 0.4))
"vlerp works")
)