From: Mikko Rasa Date: Tue, 14 May 2013 18:53:05 +0000 (+0300) Subject: Move some simple function definitions inside the class declarations X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b60ee0fb060790277bfc68722f85a137a58ad771;p=libs%2Fmath.git Move some simple function definitions inside the class declarations --- diff --git a/source/linal/matrix.h b/source/linal/matrix.h index 94a6e09..ff73165 100644 --- a/source/linal/matrix.h +++ b/source/linal/matrix.h @@ -25,10 +25,10 @@ public: static Matrix from_columns(const Vector *); static Matrix from_rows(const Vector *); - T &element(unsigned, unsigned); - const T &element(unsigned, unsigned) const; - T &operator()(unsigned, unsigned); - const T &operator()(unsigned, unsigned) const; + T &element(unsigned i, unsigned j) { return data[i+M*j]; } + const T &element(unsigned i, unsigned j) const { return data[i+M*j]; } + T &operator()(unsigned i, unsigned j) { return element(i, j); } + const T &operator()(unsigned i, unsigned j) const { return element(i, j); } Matrix &operator*=(T); Matrix &operator/=(T); @@ -77,30 +77,6 @@ inline Matrix Matrix::from_rows(const Vector *v) m(i, j) = v[i][j]; } -template -inline T &Matrix::element(unsigned i, unsigned j) -{ - return data[i+M*j]; -} - -template -inline const T &Matrix::element(unsigned i, unsigned j) const -{ - return data[i+M*j]; -} - -template -inline T &Matrix::operator()(unsigned i, unsigned j) -{ - return element(i, j); -} - -template -inline const T &Matrix::operator()(unsigned i, unsigned j) const -{ - return element(i, j); -} - template inline Matrix &Matrix::operator*=(T s) { diff --git a/source/linal/squarematrix.h b/source/linal/squarematrix.h index 4cdc9e8..94157b0 100644 --- a/source/linal/squarematrix.h +++ b/source/linal/squarematrix.h @@ -19,9 +19,9 @@ class SquareMatrix: public Matrix { public: SquareMatrix() { } - SquareMatrix(const T *); + SquareMatrix(const T *d): Matrix(d) { } template - SquareMatrix(const Matrix &); + SquareMatrix(const Matrix &m): Matrix(m) { } static SquareMatrix identity(); @@ -30,17 +30,6 @@ public: SquareMatrix &invert(); }; -template -SquareMatrix::SquareMatrix(const T *d): - Matrix(d) -{ } - -template -template -SquareMatrix::SquareMatrix(const Matrix &m): - Matrix(m) -{ } - template inline SquareMatrix SquareMatrix::identity() { diff --git a/source/linal/vector.h b/source/linal/vector.h index 1a79bd8..392e3a1 100644 --- a/source/linal/vector.h +++ b/source/linal/vector.h @@ -22,8 +22,8 @@ public: template Vector(const Vector &v); - T &operator[](unsigned i); - const T &operator[](unsigned i) const; + T &operator[](unsigned i) { return data[i]; } + const T &operator[](unsigned i) const { return data[i]; } Vector &operator*=(T); Vector &operator/=(T); @@ -54,18 +54,6 @@ inline Vector::Vector(const Vector &v) std::copy(v.data, v.data+N, data); } -template -T &Vector::operator[](unsigned i) -{ - return data[i]; -} - -template -const T &Vector::operator[](unsigned i) const -{ - return data[i]; -} - template inline Vector &Vector::operator*=(T s) { diff --git a/source/linal/vector3.h b/source/linal/vector3.h index 0197dbc..4a623ca 100644 --- a/source/linal/vector3.h +++ b/source/linal/vector3.h @@ -14,17 +14,12 @@ class Vector3: public Vector { public: Vector3() { } - Vector3(const T *); + Vector3(const T *d): Vector(d) { } Vector3(T, T, T); template - Vector3(const Vector &); + Vector3(const Vector &v): Vector(v) { } }; -template -inline Vector3::Vector3(const T *d): - Vector(d) -{ } - template inline Vector3::Vector3(T x, T y, T z) { @@ -33,12 +28,6 @@ inline Vector3::Vector3(T x, T y, T z) this->data[2] = z; } -template -template -inline Vector3::Vector3(const Vector &v): - Vector(v) -{ } - template inline T dot(const Vector &v1, const Vector &v2) {