#ifndef MSP_GEOMETRY_AFFINETRANSFORMATION_H_
#define MSP_GEOMETRY_AFFINETRANSFORMATION_H_
-#include <msp/linal/squarematrix.h>
+#include <msp/linal/matrix.h>
#include "angle.h"
#include "boundingbox.h"
#include "ray.h"
friend class AffineTransformationOps<T, D>;
private:
- LinAl::SquareMatrix<T, D+1> matrix;
+ LinAl::Matrix<T, D+1, D+1> matrix;
public:
AffineTransformation();
AffineTransformation &operator*=(const AffineTransformation &);
AffineTransformation &invert();
- const LinAl::SquareMatrix<T, D+1> &get_matrix() const { return matrix; }
- operator const LinAl::SquareMatrix<T, D+1> &() const { return matrix; }
+ const LinAl::Matrix<T, D+1, D+1> &get_matrix() const { return matrix; }
+ operator const LinAl::Matrix<T, D+1, D+1> &() const { return matrix; }
LinAl::Vector<T, D> transform(const LinAl::Vector<T, D> &) const;
LinAl::Vector<T, D> transform_linear(const LinAl::Vector<T, D> &) const;
template<typename T, unsigned D>
inline AffineTransformation<T, D>::AffineTransformation()
{
- this->matrix = LinAl::SquareMatrix<T, D+1>::identity();
+ this->matrix = LinAl::Matrix<T, D+1, D+1>::identity();
}
#include "vector.h"
#include "matrix.h"
-#include "squarematrix.h"
#include "dynamicvector.h"
#include "dynamicmatrix.h"
#include <algorithm>
#include <ostream>
+#include "matrixops.h"
#include "vector.h"
namespace Msp {
template<typename U>
Matrix(const Matrix<U, M, N> &);
+ static Matrix identity();
static Matrix from_columns(const Vector<T, M> *);
static Matrix from_rows(const Vector<T, N> *);
Matrix<T, P, Q> block(unsigned, unsigned) const;
Matrix &operator*=(T);
+ Matrix &operator*=(const Matrix &);
Matrix &operator/=(T);
Matrix &operator+=(const Matrix &);
Matrix &operator-=(const Matrix &);
+ Matrix &invert();
+
Matrix &exchange_columns(unsigned, unsigned);
Matrix &multiply_column(unsigned, T);
Matrix &add_column(unsigned, unsigned, T);
element(i, j) = other(i, j);
}
+template<typename T, unsigned M, unsigned N>
+inline Matrix<T, M, N> Matrix<T, M, N>::identity()
+{
+ static_assert(M==N, "An identity matrix must be square");
+ Matrix<T, M, N> m;
+ for(unsigned i=0; i<M; ++i)
+ m(i, i) = T(1);
+ return m;
+}
+
template<typename T, unsigned M, unsigned N>
inline Matrix<T, M, N> Matrix<T, M, N>::from_columns(const Vector<T, M> *v)
{
return *this;
}
+template<typename T, unsigned M, unsigned N>
+inline Matrix<T, M, N> &Matrix<T, M, N>::operator*=(const Matrix<T, M, N> &m)
+{
+ static_assert(M==N, "Multiplication-assignment is only possible on square matrices");
+ return *this = *this*m;
+}
+
template<typename T, unsigned M, unsigned N>
inline Matrix<T, M, N> operator*(const Matrix<T, M, N> &m, T s)
{
return r -= m2;
}
+template<typename T, unsigned M, unsigned N>
+inline Matrix<T, M, N>& Matrix<T, M, N>::invert()
+{
+ static_assert(M==N, "Inversion is only possible on square matrices");
+ Matrix<T, M, N> r = identity();
+ gauss_jordan(*this, r);
+ return *this = r;
+}
+
+template<typename T, unsigned S>
+inline Matrix<T, S, S> invert(const Matrix<T, S, S> &m)
+{
+ Matrix<T, S, S> temp = m;
+ Matrix<T, S, S> r = Matrix<T, S, S>::identity();
+ return gauss_jordan(temp, r);
+}
+
template<typename T, unsigned M, unsigned N>
inline bool operator==(const Matrix<T, M, N> &a, const Matrix<T, M, N> &b)
{
+++ /dev/null
-#ifndef MSP_LINAL_SQUAREMATRIX_H_
-#define MSP_LINAL_SQUAREMATRIX_H_
-
-#include <cmath>
-#include "matrix.h"
-#include "matrixops.h"
-
-namespace Msp {
-namespace LinAl {
-
-/**
-A mathematical matrix with S rows and columns. Some operations are provided
-here that are only possible for square matrices.
-*/
-template<typename T, unsigned S>
-class SquareMatrix: public Matrix<T, S, S>
-{
-public:
- SquareMatrix() { }
- SquareMatrix(const T *d): Matrix<T, S, S>(d) { }
- template<typename U>
- SquareMatrix(const Matrix<U, S, S> &m): Matrix<T, S, S>(m) { }
-
- static SquareMatrix identity();
-
- SquareMatrix &operator*=(const SquareMatrix &);
- using Matrix<T, S, S>::operator*=;
-
- SquareMatrix &invert();
-};
-
-template<typename T, unsigned S>
-inline SquareMatrix<T, S> SquareMatrix<T, S>::identity()
-{
- SquareMatrix<T, S> m;
- for(unsigned i=0; i<S; ++i)
- m(i, i) = T(1);
- return m;
-}
-
-template<typename T, unsigned S>
-SquareMatrix<T, S> &SquareMatrix<T, S>::operator*=(const SquareMatrix<T, S> &m)
-{
- return *this = *this*m;
-}
-
-template<typename T, unsigned S>
-SquareMatrix<T, S> &SquareMatrix<T, S>::invert()
-{
- SquareMatrix<T, S> r = identity();
- gauss_jordan(*this, r);
- return *this = r;
-}
-
-template<typename T, unsigned S>
-inline SquareMatrix<T, S> invert(const SquareMatrix<T, S> &m)
-{
- SquareMatrix<T, S> temp = m;
- SquareMatrix<T, S> r = SquareMatrix<T, S>::identity();
- return gauss_jordan(temp, r);
-}
-
-} // namespace LinAl
-} // namespace Msp
-
-#endif