diff options
author | David Thompson <dthompson2@worcester.edu> | 2017-11-12 21:41:10 -0500 |
---|---|---|
committer | David Thompson <dthompson2@worcester.edu> | 2017-11-12 21:41:10 -0500 |
commit | 37359e1b6de63d5434112364c1301f8202a7cfdc (patch) | |
tree | a8f24d1787609e90a8576c892a1355f45bf8ccd3 | |
parent | df67033b839dc0765ecbee66217f077b4d0c986c (diff) |
math: quaternion: Add custom record type printer.
* chickadee/math/quaternion.scm (display-quaternion): New procedure.
-rw-r--r-- | chickadee/math/quaternion.scm | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/chickadee/math/quaternion.scm b/chickadee/math/quaternion.scm index 4df4ffd..cf2b4bc 100644 --- a/chickadee/math/quaternion.scm +++ b/chickadee/math/quaternion.scm @@ -23,7 +23,9 @@ (define-module (chickadee math quaternion) #:use-module (chickadee math) + #:use-module (ice-9 format) #:use-module (srfi srfi-9) + #:use-module (srfi srfi-9 gnu) #:use-module (system foreign) #:export (quaternion quaternion? @@ -88,6 +90,15 @@ "Return the W coordinate of the quaternion Q." (quaternion-ref q 3)) +(define (display-quaternion q port) + (format port "#<quaterion ~f ~f ~f ~f>" + (quaternion-x q) + (quaternion-y q) + (quaternion-z q) + (quaternion-w q))) + +(set-record-type-printer! <quaternion> display-quaternion) + (define-inlinable (quaternion-magnitude q) "Return the magnitude of the quaternion Q." (sqrt |