summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-10-19 15:21:10 -0400
committerDavid Thompson <dthompson2@worcester.edu>2014-10-19 15:25:28 -0400
commitae21c9cc5a72b3fe7a3207a82c8a42d464cd4a15 (patch)
treebb948d24803cb86987490bb42e316c1c1080bc40
parentae7af4e30ff752ca7fa173df8c171c344991f6a1 (diff)
quaternion: Make better use of pattern matching.
* sly/quaternion.scm (axis-angle->quaternion, quaternion->vector, vector->quaternion): Use match-lambda and record destructuring.
-rw-r--r--sly/quaternion.scm24
1 files changed, 11 insertions, 13 deletions
diff --git a/sly/quaternion.scm b/sly/quaternion.scm
index 663b0dd..8f34602 100644
--- a/sly/quaternion.scm
+++ b/sly/quaternion.scm
@@ -94,23 +94,21 @@ Q2 and blending factor DELTA."
(define (axis-angle->quaternion axis theta)
"Convert the rotation of THETA radians about AXIS to a quaternion.
AXIS must be a 3D vector."
- (let* ((cos (cos (/ theta 2)))
- (sin (sin (/ theta 2))))
- (match axis
- ((? vector3? v)
- (make-quaternion cos (* (vx v) sin) (* (vy v) sin) (* (vz v) sin))))))
+ (match axis
+ (($ <vector3> x y z)
+ (let* ((theta/2 (/ theta 2))
+ (sin (sin theta/2)))
+ (make-quaternion (cos theta/2) (* x sin) (* y sin) (* z sin))))))
-(define (quaternion->vector q)
- "Convert the quaternion Q into a 4D vector."
- (match q
+(define quaternion->vector
+ (match-lambda
(($ <quaternion> w x y z)
(vector4 w x y z))))
-(define (vector->quaternion v)
- "Convert the 4D vector V into a quaternion."
- (match v
- ((? vector4? v)
- (make-quaternion (vx v) (vy v) (vz v) (vw v)))))
+(define vector->quaternion
+ (match-lambda
+ (($ <vector4> x y z w)
+ (make-quaternion x y z w))))
(define rotate
(match-lambda*