summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-06-20 08:00:24 -0400
committerDavid Thompson <dthompson2@worcester.edu>2014-06-20 08:01:21 -0400
commit7f5b8242552fa4792420302f7765f172108835bd (patch)
treec776f4177b211d115ecf5ac0edd9bcc459c4d967
parentc8e2b160356afb500c9e2eaeb62279aa2bbc9fd4 (diff)
Add support for 3D vectors and scalars in scale procedure.
* 2d/transform.scm (scale): Support 3D vectors and scalars as arguments.
-rw-r--r--2d/transform.scm31
1 files changed, 25 insertions, 6 deletions
diff --git a/2d/transform.scm b/2d/transform.scm
index 9b7e05d..a1c05ea 100644
--- a/2d/transform.scm
+++ b/2d/transform.scm
@@ -140,12 +140,31 @@ vector V."
(vx v) (vy v) 0 1))
(define (scale v)
- "Return a new transform that scales the X and Y axes by the vector
-V."
- (make-transform (vx v) 0 0 0
- 0 (vy v) 0 0
- 0 0 1 0
- 0 0 0 1))
+ "Return a new transform that scales by the 2D vector, 3D vector, or
+scalar V."
+ (cond
+ ((number? v)
+ (make-transform v 0 0 0
+ 0 v 0 0
+ 0 0 v 0
+ 0 0 0 1))
+ ((vector2? v)
+ (let ((x (vx v))
+ (y (vy v)))
+ (make-transform x 0 0 0
+ 0 y 0 0
+ 0 0 1 0
+ 0 0 0 1)))
+ ((vector3? v)
+ (let ((x (vx v))
+ (y (vy v))
+ (z (vz v)))
+ (make-transform x 0 0 0
+ 0 y 0 0
+ 0 0 z 0
+ 0 0 0 1)))
+ (else
+ (error "Invalid scaling vector: " v))))
(define (rotate-x angle)
"Return a new transform that rotates the X axis by ANGLE radians."