ISeeML  1.0
Point.hpp
1 //
2 // Definition of iSeeML::geom::Point, class of ISeeML' 2D geometric
3 // points.
4 //
5 
6 // To only include this definition once
7 #ifndef ISEEML_GEOM_POINT_HH
8 #define ISEEML_GEOM_POINT_HH
9 
10 
11 // This class needs the definition of iSeeML::geom::Vector.
12 #include <iSeeML/geom/Vector.hpp>
13 
14 
30  // === Object's Fields ==========================================
31 
32  double XCoord;
33  double YCoord;
34 
35 public:
40  static const string ClassName;
41 
42 
43  // === Constructors and Destructors =============================
44 
46  Point() : XCoord(0), YCoord(0) {}
47 
57  Point(const double& x, const double& y) :
58  XCoord(x), YCoord(y) {}
59 
60  // The default copy constructor is OK.
61 
62 
63  // === Description Methods ======================================
64 
73  { return *( (iSeeML::Object*) (new Point(*this)) ); }
74 
75 
83  void writeTo(ostream& O) const { algWriteTo(O); }
84 
85 
90  const double& xCoord() const { return XCoord; }
91 
96  const double& yCoord() const { return YCoord; }
97 
98 protected:
107  int algDimension() const { return 2; }
108 
123  double algCoord(const int i) const {
124  switch (i) { case 1 : return xCoord();
125  case 2 : return yCoord(); default:
126 #ifdef ISEEML_CHECK_GEOM_POINT_PRECOND
127  cerr << ClassName << "::coord: parameter " << i << endl
128  << " outside allowed values (1 or 2), returning zero..."
129  << endl;
130 #endif
131  return 0; } }
132 
133 public:
134  // === Modification Methods =====================================
135 
147  Point& moveTo(const double& x, const double& y)
148  { XCoord = x; YCoord = y; return *this; }
149 
160  { XCoord += v.xCoord(); YCoord += v.yCoord(); return *this; }
161 
162 
163  // === Operators ================================================
164 
173  bool operator==(const Point& other) const
174  { return( isZero( xCoord() - other.xCoord() ) &&
175  isZero( yCoord() - other.yCoord() ) ); }
176 
177 
188  { Point res(*this); return res.translate(v); }
189 
201  { return( *this + (-v) ); }
202 
203 
212  iSeeML::geom::Vector operator-(const Point& other) const
213  { return( Vector( xCoord() - other.xCoord(),
214  yCoord() - other.yCoord() ) ); }
215 
216 
217  // === Various Methods ==========================================
218 
230  double distance(const Point& other) const
231  { return( (other - *this).length() ); }
232 
244  double sqrDist(const Point& other) const
245  { return( (other - *this).sqrLength() ); }
246 
247 }; // end of class iSeeML::geom::Point
248 
249 #endif // end of definition
250 
251 
This class defines 2D geometric vectors, which can be defined by their Polar or Cartesian coordinates...
Definition: Vector.hpp:34
This class is the base class of ISeeML: every class of ISeeML inherits this one.
Definition: Object.hpp:47
void writeTo(ostream &O) const
Description method, writing a description of the point into a stream: Cartesian coordinate in each di...
Definition: Point.hpp:83
const double & xCoord() const
Description method, giving the point&#39;s first coordinate.
Definition: Point.hpp:90
static const string ClassName
The class name is public, as this class can be instanced.
Definition: Point.hpp:40
Point()
The default constructor, returning the frame origin (0,0).
Definition: Point.hpp:46
This class defines basic 2D geometric objects, from which compound geometric objects are built...
Definition: BasicObject.hpp:21
iSeeML::geom::Vector operator-(const Point &other) const
Difference operator between two points, giving the vector connecting these points.
Definition: Point.hpp:212
double algCoord(const int i) const
Description method, giving Cartesian coordinate of given index of the point.
Definition: Point.hpp:123
virtual void algWriteTo(ostream &O) const
Description method for algebraic vectors, writing this vector in a given output stream: coordinates f...
Definition: Object.hpp:161
bool operator==(const Point &other) const
Equality operator between points.
Definition: Point.hpp:173
Point & translate(const iSeeML::geom::Vector &v)
Modification method, translating the point along a vector.
Definition: Point.hpp:159
double distance(const Point &other) const
Various method, giving the distance between two points.
Definition: Point.hpp:230
Point operator-(const iSeeML::geom::Vector &v) const
Difference operator between a point and a vector, giving the translation of the current point along t...
Definition: Point.hpp:200
int algDimension() const
Description method, giving the dimension of the containing space (2) when this point is considered as...
Definition: Point.hpp:107
const double & xCoord() const
Description method, giving the vector&#39;s first Cartesian coordinate.
Definition: Vector.hpp:111
Point operator+(const iSeeML::geom::Vector &v) const
Sum operator between a point and a vector, giving the translation of the current point along the vect...
Definition: Point.hpp:187
This class defines 2D geometric points, defined by their Cartesian coordinates.
Definition: Point.hpp:29
Point & moveTo(const double &x, const double &y)
Modification method, moving the point to a given position.
Definition: Point.hpp:147
const double & yCoord() const
Description method, giving the vector&#39;s second Cartesian coordinate.
Definition: Vector.hpp:118
static bool isZero(const double &x)
Method comparing a double to zero.
Definition: Object.hpp:288
Point(const double &x, const double &y)
The main constructor, creating a point from its Cartesian coordinates (Polar coordinates are not used...
Definition: Point.hpp:57
double sqrDist(const Point &other) const
Gives the square of the distance between two points.
Definition: Point.hpp:244
const double & yCoord() const
Description method, giving the point&#39;s second coordinate.
Definition: Point.hpp:96
iSeeML::Object & clone() const
Description method, giving a copy of the current point.
Definition: Point.hpp:72