summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2017-08-15 10:21:39 -0400
committerDavid Thompson <dthompson2@worcester.edu>2017-09-13 21:16:30 -0400
commit49565d13e9da2d68ef66dcf1573611725ef24935 (patch)
tree0e2038c900225ec2a6e85c90775fa45c89ac8f70
parent0db3585bc1f75d8f4f2db779d05e63ca345c79de (diff)
math: vector: Add custom record type printers for vectors.
* chickadee/math/vector.scm (display-vec2, display-vec3): New procedures.
-rw-r--r--chickadee/math/vector.scm12
1 files changed, 12 insertions, 0 deletions
diff --git a/chickadee/math/vector.scm b/chickadee/math/vector.scm
index 89b4f33..cdc9b82 100644
--- a/chickadee/math/vector.scm
+++ b/chickadee/math/vector.scm
@@ -16,8 +16,10 @@
;;; <http://www.gnu.org/licenses/>.
(define-module (chickadee math vector)
+ #:use-module (ice-9 format)
#:use-module (rnrs bytevectors)
#:use-module (srfi srfi-9)
+ #:use-module (srfi srfi-9 gnu)
#:use-module (system foreign)
#:use-module (chickadee math)
#:export (vec2
@@ -163,6 +165,16 @@ polar coordinate (R, THETA)."
"Set the z coordinate of the vec3 V to Z."
(vec3-set! v 2 z))
+(define (display-vec2 v port)
+ (format port "#<vec2 x: ~f y: ~f>" (vec2-x v) (vec2-y v)))
+
+(set-record-type-printer! <vec2> display-vec2)
+
+(define (display-vec3 v port)
+ (format port "#<vec3 x: ~f y: ~f z: ~f>" (vec3-x v) (vec3-y v) (vec3-z v)))
+
+(set-record-type-printer! <vec3> display-vec3)
+
(define (vec2-copy! source-vec2 target-vec2)
"Copy TARGET-VEC2 to SOURCE-VEC2."
(set-vec2-x! target-vec2 (vec2-x source-vec2))