From 3ee98f3bac24fd1c70a9de3e0fbe774e762c25b3 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Fri, 26 Jun 2009 15:31:34 +0000 Subject: Add lots of comments, and some code fixes discovered in the process. --- libdimensionxx/dimensionxx/geometry.hpp | 55 +++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) (limited to 'libdimensionxx/dimensionxx/geometry.hpp') diff --git a/libdimensionxx/dimensionxx/geometry.hpp b/libdimensionxx/dimensionxx/geometry.hpp index f623eda..606f83a 100644 --- a/libdimensionxx/dimensionxx/geometry.hpp +++ b/libdimensionxx/dimensionxx/geometry.hpp @@ -18,15 +18,17 @@ * . * *************************************************************************/ +// Wrappers for geometric types (Vectors, Matricies, Lines (rays)). + #ifndef DIMENSIONXX_GEOMETRY_HPP #define DIMENSIONXX_GEOMETRY_HPP -// Wrappers for geometric types (Vectors, Matricies, Lines (rays)). - #include namespace Dimension { + class Vector; + // Wrapper for dmnsn_matrix class Matrix { @@ -56,6 +58,12 @@ namespace Dimension // Get the wrapped matrix dmnsn_matrix dmnsn() const { return m_matrix; } + // Special constructors + static inline Matrix identity(); + static inline Matrix scale(const Vector& factor); + static inline Matrix translation(const Vector& d); + static inline Matrix rotation(const Vector& theta); + private: dmnsn_matrix m_matrix; }; @@ -126,6 +134,49 @@ namespace Dimension dmnsn_line m_line; }; + // Matrix operators + + inline Matrix + operator*(const Matrix& lhs, const Matrix& rhs) + { + // This order is important! + Matrix r = rhs; + r *= lhs; + return r; + } + + inline Matrix + inverse(const Matrix& M) + { + return Matrix(dmnsn_matrix_inverse(M.dmnsn())); + } + + // Special Matrix constructors + + inline Matrix + Matrix::identity() + { + return Matrix(dmnsn_identity_matrix()); + } + + inline Matrix + Matrix::scale(const Vector& factor) + { + return Matrix(dmnsn_scale_matrix(factor.dmnsn())); + } + + inline Matrix + Matrix::translation(const Vector& d) + { + return Matrix(dmnsn_translation_matrix(d.dmnsn())); + } + + inline Matrix + Matrix::rotation(const Vector& theta) + { + return Matrix(dmnsn_rotation_matrix(theta.dmnsn())); + } + // Vector operators inline Vector -- cgit v1.2.3