xc
Pos2d.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. Pérez Tato
6 //
7 // XC utils 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 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // 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.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //Pos2d.h
22 
23 #ifndef POS2D_H
24 #define POS2D_H
25 
26 
27 #include <string>
28 #include "../cgal_types.h"
29 #include "../ProtoGeom.h"
30 
31 class Vector2d;
32 class Plotter;
33 class Line2d;
34 class Ray2d;
35 class Segment2d;
36 class Polygon2d;
37 
39 //
41 class Pos2d: public ProtoGeom
42  {
43  CGPoint_2 cgpt;
44  public:
45  typedef Vector2d vector;
46 
47  Pos2d(void);
48  explicit Pos2d(const CGPoint_2 &p);
49  Pos2d(const GEOM_FT &Ax,const GEOM_FT &Ay);
50  Pos2d(const GEOM_RT &x,const GEOM_RT &y,const GEOM_RT &h);
51 
52  bool notAPoint(void) const;
53  Pos2d &operator+=(const Vector2d &v);
54  Pos2d &operator-=(const Vector2d &v);
55  Vector2d operator-(const Pos2d &) const;
56  Pos2d operator-(const Vector2d &) const;
57  Pos2d operator+(const Vector2d &) const;
58  virtual bool operator==(const Pos2d &) const;
59  inline bool operator!=(const Pos2d &other) const
60  { return !(*this==other); }
61  const CGPoint_2 &ToCGAL(void) const
62  { return cgpt; }
63  inline GEOM_FT operator()(const size_t &i) const //Base 1
64  { return cgpt.cartesian(i-1); }
65  inline GEOM_FT at0(const size_t &j) const //Base 0
66  { return cgpt.cartesian(j); }
67  inline GEOM_FT operator[](const size_t &j) const //Base 0
68  { return at0(j); }
69  inline GEOM_FT x() const
70  { return Pos2d::operator()(1); }
71  inline GEOM_FT y() const
72  { return Pos2d::operator()(2); }
73  inline const GEOM_RT hx() const
74  { return cgpt.hx(); }
75  inline const GEOM_RT hy() const
76  { return cgpt.hy(); }
77  inline const GEOM_RT hw() const
78  { return cgpt.hw(); }
79 
80  void SetX(const GEOM_FT &vx);
81  void SetY(const GEOM_FT &vy);
82  void Set(unsigned short int i,const GEOM_FT &v);
83 
84  size_t dimension(void) const
85  { return cgpt.dimension(); }
86  Vector2d VectorPos(void) const;
87  bool domina_a(const Pos2d &) const;
88  GEOM_FT dist(const Pos2d &) const;
89  GEOM_FT dist2(const Pos2d &) const;
90  GEOM_FT dist2(const Line2d &) const;
91  GEOM_FT dist(const Line2d &) const;
92  GEOM_FT dist2(const Ray2d &) const;
93  GEOM_FT dist(const Ray2d &) const;
94  GEOM_FT dist2(const Segment2d &) const;
95  GEOM_FT dist(const Segment2d &) const;
96 
97  friend bool colineales(const Pos2d &p1,const Pos2d &p2,const Pos2d &p3);
98 
99  Polygon2d getBufferPolygon(const GEOM_FT &d, const size_t &numVertices= 8) const;
100 
101  void Print(std::ostream &os) const;
102  void Plot(Plotter &psos) const;
103 
104  boost::python::dict getPyDict(void) const;
105  void setPyDict(const boost::python::dict &);
106  };
107 
108 std::ostream &operator << (std::ostream &stream,const Pos2d &n);
109 
110 inline GEOM_FT dist2(const Pos2d &p1,const Pos2d &p2)
111  { return p1.dist2(p2); }
112 
113 inline GEOM_FT dist(const Pos2d &p1,const Pos2d &p2)
114  { return p1.dist(p2); }
115 
116 inline Pos2d pos_max(const Pos2d &a,const Pos2d &b)
117 { return Pos2d(std::max(a.x(),b.x()),std::max(a.y(),b.y())); }
118 inline Pos2d pos_min(const Pos2d &a,const Pos2d &b)
119  { return Pos2d(std::min(a.x(),b.x()),std::min(a.y(),b.y())); }
120 
121 const Pos2d Origin2d;
122 
123 #endif
124 
125 
126 
GEOM_FT dist(const Pos2d &) const
Return the distance to the point.
Definition: Pos2d.cc:147
virtual bool operator==(const Pos2d &) const
Comparison operator.
Definition: Pos2d.cc:92
Posición en dos dimensiones.
Definition: Pos2d.h:41
Pos2d & operator+=(const Vector2d &v)
Adds a vector.
Definition: Pos2d.cc:57
bool notAPoint(void) const
return true if one of the coordinate components is not a number.
Definition: Pos2d.cc:53
Line in a two-dimensional space.
Definition: Line2d.h:61
Polygon2d getBufferPolygon(const GEOM_FT &d, const size_t &numVertices=8) const
Return a buffer polygon around the point.
Definition: Pos2d.cc:184
Vector en dos dimensiones.
Definition: Vector2d.h:40
Pos2d(void)
Default constructor.
Definition: Pos2d.cc:37
Base class for geometry objects.
Definition: ProtoGeom.h:33
Vector2d operator-(const Pos2d &) const
Vector between points.
Definition: Pos2d.cc:71
Polígono en dos dimensiones.
Definition: Polygon2d.h:38
Segment in a two-dimensional space.
Definition: Segment2d.h:38
Pos2d & operator-=(const Vector2d &v)
Substracts a vector.
Definition: Pos2d.cc:64
boost::python::dict getPyDict(void) const
Return a Python dictionary with the object members values.
Definition: Pos2d.cc:196
Vector2d VectorPos(void) const
Return the position vector of the point.
Definition: Pos2d.cc:107
Pos2d operator+(const Vector2d &) const
Return the point obtained by adding the vector.
Definition: Pos2d.cc:85
Ray in a two-dimensional space.
Definition: Ray2d.h:35
GEOM_FT dist2(const Pos2d &) const
Return the squared distance to the point.
Definition: Pos2d.cc:151
void setPyDict(const boost::python::dict &)
Set the values of the object members from a Python dictionary.
Definition: Pos2d.cc:205