summaryrefslogtreecommitdiff
path: root/sly/math
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-12-06 11:19:57 -0500
committerDavid Thompson <dthompson2@worcester.edu>2014-12-06 13:20:49 -0500
commit2c821512f1c1a1dde77de9a9df4d861d41cce0f5 (patch)
treeed2e07c76ff53aa1257ba4a0f14f52590e23ec40 /sly/math
parent30bd4bdf2bf9b18b671538be4749148d02ccfcc3 (diff)
math: vector: Add vmap.
* sly/math/vector.scm (vmap): New procedure.
Diffstat (limited to 'sly/math')
-rw-r--r--sly/math/vector.scm13
1 files changed, 12 insertions, 1 deletions
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 <vector2>
@@ -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
+ (($ <vector2> x y)
+ (vector2 (proc x) (proc y)))
+ (($ <vector3> x y z)
+ (vector3 (proc x) (proc y) (proc z)))
+ (($ <vector4> x y z w)
+ (vector4 (proc x) (proc y) (proc z) (proc w)))))
+
(define-syntax-rule (vector-lambda proc)
(match-lambda*
((($ <vector2> x1 y1) ($ <vector2> x2 y2))