v4.hpp

Go to the documentation of this file.
00001 /*
00002 **    Projet etudiants CPE Lyon
00003 **    Copyright (C) 2012 Damien Rohmer
00004 **
00005 **    This program is free software: you can redistribute it and/or modify
00006 **    it under the terms of the GNU General Public License as published by
00007 **    the Free Software Foundation, either version 3 of the License, or
00008 **    (at your option) any later version.
00009 **
00010 **   This program is distributed in the hope that it will be useful,
00011 **    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 **    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 **    GNU General Public License for more details.
00014 **
00015 **    You should have received a copy of the GNU General Public License
00016 **    along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 #ifndef V4_HPP
00020 #define V4_HPP
00021 
00022 #include <iostream>
00023 
00024 namespace cpe
00025 {
00026 
00027     class v3;
00028 
00030     class v4
00031     {
00032     public:
00033 
00034         // ********************************************* //
00035         // ********************************************* //
00036         //  CONSTRUCTORS
00037         // ********************************************* //
00038         // ********************************************* //
00039 
00041         v4();
00043         v4(const double& x,const double& y,const double& z,const double& w);
00045         v4(const v3& xyz,const double& w);
00046 
00047         // ********************************************* //
00048         // ********************************************* //
00049         //  Get/set
00050         // ********************************************* //
00051         // ********************************************* //
00052 
00054         const double& x() const;
00056         double& x();
00058         const double& y() const;
00060         double& y();
00062         const double& z() const;
00064         double& z();
00066         const double& w() const;
00068         double& w();
00069 
00071         const double& operator[](const size_t& k) const;
00073         double& operator[](const size_t& k);
00075         const double& operator()(const size_t& k) const;
00077         double& operator()(const size_t& k);
00078 
00079 
00081         void set_zero();
00082 
00083 
00084         // ********************************************* //
00085         // ********************************************* //
00086         //  Math operation
00087         // ********************************************* //
00088         // ********************************************* //
00089 
00091         double dot(const v4& p) const;
00092 
00094         double norm() const;
00096         double norm2() const;
00097 
00098 
00099 
00100 
00101 
00102 
00103         // ********************************************* //
00104         // ********************************************* //
00105         //  Operator +-*/
00106         // ********************************************* //
00107         // ********************************************* //
00108 
00110         friend v4 operator+(const v4& p1,const v4& p2);
00112         friend v4 operator+(const double& s,const v4& p);
00114         friend v4 operator+(const v4& p,const double& s);
00115 
00117         friend v4 operator-(const v4& p1,const v4& p2);
00119         friend v4 operator-(const double& s,const v4& p);
00121         friend v4 operator-(const v4& p,const double& s);
00122 
00124         friend v4 operator*(const double& s,const v4& p);
00126         friend v4 operator*(const v4& p,const double& s);
00128         friend v4 operator/(const v4& p,const double& s);
00129 
00131         v4& operator+=(const v4& p);
00133         v4& operator+=(const double& s);
00135         v4& operator-=(const v4& p);
00137         v4& operator-=(const double& s);
00139         v4& operator*=(const double& s);
00141         v4& operator/=(const double& s);
00142 
00144         v4 operator-() const;
00145 
00149         v4 product_compontentwise(const v4& p) const;
00154         v4& product_compontentwise_internal(const v4& p);
00155 
00156 
00157         // ********************************************* //
00158         // ********************************************* //
00159         //  Output
00160         // ********************************************* //
00161         // ********************************************* //
00162 
00164         std::string to_string() const;
00165 
00167         friend std::ostream& operator<<(std::ostream& stream,const v4& p);
00168 
00169 
00170 
00171     private:
00172 
00173         // ********************************************* //
00174         // ********************************************* //
00175         //  Internal parameters
00176         // ********************************************* //
00177         // ********************************************* //
00178 
00180         double internal_x;
00182         double internal_y;
00184         double internal_z;
00186         double internal_w;
00187 
00188 
00189         // ********************************************* //
00190         // ********************************************* //
00191         //  Helper
00192         // ********************************************* //
00193         // ********************************************* //
00194 
00196         void assert_size(const size_t& k) const throw(std::exception);
00197 
00198 
00199     };
00200 
00201 }
00202 
00203 #endif