/* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #pragma once #include #include #include "matrixN.h" #ifndef MATH_CHECK_INDEXES # define MATH_CHECK_INDEXES 0 #endif #if MATH_CHECK_INDEXES #include #endif template class MatrixN; template class VectorN { public: // trivial ctor inline VectorN() { for (auto i = 0; i < N; i++) { _v[i] = T{}; } } // vector ctor inline VectorN(const T *v) { memcpy(_v, v, sizeof(T)*N); } inline T & operator[](uint8_t i) { #if MATH_CHECK_INDEXES assert(i >= 0 && i < N); #endif return _v[i]; } inline const T & operator[](uint8_t i) const { #if MATH_CHECK_INDEXES assert(i >= 0 && i < N); #endif return _v[i]; } // test for equality bool operator ==(const VectorN &v) const { for (uint8_t i=0; i operator -(void) const { VectorN v2; for (uint8_t i=0; i operator +(const VectorN &v) const { VectorN v2; for (uint8_t i=0; i operator -(const VectorN &v) const { VectorN v2; for (uint8_t i=0; i operator *(const T num) const { VectorN v2; for (uint8_t i=0; i operator /(const T num) const { VectorN v2; for (uint8_t i=0; i &operator +=(const VectorN &v) { for (uint8_t i=0; i &operator -=(const VectorN &v) { for (uint8_t i=0; i &operator *=(const T num) { for (uint8_t i=0; i &operator /=(const T num) { for (uint8_t i=0; i &v) const { float ret = 0; for (uint8_t i=0; i &A, const VectorN &B) { for (uint8_t i = 0; i < N; i++) { _v[i] = 0; for (uint8_t k = 0; k < N; k++) { _v[i] += A.v[i][k] * B[k]; } } } protected: T _v[N]; };