diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-06-20 08:09:10 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-06-20 08:09:10 -0400 |
commit | e7a4812aa556f2c3159a6ca772e6c1f61de18e07 (patch) | |
tree | 4d737f393e78471bfac45d0187e3739fc4bba754 /libdimension/dimension/geometry.h | |
parent | db09a6bc5bb5da674abf7b5f8874a57ef2cf4dfb (diff) | |
download | dimension-e7a4812aa556f2c3159a6ca772e6c1f61de18e07.tar.xz |
Add some macros to make printf()-ing geometric types easier.
Diffstat (limited to 'libdimension/dimension/geometry.h')
-rw-r--r-- | libdimension/dimension/geometry.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/libdimension/dimension/geometry.h b/libdimension/dimension/geometry.h index 98fc913..d55126d 100644 --- a/libdimension/dimension/geometry.h +++ b/libdimension/dimension/geometry.h @@ -31,17 +31,35 @@ /* Vector and matrix types */ typedef struct dmnsn_vector { double x, y, z; } dmnsn_vector; +#define DMNSN_VECTOR_FORMAT "<%g, %g, %g>" +#define DMNSN_VECTOR_PRINTF(v) (v).x, (v).y, (v).z typedef struct dmnsn_matrix { double n[4][4]; } dmnsn_matrix; +#define DMNSN_MATRIX_FORMAT \ + "[%g\t%g\t%g\t%g]\n" \ + "[%g\t%g\t%g\t%g]\n" \ + "[%g\t%g\t%g\t%g]\n" \ + "[%g\t%g\t%g\t%g]" +#define DMNSN_MATRIX_PRINTF(m) \ + (m).n[0][0], (m).n[0][1], (m).n[0][2], (m).n[0][3], \ + (m).n[1][0], (m).n[1][1], (m).n[1][2], (m).n[1][3], \ + (m).n[2][0], (m).n[2][1], (m).n[2][2], (m).n[2][3], \ + (m).n[3][0], (m).n[3][1], (m).n[3][2], (m).n[3][3] /* A line, or ray */ typedef struct dmnsn_line { dmnsn_vector x0; /* A point on the line */ dmnsn_vector n; /* A normal vector; the direction of the line */ } dmnsn_line; +#define DMNSN_LINE_FORMAT "(<%g, %g, %g> + t*<%g, %g, %g>)" +#define DMNSN_LINE_PRINTF(l) \ + DMNSN_VECTOR_PRINTF((l).x0), DMNSN_VECTOR_PRINTF((l).n) /* A bounding box */ typedef struct dmnsn_bounding_box { dmnsn_vector min, max; } dmnsn_bounding_box; +#define DMNSN_BOUNDING_BOX_FORMAT "(<%g, %g, %g> ==> <%g, %g, %g>)" +#define DMNSN_BOUNDING_BOX_PRINTF(box) \ + DMNSN_VECTOR_PRINTF((box).min), DMNSN_VECTOR_PRINTF((box).max) /* Constants */ |