#include #define tmplx template #define tmpl template tmplx VectorXD::MatrixMxN() { this->fill(0); } tmplx VectorXD::MatrixMxN(double k) { this->fill(k); } tmplx VectorXD::MatrixMxN(const double scalars[X]) { this->fill(scalars); } tmplx VectorXD::MatrixMxN(const VectorXD& other) { for (unsigned i = 0; i < X; ++i) { _scalars[i] = other._scalars[i]; } } tmpl T& GenericVector::setScalar(unsigned i, double value) { return setScalar(i, 0,value); } tmpl double GenericVector::getScalar(unsigned i) const { return getScalar(i, 0); } tmpl double GenericVector::operator[](unsigned i) const { return getScalar(i); } tmpl double GenericVector::dotProduct(const T &other) const { double total = 0; for (unsigned i = 0; i < X; ++i) { total += _scalars[i][0] * other._scalars[i][0]; } return total; } tmpl T& GenericVector::crossProduct(const T& other) { T t = *getThis(); for (unsigned i = 0; i < X; ++i) { unsigned j = (i + 1) % X; unsigned k = (i + 2) % X; _scalars[i][0] = (t._scalars[j][0] * other._scalars[k][0]) - (t._scalars[k][0] * other._scalars[j][0]); } return *getThis(); } tmpl T GenericVector::crossProduct(const T &v1, const T &v2) { return T(v1).crossProduct(v2); } tmpl double GenericVector::norm() const { double total = 0; for (unsigned i = 0; i < X; ++i) { total += _scalars[i][0] * _scalars[i][0]; } return sqrt(total); } tmpl T* GenericVector::getThis() const { return (T*)this; } //tmpl QDebug operator<<(QDebug dbg, const T &v) //{ // return dbg.nospace() << "(" << v.getX() << ", " << v.getY() << ", " << v.getZ() << ")"; //}