bpp-core3  3.0.0
Point2D.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_GRAPHICS_POINT2D_H
6 #define BPP_GRAPHICS_POINT2D_H
7 
8 
9 #include "../Clonable.h"
10 
11 namespace bpp
12 {
21 template<class T> class Point2D :
22  public virtual Clonable
23 {
24 private:
25  T x_;
26  T y_;
27 
28 public:
29  // Constructors and destructor :
30 
39  Point2D<T>(const T x = 0, const T y = 0) : x_(x), y_(y) {}
40 
44  virtual ~Point2D() {}
45 
46 public:
47  // Methodes
48 
52  Point2D<T>* clone() const { return new Point2D(*this); }
53 
57  void setCoord(const T x, const T y);
58 
62  void setX(const T x) { x_ = x; }
63 
67  void setY(const T y) { y_ = y; }
68 
72  const T& getX() const { return x_; }
73 
77  const T& getY() const { return y_; }
78 
84  bool hasSameCoordsAs(const Point2D<T>& coord) const
85  {
86  return x_ == coord.x_ && y_ == coord.y_;
87  }
88 
95  virtual bool operator==(const Point2D<T>& coord) const
96  {
97  return hasSameCoordsAs(coord);
98  }
99 
103  virtual bool operator!=(const Point2D<T>& coord) const
104  {
105  return !hasSameCoordsAs(coord);
106  }
107 };
108 } // end of namespace bpp;
109 #endif // BPP_GRAPHICS_POINT2D_H
The Point2D class.
Definition: Point2D.h:21
virtual ~Point2D()
Destroy the Point2D object.
Definition: Point2D.h:44
void setY(const T y)
Set only the latitude.
Definition: Point2D.h:67
virtual bool operator==(const Point2D< T > &coord) const
The == operator.
Definition: Point2D.h:95
Point2D< T > * clone() const
Implement the Clonable interface.
Definition: Point2D.h:52
Point2D(const T x=0, const T y=0)
Build a new Point2D from two values.
Definition: Point2D.h:39
const T & getY() const
Get the latitude.
Definition: Point2D.h:77
const T & getX() const
Get the longitude.
Definition: Point2D.h:72
bool hasSameCoordsAs(const Point2D< T > &coord) const
Compares two Point2D objets.
Definition: Point2D.h:84
virtual bool operator!=(const Point2D< T > &coord) const
The != operator.
Definition: Point2D.h:103
void setX(const T x)
Set only the longitude.
Definition: Point2D.h:62
The Clonable interface (allow an object to be cloned).
Definition: Clonable.h:63
void setCoord(const T x, const T y)
Set the two values.