| [342f33f] | 1 | #ifndef VECTOR_HPP_ | 
|---|
|  | 2 | #define VECTOR_HPP_ | 
|---|
|  | 3 |  | 
|---|
| [357fba] | 4 | using namespace std; | 
|---|
|  | 5 |  | 
|---|
| [f66195] | 6 | /*********************************************** includes ***********************************/ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | // include config.h | 
|---|
|  | 9 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 10 | #include <config.h> | 
|---|
|  | 11 | #endif | 
|---|
| [357fba] | 12 |  | 
|---|
| [986ed3] | 13 | #include <iosfwd> | 
|---|
| [54a746] | 14 |  | 
|---|
| [1bd79e] | 15 | #include <memory> | 
|---|
| [45ef76] | 16 | #include <vector> | 
|---|
| [1bd79e] | 17 |  | 
|---|
| [f66195] | 18 | #include "defs.hpp" | 
|---|
| [57f243] | 19 | #include "LinearAlgebra/Space.hpp" | 
|---|
| [f66195] | 20 |  | 
|---|
|  | 21 | /********************************************** declarations *******************************/ | 
|---|
| [7d96c6] | 22 |  | 
|---|
| [45ef76] | 23 | class Vector; | 
|---|
| [325390] | 24 | class Matrix; | 
|---|
| [ce3d2b] | 25 | struct VectorContent; | 
|---|
| [45ef76] | 26 |  | 
|---|
|  | 27 | typedef std::vector<Vector> pointset; | 
|---|
|  | 28 |  | 
|---|
| [342f33f] | 29 | /** Single vector. | 
|---|
|  | 30 | * basically, just a x[3] but with helpful functions | 
|---|
|  | 31 | */ | 
|---|
| [1513a74] | 32 | class Vector : public Space{ | 
|---|
| [325390] | 33 | friend Vector operator*(const Matrix&,const Vector&); | 
|---|
| [8e17d6] | 34 | friend class Matrix; | 
|---|
| [1bd79e] | 35 | public: | 
|---|
| [042f82] | 36 | Vector(); | 
|---|
| [fb73b8] | 37 | Vector(const double x1, const double x2, const double x3); | 
|---|
| [d74077] | 38 | Vector(const double x[3]); | 
|---|
| [0a4f7f] | 39 | Vector(const Vector& src); | 
|---|
| [72e7fa] | 40 | virtual ~Vector(); | 
|---|
|  | 41 |  | 
|---|
| [1bd79e] | 42 | // Method implemented by forwarding to the Representation | 
|---|
|  | 43 |  | 
|---|
| [753f02] | 44 | double DistanceSquared(const Vector &y) const; | 
|---|
| [d4c9ae] | 45 | double DistanceToSpace(const Space& space) const; | 
|---|
| [753f02] | 46 | double ScalarProduct(const Vector &y) const; | 
|---|
|  | 47 | double Angle(const Vector &y) const; | 
|---|
| [54a746] | 48 | bool IsZero() const; | 
|---|
|  | 49 | bool IsOne() const; | 
|---|
| [753f02] | 50 | bool IsNormalTo(const Vector &normal) const; | 
|---|
|  | 51 | bool IsEqualTo(const Vector &a) const; | 
|---|
|  | 52 |  | 
|---|
|  | 53 | void AddVector(const Vector &y); | 
|---|
|  | 54 | void SubtractVector(const Vector &y); | 
|---|
|  | 55 | void VectorProduct(const Vector &y); | 
|---|
|  | 56 | void ProjectOntoPlane(const Vector &y); | 
|---|
|  | 57 | void ProjectIt(const Vector &y); | 
|---|
|  | 58 | Vector Projection(const Vector &y) const; | 
|---|
|  | 59 | void ScaleAll(const double *factor); | 
|---|
| [b5bf84] | 60 | void ScaleAll(const Vector &factor); | 
|---|
| [776b64] | 61 | void Scale(const double factor); | 
|---|
| [753f02] | 62 | bool GetOneNormalVector(const Vector &x1); | 
|---|
|  | 63 | bool MakeNormalTo(const Vector &y1); | 
|---|
| [45ef76] | 64 | std::pair<Vector,Vector> partition(const Vector&) const; | 
|---|
|  | 65 | std::pair<pointset,Vector> partition(const pointset&) const; | 
|---|
| [a439e5] | 66 | size_t GreatestComponent() const; | 
|---|
|  | 67 | size_t SmallestComponent() const; | 
|---|
| [2ededc2] | 68 |  | 
|---|
| [0a4f7f] | 69 | // Accessors ussually come in pairs... and sometimes even more than that | 
|---|
| [753f02] | 70 | double& operator[](size_t i); | 
|---|
|  | 71 | const double& operator[](size_t i) const; | 
|---|
| [1bd79e] | 72 | double& at(size_t i); | 
|---|
|  | 73 | const double& at(size_t i) const; | 
|---|
| [0a4f7f] | 74 |  | 
|---|
|  | 75 | // Assignment operator | 
|---|
| [753f02] | 76 | Vector &operator=(const Vector& src); | 
|---|
| [0a4f7f] | 77 |  | 
|---|
|  | 78 | // Access to internal structure | 
|---|
| [ce3d2b] | 79 | VectorContent* get(); | 
|---|
| [72e7fa] | 80 |  | 
|---|
| [1bd79e] | 81 | // Methods that are derived directly from other methods | 
|---|
|  | 82 | double Norm() const; | 
|---|
|  | 83 | double NormSquared() const; | 
|---|
|  | 84 | void Normalize(); | 
|---|
| [421a1f] | 85 | Vector getNormalized() const; | 
|---|
| [1bd79e] | 86 | void Zero(); | 
|---|
|  | 87 | void One(const double one); | 
|---|
|  | 88 | void LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors); | 
|---|
|  | 89 |  | 
|---|
| [72e7fa] | 90 | // operators for mathematical operations | 
|---|
|  | 91 | bool operator==(const Vector& b) const; | 
|---|
| [fa5a6a] | 92 | bool operator!=(const Vector& b) const; | 
|---|
| [72e7fa] | 93 | const Vector& operator+=(const Vector& b); | 
|---|
|  | 94 | const Vector& operator-=(const Vector& b); | 
|---|
|  | 95 | Vector const operator+(const Vector& b) const; | 
|---|
|  | 96 | Vector const operator-(const Vector& b) const; | 
|---|
| [0a4f7f] | 97 |  | 
|---|
| [1513a74] | 98 | // Methods inherited from Space | 
|---|
|  | 99 | virtual double distance(const Vector &point) const; | 
|---|
|  | 100 | virtual Vector getClosestPoint(const Vector &point) const; | 
|---|
|  | 101 |  | 
|---|
| [1bd79e] | 102 | protected: | 
|---|
|  | 103 |  | 
|---|
| [0a4f7f] | 104 | private: | 
|---|
| [ce3d2b] | 105 | Vector(VectorContent *); | 
|---|
|  | 106 | VectorContent *content; | 
|---|
| [0a4f7f] | 107 |  | 
|---|
| [342f33f] | 108 | }; | 
|---|
|  | 109 |  | 
|---|
| [005e18] | 110 | // some commonly used and fixed vectors | 
|---|
|  | 111 | const extern Vector zeroVec; | 
|---|
| [407782] | 112 | const extern Vector unitVec[NDIM]; | 
|---|
| [005e18] | 113 |  | 
|---|
| [9c20aa] | 114 | ostream & operator << (ostream& ost, const Vector &m); | 
|---|
| [b84d5d] | 115 | const Vector& operator*=(Vector& a, const double m); | 
|---|
|  | 116 | Vector const operator*(const Vector& a, const double m); | 
|---|
|  | 117 | Vector const operator*(const double m, const Vector& a); | 
|---|
| [342f33f] | 118 |  | 
|---|
|  | 119 | #endif /*VECTOR_HPP_*/ | 
|---|