From d1e94994f75466ab207322f59847ac0f359f46b8 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Tue, 18 May 2010 11:02:46 -0600 Subject: New dmnsn_vector_element() function. --- libdimension/dimension/geometry.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'libdimension') diff --git a/libdimension/dimension/geometry.h b/libdimension/dimension/geometry.h index 6fb7c96..8e2e47c 100644 --- a/libdimension/dimension/geometry.h +++ b/libdimension/dimension/geometry.h @@ -101,6 +101,31 @@ dmnsn_new_line(dmnsn_vector x0, dmnsn_vector n) return l; } +/* Vector element access */ + +enum { + DMNSN_X, + DMNSN_Y, + DMNSN_Z +}; + +DMNSN_INLINE double +dmnsn_vector_element(dmnsn_vector n, int elem) +{ + switch (elem) { + case DMNSN_X: + return n.x; + case DMNSN_Y: + return n.y; + case DMNSN_Z: + return n.z; + + default: + dmnsn_assert(false, "Wrong vector element requested."); + return 0.0; /* Shut up compiler */ + } +} + /* Vector and matrix arithmetic */ DMNSN_INLINE dmnsn_vector -- cgit v1.2.3