1%%%%%%%%%%%%%%%%%%%
2% XLiFE++ is an extended library of finite elements written in C++
3%     Copyright (C) 2014  Lunéville, Eric; Kielbasiewicz, Nicolas; Lafranche, Yvon; Nguyen, Manh-Ha; Chambeyron, Colin
4%
5%     This program is free software: you can redistribute it and/or modify
6%     it under the terms of the GNU General Public License as published by
7%     the Free Software Foundation, either version 3 of the License, or
8%     (at your option) any later version.
9%     This program is distributed in the hope that it will be useful,
10%     but WITHOUT ANY WARRANTY; without even the implied warranty of
11%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12%     GNU General Public License for more details.
13%     You should have received a copy of the GNU General Public License
14%     along with this program.  If not, see <http://www.gnu.org/licenses/>.
15%%%%%%%%%%%%%%%%%%%
16
17\section{The {\classtitle Point} class}
18
19The purpose of the {\class Point} class is to deal with point in any dimension. It is derived
20from the \emph{std:vector<Real>}.
21\vspace{.2cm}
22\begin{lstlisting}
23typedef std::vector<Real>::iterator ivr_t;
24typedef std::vector<Real>::const_iterator civr_t;
25
26class Point : public std::vector<Real>
27{public:
28 static Real tolerance;
29 ...
30}
31\end{lstlisting}
32\vspace{.2cm}
33The static member \emph{tolerance} is used in comparison operations. By default, its value
34is 0; As a child class of {\class std::vector}, the Point class does not have copy constructor
35and assignment = operator.
36
37It offers some basic constructors:
38\vspace{.2cm}
39\begin{lstlisting}[]{}
40Point(const int, const Real v = 0.); // dimension and constant value
41Point(const Dimen, const Real v = 0.); // dimension and constant value
42Point(const Real x1); // 1D constructor by coordinate
43Point(const Real x1, const Real x2); // 2D constructor by coordinates
44Point(const Real x1, const Real x2, const Real x3); // 3D constructor by coordinates
45Point(const Dimen d, Real* pt); // constructor by dimension and Real array
46Point(const std::vector<Real>& pt); // constructor by stl vector
47Point(const std::vector<Real>::const_iterator, Dimen); // constructor by stl vector iterator
48~Point(); // destructor
49\end{lstlisting}
50\vspace{.2cm}
51One can access (both read and read/write access) to the coordinates either by index (from 1
52to dim) or by explicit name x(), y() and z() (restricted to 3D point):
53\vspace{.2cm}
54\begin{lstlisting}[]{}
55Real operator()(const Dimen d) const; //the d-th coordinates (r)
56Real& operator()(const Dimen d);      //d-th coordinates (r/w)
57Real  x() const; //the first coordinate  (r)
58Real& x();       //the first coordinate  (r/w)
59Real  y() const; //the second coordinate (r)
60Real& y();       //the second coordinate (r/w)
61Real  z() const; //the third coordinate  (r)
62Real& z();       //the third coordinate  (r/w)
63std::vector<Real> toVect(const Point &)  //!<convert to a std::vector
64\end{lstlisting}
65\vspace{.2cm}
66Through overloaded operator, the Point class provides some algebraic operations and distance
67computation functions:
68\vspace{.2cm}
69\begin{lstlisting}[]{}
70Point& operator+=(const Point &); //add a point to the current point
71Point& operator-=(const Point &); //subtract a point to the current point
72Point& operator+=(const Real);  //add a constant point to the current point
73Point& operator-=(const Real);  //subtract a constant point to the current point
74Point& operator*=(const Real ); //scale the current point
75Point& operator/=(const Real ); //scale the current point
76Real squareDistance(const Point&) const; //square distance to an other point
77Real distance(const Point&) const; //distance to an other point
78\end{lstlisting}
79\vspace{.2cm}
80Note that size compatibility tests are performed on such computations.\\
81
82Algebraic operations on points may be also be processed by external function to the class:
83\vspace{.2cm}
84\begin{lstlisting}[]{}
85Point operator+(const Point &);                 //same point (completeness)
86Point operator-(const Point &);                 //opposite point
87Point operator+(const Point &,const Point &);   //sum of two points
88Point operator-(const Point &,const Point &);   //difference of two points
89Point operator+(const Point &,const Real );     //sum of two points
90Point operator-(const Point &,const Real );     //difference of two points
91Point operator+(const Real,const Point & );     //sum of two points
92Point operator-(const Real,const Point & );     //difference of two points
93Point operator*(const Real ,const Point &);     //scale a point
94Point operator*(const Point &,const Real );     //scale a point
95Point operator/(const Point &,const Real );     //scale a point
96Real pointDistance(const Point&,const Point&);  //distance between two points
97Real squareDistance(const Point&,const Point&); //square distance between two points
98\end{lstlisting}
99\vspace{.2cm}
100{\cmd distance()} is a function of the \emph{std::iterator} class, it is the reason why the
101distance between two points is named {\cmd pointDistance}. \\
102
103Finally, to order (partially) a couple of points, the comparison operators (==, !=, <, >, <=
104and >=) are overloaded:
105\vspace{.2cm}
106\begin{lstlisting}[]{}
107bool operator==(const Point &,const Point &); //equality of two points
108bool operator!=(const Point &,const Point &); //not equality of two points
109bool operator< (const Point &,const Point &); //leather than
110bool operator<=(const Point &,const Point &); //leather than or equal
111bool operator> (const Point &,const Point &); //greater than
112bool operator>=(const Point &,const Point &); //greater between or equal
113\end{lstlisting}
114\vspace{.2cm}
115The comparison between points are performed using the tolerance value $\tau$ ({\var Point::tolerance})
116which means for points $p$ and $q$ in $\mathbb{R}^n$:
117\[
118\begin{array}{l}
119p==q\ {\rm if}\  |p-q|\leq \tau \\
120p<q\ {\rm if}\ \exists i\leq n,\ \forall j<i,\  |p_j-q_j|\leq \tau\  {\rm and}\ p_j<q_j-\tau.
121
122\end{array}
123\]
124
125\displayInfos{library=utils, header=Point.hpp, implementation=Point.cpp, test=test\_Point.cpp,
126header dep=config.h}
127