/** * @file Vector.hpp * * Vector class. * * @author James Goppert */ #pragma once #include namespace matrix { template class Matrix; template class Vector : public Matrix { public: virtual ~Vector() {}; Vector() : Matrix() { } inline Type operator()(size_t i) const { const Matrix &v = *this; return v(i, 0); } inline Type &operator()(size_t i) { Matrix &v = *this; return v(i, 0); } Type dot(const Vector & b) { Vector &a(*this); Type r = 0; for (int i = 0; i<3; i++) { r += a(i)*b(i); } return r; } Type norm() { Vector &a(*this); return sqrt(a.dot(a)); } /** * Vector Operations */ Vector operator+(const Vector &other) const { Vector res; const Vector &self = *this; for (size_t i = 0; i < M; i++) { res(i) = self(i) + other(i); } return res; } bool operator==(const Vector &other) const { Vector res; const Vector &self = *this; for (size_t i = 0; i < M; i++) { if (self(i) != other(i)) { return false; } } return true; } Vector operator-(const Vector &other) const { Vector res; const Vector &self = *this; for (size_t i = 0; i < M; i++) { res(i) = self(i) - other(i); } return res; } void operator+=(const Vector &other) { Vector &self = *this; self = self + other; } void operator-=(const Vector &other) { Vector &self = *this; self = self - other; } /** * Scalar Operations */ Vector operator*(Type scalar) const { Vector res; const Vector &self = *this; for (size_t i = 0; i < M; i++) { res(i) = self(i) * scalar; } return res; } Vector operator+(Type scalar) const { Vector res; const Vector &self = *this; for (size_t i = 0; i < M; i++) { res(i) = self(i) + scalar; } return res; } void operator*=(Type scalar) { Vector &self = *this; for (size_t i = 0; i < M; i++) { self(i) = self(i) * scalar; } } void operator/=(Type scalar) { Vector &self = *this; self = self * (1.0f / scalar); } }; }; // namespace matrix /* vim: set et fenc=utf-8 ff=unix sts=0 sw=4 ts=4 : */