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