bpp-core3  3.0.0
Point2D.h
Go to the documentation of this file.
1 //
2 // File: Point2D.h
3 // Authors:
4 // Sylvain Gaillard
5 // Julien Dutheil
6 //
7 
8 /*
9  Copyright or © or Copr. CNRS, (November 17, 2004)
10 
11  This software is a computer program whose purpose is to provide classes
12  for population genetics analysis.
13 
14  This software is governed by the CeCILL license under French law and
15  abiding by the rules of distribution of free software. You can use,
16  modify and/ or redistribute the software under the terms of the CeCILL
17  license as circulated by CEA, CNRS and INRIA at the following URL
18  "http://www.cecill.info".
19 
20  As a counterpart to the access to the source code and rights to copy,
21  modify and redistribute granted by the license, users are provided only
22  with a limited warranty and the software's author, the holder of the
23  economic rights, and the successive licensors have only limited
24  liability.
25 
26  In this respect, the user's attention is drawn to the risks associated
27  with loading, using, modifying and/or developing or reproducing the
28  software by the user in light of its specific status of free software,
29  that may mean that it is complicated to manipulate, and that also
30  therefore means that it is reserved for developers and experienced
31  professionals having in-depth computer knowledge. Users are therefore
32  encouraged to load and test the software's suitability as regards their
33  requirements in conditions enabling the security of their systems and/or
34  data to be ensured and, more generally, to use and operate it in the
35  same conditions as regards security.
36 
37  The fact that you are presently reading this means that you have had
38  knowledge of the CeCILL license and that you accept its terms.
39 */
40 
41 #ifndef BPP_GRAPHICS_POINT2D_H
42 #define BPP_GRAPHICS_POINT2D_H
43 
44 
45 #include "../Clonable.h"
46 
47 namespace bpp
48 {
57 template<class T> class Point2D :
58  public virtual Clonable
59 {
60 private:
61  T x_;
62  T y_;
63 
64 public:
65  // Constructors and destructor :
66 
75  Point2D<T>(const T x = 0, const T y = 0) : x_(x), y_(y) {}
76 
80  virtual ~Point2D() {}
81 
82 public:
83  // Methodes
84 
88  Point2D<T>* clone() const { return new Point2D(*this); }
89 
93  void setCoord(const T x, const T y);
94 
98  void setX(const T x) { x_ = x; }
99 
103  void setY(const T y) { y_ = y; }
104 
108  const T& getX() const { return x_; }
109 
113  const T& getY() const { return y_; }
114 
120  bool hasSameCoordsAs(const Point2D<T>& coord) const
121  {
122  return x_ == coord.x_ && y_ == coord.y_;
123  }
124 
131  virtual bool operator==(const Point2D<T>& coord) const
132  {
133  return hasSameCoordsAs(coord);
134  }
135 
139  virtual bool operator!=(const Point2D<T>& coord) const
140  {
141  return !hasSameCoordsAs(coord);
142  }
143 };
144 } // end of namespace bpp;
145 #endif // BPP_GRAPHICS_POINT2D_H
The Clonable interface (allow an object to be cloned).
Definition: Clonable.h:103
The Point2D class.
Definition: Point2D.h:59
virtual bool operator==(const Point2D< T > &coord) const
The == operator.
Definition: Point2D.h:131
virtual ~Point2D()
Destroy the Point2D object.
Definition: Point2D.h:80
void setCoord(const T x, const T y)
Set the two values.
void setY(const T y)
Set only the latitude.
Definition: Point2D.h:103
const T & getY() const
Get the latitude.
Definition: Point2D.h:113
void setX(const T x)
Set only the longitude.
Definition: Point2D.h:98
const T & getX() const
Get the longitude.
Definition: Point2D.h:108
bool hasSameCoordsAs(const Point2D< T > &coord) const
Compares two Point2D objets.
Definition: Point2D.h:120
Point2D< T > * clone() const
Implement the Clonable interface.
Definition: Point2D.h:88
virtual bool operator!=(const Point2D< T > &coord) const
The != operator.
Definition: Point2D.h:139
Point2D(const T x=0, const T y=0)
Build a new Point2D from two values.
Definition: Point2D.h:75