summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2018-09-10 17:09:50 -0400
committerDavid Thompson <dthompson2@worcester.edu>2018-09-10 17:09:50 -0400
commitc033330cfb6e4489f12ac04ae6ce15b972fa73d7 (patch)
treec027a867bc2abf9bdb50e950c29d89657d912406
parent83270f809d12ffe24b27473a2898d0502c99cc1c (diff)
math: vector: Add vec2*, vec2+, and vec2- procedures.
* chickadee/math/vector.scm (vec2*, vec2+, vec2-): New procedures.
-rw-r--r--chickadee/math/vector.scm21
1 files changed, 21 insertions, 0 deletions
diff --git a/chickadee/math/vector.scm b/chickadee/math/vector.scm
index 2ae9187..da5eef2 100644
--- a/chickadee/math/vector.scm
+++ b/chickadee/math/vector.scm
@@ -39,6 +39,9 @@
vec2-mult!
vec2-add!
vec2-sub!
+ vec2*
+ vec2+
+ vec2-
vec3
vec3?
vec3->pointer
@@ -312,6 +315,24 @@ polar coordinate (R, THETA)."
(set-vec3-y! v (- (vec3-y v) (vec3-y x)))
(set-vec3-z! v (- (vec3-z v) (vec3-z x))))))
+(define-inlinable (vec2* v x)
+ "Multiply V by X."
+ (let ((new (vec2-copy v)))
+ (vec2-mult! new x)
+ new))
+
+(define-inlinable (vec2+ v x)
+ "Add X to V."
+ (let ((new (vec2-copy v)))
+ (vec2-add! new x)
+ new))
+
+(define-inlinable (vec2- v x)
+ "Subtract X from V."
+ (let ((new (vec2-copy v)))
+ (vec2-sub! new x)
+ new))
+
;; Reader macro for vectors.
(define (read-vec chr port)
(define (consume-whitespace port)