Simplexus  1.0
Création d'un pavage par des simplexes de dimension N et visualisation graphique en dimension 2.
point.hpp
Go to the documentation of this file.
1 #ifndef _POINT_H
2 #define _POINT_H
3 
11 #include <cstddef>
12 #include <iostream>
13 #include <cstdlib>
14 #include <cassert>
15 #include <cstdarg>
16 #include <array>
17 #include <cmath>
18 #include <initializer_list>
19 
20 
22 template<std::size_t N>
29 class Point
30 {
31  private:
32  std::array<double, N> coordinates;
33  bool boundry = false;
35  public:
42  Point();
43 
50  Point(const Point& other);
51 
59  Point(double val, ...);
60 
69  Point(std::initializer_list<double> l);
70 
71 
79  Point(Point&& other);
80 
90  const Point& operator=(Point&& other);
91 
100  Point& operator=(const Point& other);
101 
110  void setCoord(unsigned int index, double val);
111 
120  void setCoords(double val, ...);
121 
130  double getCoord(unsigned int index) const;
131 
139  bool outOfBoundries();
140 
149  bool operator==(Point const& other);
150 
159  bool operator<(const Point& other) const;
160 
169  bool operator>=(const Point& other) const;
170 
179  bool operator<=(const Point& other) const;
180 
189  bool operator>(const Point& other) const;
190 
199  double distance(const Point<N>& other) const;
200 
207  void toBoundry();
208 
216  bool isBoundry();
217 
226  template<std::size_t P>
227  friend std::ostream& operator<<(std::ostream& os, const Point<P>& point);
228 
229 };
230 
231 template<std::size_t N>
233  //std::cout << "Point::Constructeur vide" << std::endl;
234  for(unsigned i=0; i<N; i++){
235  coordinates[i] = 0.0;
236  }
237 }
238 
239 template<std::size_t N>
240 Point<N>::Point(const Point& other){
241  std::cout << "Point::Constructeur par copie" << std::endl;
242  for(unsigned i = 0; i<N; i++){
243  coordinates[i] = other.coordinates[i];
244  }
245  this->boundry=other.boundry;
246 }
247 
248 template<std::size_t N>
250  //std::cout << "Point::Constructeur par deplacement" << std::endl;
251  coordinates = std::move(other.coordinates);
252  this->boundry=other.boundry;
253  other.coordinates.empty();
254 }
255 
256 template<std::size_t N>
257 Point<N>::Point(double val, ...){
258  //std::cout << "Point::Constructeur par valeur (...)" << std::endl;
259  this->setCoord(0, val);
260  va_list ap;
261 
262  va_start(ap,NULL);
263  for (unsigned i = 1; i<N; i++){
264  this->setCoord(i, va_arg(ap,double));
265  }
266 
267  va_end(ap);
268 }
269 
270 template<std::size_t N>
271 Point<N>::Point(std::initializer_list<double> l){
272  //std::cout << "Point::Constructeur par valeur (initializer_list)" << std::endl;
273  for(unsigned i=0; i<N; i++){
274  coordinates[i] = 0.0;
275  }
276  size_t pos = 0;
277  for(double v : l){
278  if(pos >= N)
279  break;
280  coordinates[pos] = v;
281  pos++;
282  }
283 }
284 
285 template<std::size_t N>
287  //std::cout << "Point::Operator=" << std::endl;
288  for(unsigned i = 0; i<N; i++){
289  coordinates[i] = other.coordinates[i];
290  }
291  this->boundry=other.boundry;
292  return *this;
293 }
294 
295 template<std::size_t N>
297  //std::cout << "Point::Operateur d'affectation par deplacement" << std::endl;
298  if (this != &other){
299  coordinates = std::move(other.coordinates);
300  other.coordinates.empty();
301  delete other.coordinates;
302  }
303  this->boundry=other.boundry;
304  return *this;
305 }
306 
307 template<std::size_t P>
308 std::ostream& operator<<(std::ostream& os, const Point<P>& point){
309  os << "(";
310  for(unsigned i=0; i<P; i++){
311  os << point.getCoord(i);
312  if (i != P-1)
313  os << ", ";
314  }
315  os << ")";
316  return os;
317 }
318 
319 template<std::size_t N>
320 void Point<N>::setCoord(unsigned int index, double val){
321  if (index >= N) {
322  std::cerr << "Depassement !" << std::endl;
323  abort();
324  }
325  coordinates[index] = val;
326 }
327 
328 template<std::size_t N>
329 void Point<N>::setCoords(double val, ...){
330  this->setCoord(0, val);
331  va_list ap;
332 
333  va_start(ap,NULL);
334  for (unsigned i = 1; i<N; i++){
335  this->setCoord(i, va_arg(ap,double));
336  }
337  va_end(ap);
338 }
339 
340 template<std::size_t N>
341 double Point<N>::getCoord(unsigned int index) const{
342  return coordinates[index];
343 }
344 
345 template<std::size_t N>
347  double MIN_VALUE = -250.0;
348  double MAX_VALUE = 250.0;
349 
350  for (unsigned int i =0; i<N; i++){
351  if (this->getCoord(i) < MIN_VALUE || this->getCoord(i) > MAX_VALUE){
352  return true;
353  }
354  }
355 
356  return false;
357 }
358 
359 template<std::size_t N>
360 bool Point<N>::operator==(Point<N> const& other){
361  for (unsigned i=0; i<N; i++){
362  if (other.getCoord(i) != this->getCoord(i))
363  return false;
364  }
365  return true;
366 }
367 
368 template<std::size_t N>
369 bool Point<N>::operator<(const Point<N>& other) const{
370  for (unsigned i=0; i<N; i++){
371  if (other.getCoord(i) > this->getCoord(i))
372  return false;
373  }
374  return true;
375 }
376 
377 template<std::size_t N>
378 bool Point<N>::operator>(const Point<N>& other) const{
379  return !(*this<other || *this==other);
380 }
381 
382 template<std::size_t N>
383 bool Point<N>::operator<=(const Point<N>& other) const{
384  return !(*this>other);
385 }
386 
387 template<std::size_t N>
388 bool Point<N>::operator>=(const Point<N>& other) const{
389  return !(*this<other);
390 }
391 
392 template<std::size_t N>
393 double Point<N>::distance(const Point<N>& other) const{
394  Point<N> diffOfPoints;
395  double dist = 0.0;
396  for (unsigned int i=0; i<N; i++){
397  dist += (this->getCoord(i)-other.getCoord(i))*(this->getCoord(i)-other.getCoord(i));
398  }
399  return std::sqrt(dist);
400 }
401 
402 template<std::size_t N>
404  boundry= true;
405 }
406 
407 template<std::size_t N>
409  return boundry;
410 }
411 
412 #endif
const Point & operator=(Point &&other)
Opérateur d’affectation par déplacement.
Definition: point.hpp:296
bool operator>=(const Point &other) const
Opérateur de supériorité
Definition: point.hpp:388
bool operator<(const Point &other) const
Opérateur d'infériorité stricte.
Definition: point.hpp:369
bool operator==(Point const &other)
Opérateur d'égalité
Definition: point.hpp:360
bool isBoundry()
Détermine si le point est une borne.
Definition: point.hpp:408
bool outOfBoundries()
Determine si le point est dans une zone statique.
Definition: point.hpp:346
Point()
Constructeur.
Definition: point.hpp:232
bool operator<=(const Point &other) const
Opérateur d'infériorité
Definition: point.hpp:383
double getCoord(unsigned int index) const
Getter d'une coordonnée.
Definition: point.hpp:341
void setCoords(double val,...)
Setter d'un nombre variable de coordonnées.
Definition: point.hpp:329
void setCoord(unsigned int index, double val)
setter d'une coordonnée du point e la coordonnée d'index index du point
Definition: point.hpp:320
void toBoundry()
Identificateur d'un point comme borne.
Definition: point.hpp:403
double distance(const Point< N > &other) const
Calcul de distance entre deux points.
Definition: point.hpp:393
bool operator>(const Point &other) const
Opérateur de supériorité strict.
Definition: point.hpp:378
classe representant un point dans un espace de dimension N
Definition: point.hpp:29