From 2c821512f1c1a1dde77de9a9df4d861d41cce0f5 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 6 Dec 2014 11:19:57 -0500 Subject: math: vector: Add vmap. * sly/math/vector.scm (vmap): New procedure. --- sly/math/vector.scm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sly/math/vector.scm b/sly/math/vector.scm index 717c5f6..33c62d8 100644 --- a/sly/math/vector.scm +++ b/sly/math/vector.scm @@ -32,7 +32,7 @@ vector2 vector3 vector4 vector2? vector3? vector4? vx vy vz vw - v+ v- v* vdot vcross + vmap v+ v- v* vdot vcross magnitude normalize vlerp)) (define-record-type @@ -78,6 +78,17 @@ (define vw vector4-w) +(define (vmap proc v) + "Return a new vector that is the result of applying PROC to each +element of the 2D/3D/4D vector V." + (match v + (($ x y) + (vector2 (proc x) (proc y))) + (($ x y z) + (vector3 (proc x) (proc y) (proc z))) + (($ x y z w) + (vector4 (proc x) (proc y) (proc z) (proc w))))) + (define-syntax-rule (vector-lambda proc) (match-lambda* ((($ x1 y1) ($ x2 y2)) -- cgit v1.2.3