summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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))