Xmipp  v3.23.11-Nereus
point2D.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: David Strelak (davidstrelak@gmail.com)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
26 #ifndef LIBRARIES_DATA_POINT2D_H_
27 #define LIBRARIES_DATA_POINT2D_H_
28 
29 #include "point.h"
30 #include <initializer_list>
31 
36 template<typename T>
37 class Point2D: Point {
38 public:
39  explicit Point2D(T x, T y) :
40  x(x), y(y) {
41  }
42 
43  Point2D(const std::initializer_list<T> &l) {
44  if (2 == l.size())
45  {
46  auto it = l.begin();
47  x = *it++;
48  y = *it++;
49  }
50  }
51 
52  T x; // FIXME DS this should be private member with setters / getters
53  T y;
54 
55 
56  Point2D operator/=(T rhs) const {
57  return Point2D(x / rhs, y / rhs);
58  }
59 
60  friend Point2D operator/(const Point2D &lhs, T rhs) {
61  return lhs /= rhs;
62  }
63 
64  Point2D operator-=(T rhs) const {
65  return Point2D(x - rhs, y - rhs);
66  }
67 
68  Point2D operator+=(T rhs) const {
69  return Point2D(x + rhs, y + rhs);
70  }
71 
72  Point2D operator+=(const Point2D &rhs) const {
73  return Point2D(x + rhs.x, y + rhs.y);
74  }
75 
76  Point2D operator+=(const Point2D &rhs) {
77  x += rhs.x;
78  y += rhs.y;
79  return *this;
80  }
81 
82  Point2D operator-=(const Point2D &rhs) const {
83  return Point2D(x - rhs.x, y - rhs.y);
84  }
85 
86  friend Point2D operator-(const Point2D &lhs, T rhs) {
87  return lhs -= rhs;
88  }
89 
90  friend Point2D operator+(const Point2D &lhs, T rhs) {
91  return lhs += rhs;
92  }
93 
94  friend Point2D operator+(const Point2D &lhs, const Point2D &rhs) {
95  return lhs += rhs;
96  }
97 
98  friend Point2D operator-(const Point2D &lhs, const Point2D &rhs) {
99  return lhs -= rhs;
100  }
101 };
103 #endif /* LIBRARIES_DATA_POINT2D_H_ */
Point2D operator-=(T rhs) const
Definition: point2D.h:64
T y
Definition: point2D.h:53
friend Point2D operator-(const Point2D &lhs, T rhs)
Definition: point2D.h:86
friend Point2D operator+(const Point2D &lhs, T rhs)
Definition: point2D.h:90
Definition: point.h:32
friend Point2D operator-(const Point2D &lhs, const Point2D &rhs)
Definition: point2D.h:98
friend Point2D operator+(const Point2D &lhs, const Point2D &rhs)
Definition: point2D.h:94
Point2D(T x, T y)
Definition: point2D.h:39
Point2D operator/=(T rhs) const
Definition: point2D.h:56
Point2D operator-=(const Point2D &rhs) const
Definition: point2D.h:82
T x
Definition: point2D.h:52
Point2D operator+=(T rhs) const
Definition: point2D.h:68
Point2D(const std::initializer_list< T > &l)
Definition: point2D.h:43
Point2D operator+=(const Point2D &rhs)
Definition: point2D.h:76
Point2D operator+=(const Point2D &rhs) const
Definition: point2D.h:72
friend Point2D operator/(const Point2D &lhs, T rhs)
Definition: point2D.h:60