summaryrefslogtreecommitdiff
path: root/2d/transform.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-06-20 08:03:59 -0400
committerDavid Thompson <dthompson2@worcester.edu>2014-06-20 08:03:59 -0400
commit1050850d2498bb2e88f097702fe202c2260c21d2 (patch)
tree310ecf319eefd0053710974262251a792e68b354 /2d/transform.scm
parent7f5b8242552fa4792420302f7765f172108835bd (diff)
Add support for 3D vectors in translate procedure.
* 2d/transform.scm (translate): Support 3D vector as argument.
Diffstat (limited to '2d/transform.scm')
-rw-r--r--2d/transform.scm25
1 files changed, 19 insertions, 6 deletions
diff --git a/2d/transform.scm b/2d/transform.scm
index a1c05ea..ebb30e2 100644
--- a/2d/transform.scm
+++ b/2d/transform.scm
@@ -132,12 +132,25 @@ identity-transform if called without any arguments."
(reduce mul identity-transform transforms))
(define (translate v)
- "Return a new transform that translates the x and y axes by the
-vector V."
- (make-transform 1 0 0 0
- 0 1 0 0
- 0 0 1 0
- (vx v) (vy v) 0 1))
+ "Return a new transform that translates by the 2D or 3D vector V."
+ (cond
+ ((vector2? v)
+ (let ((x (vx v))
+ (y (vy v)))
+ (make-transform 1 0 0 0
+ 0 1 0 0
+ 0 0 1 0
+ x y 0 1)))
+ ((vector3? v)
+ (let ((x (vx v))
+ (y (vy v))
+ (z (vz v)))
+ (make-transform 1 0 0 0
+ 0 1 0 0
+ 0 0 1 0
+ x y z 1)))
+ (else
+ (error "Invalid scaling vector: " v))))
(define (scale v)
"Return a new transform that scales by the 2D vector, 3D vector, or