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