xc
BND2d.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 //BND2d.h
22 
23 #ifndef BND2D_H
24 #define BND2D_H
25 
26 #include "GeomObj2d.h"
27 #include "../cgal_types.h"
28 
29 class Segment2d;
30 class Ray2d;
31 class Polygon2d;
32 class Polyline2d;
33 
34 
36 //
38 class BND2d: public GeomObj2d
39  {
40  CGIsoRectangle_2 cgrectg;
41  bool undefined;
42  template <class inputIterator>
43  bool Overlap(inputIterator begin, inputIterator end) const;
44  protected:
45  inline bool In(const CGPoint_2 &p, const double &tol) const
46  { return In(Pos2d(p), tol); }
47  inline bool Overlap(const CGPoint_2 &p) const
48  { return Overlap(Pos2d(p)); }
49  public:
50  BND2d(void);
51  BND2d(const Pos2d &p_min,const Pos2d &p_max);
52  virtual GeomObj *getCopy(void) const
53  { return new BND2d(*this); }
54  inline bool isUndefined(void) const
55  { return undefined; }
56  inline virtual unsigned short int Dimension(void) const
57  //Return the dimension of the object 0, 1, 2 or 3.
58  { return 2; }
60  inline virtual GEOM_FT getWidth(void) const
61  { return GetXMax()-GetXMin(); }
63  inline GEOM_FT getHeight(void) const
64  { return GetYMax()-GetYMin(); }
65 
66  Polygon2d getPolygon(void) const;
67  const GeomObj::list_Pos2d &getVertexList(void) const;
68  boost::python::list getVertexListPy(void) const;
70  inline virtual GEOM_FT getLength(void) const
71  { return 2*getWidth()+2*getHeight(); }
72  Vector2d Diagonal(void) const;
73  virtual GEOM_FT getArea(void) const;
75  inline virtual GEOM_FT getVolume(void) const
76  { return 0.0; }
77  virtual GEOM_FT Ix(void) const;
78  virtual GEOM_FT Iy(void) const;
79  inline virtual GEOM_FT Pxy(void) const
80  { return 0.0; }
81 
82  void Update(const Pos2d &);
83  void PutPMax(const Pos2d &);
84  void PutPMin(const Pos2d &);
85  void PutPMinMax(const Pos2d &,const Pos2d &);
86  Pos2d getPMax(void) const;
87  Pos2d getPMin(void) const;
88  inline GEOM_FT GetMax(unsigned short int i) const
89  { return cgrectg.max_coord(i-1); }
90  inline GEOM_FT GetMin(unsigned short int i) const
91  { return cgrectg.min_coord(i-1); }
92 
93  Pos2d getCenterOfMass(void) const;
94 
95  bool In(const Pos2d &, const double &tol= 0.0) const;
96  template <class inputIterator>
97  bool In(inputIterator begin, inputIterator end, const double &tol= 0.0) const;
98  bool In(const Polyline2d &, const double &tol= 0.0) const;
99  bool In(const Polygon2d &, const double &tol= 0.0) const;
100  bool Overlap(const Pos2d &) const;
101  bool Overlap(const Line2d &r) const;
102  bool Overlap(const Ray2d &sr) const;
103  bool Overlap(const Segment2d &sg) const;
104  bool Overlap(const BND2d &) const;
105  bool Overlap(const Polyline2d &) const;
106  bool Overlap(const Polygon2d &) const;
107  bool Overlap(const std::list<Polygon2d> &) const;
108  bool Interseca(const Line2d &r) const;
109  bool Interseca(const Ray2d &sr) const;
110  bool Interseca(const Segment2d &sg) const;
111  bool Interseca(const BND2d &) const;
112 
113  void Transform(const Trf2d &trf2d);
114 
115  BND2d &operator+=(const Pos2d &p);
116  BND2d &operator+=(const BND2d &a);
117  friend BND2d operator+(const BND2d &a, const BND2d &b);
118  friend bool operator==(const BND2d &a,const BND2d &b);
119  void Print(std::ostream &stream) const;
120  void Plot(Plotter &) const;
121  };
122 
123 inline bool intersecan(const Line2d &r,const BND2d &bnd)
124  { return bnd.Interseca(r); }
125 inline bool intersecan(const Ray2d &sr,const BND2d &bnd)
126  { return bnd.Interseca(sr); }
127 inline bool intersecan(const Segment2d &sg,const BND2d &bnd)
128  { return bnd.Interseca(sg); }
129 inline bool intersecan(const BND2d &bnd,const Line2d &r)
130  { return bnd.Interseca(r); }
131 inline bool intersecan(const BND2d &bnd,const Ray2d &sr)
132  { return bnd.Interseca(sr); }
133 inline bool intersecan(const BND2d &bnd,const Segment2d &sg)
134  { return bnd.Interseca(sg); }
135 
138 template <class inputIterator>
139 bool BND2d::In(inputIterator begin, inputIterator end, const double &tol) const
140  {
141  bool retval= true;
142  for(inputIterator i= begin;i!=end;i++)
143  if(!this->In(*i, tol))
144  {
145  retval= false;
146  break;
147  }
148  return retval;
149  }
150 
153 template <class inputIterator>
154 bool BND2d::Overlap(inputIterator begin, inputIterator end) const
155  {
156  bool retval= false;
157  for(inputIterator i= begin;i!=end;i++)
158  if(Overlap(*i))
159  {
160  retval= true;
161  break;
162  }
163  return retval;
164  }
165 
166 #endif
virtual GEOM_FT Pxy(void) const
!
Definition: BND2d.h:79
"boundary" en dos dimensiones.
Definition: BND2d.h:38
GEOM_FT GetMax(unsigned short int i) const
Return the maximum value of the i-th coordinate.
Definition: BND2d.h:88
const GeomObj::list_Pos2d & getVertexList(void) const
Return a list with the object vertices.
Definition: BND2d.cc:101
virtual GEOM_FT getArea(void) const
Return the object area.
Definition: BND2d.cc:126
Base class for position lists.
Definition: PolyPos.h:35
virtual GEOM_FT getWidth(void) const
Return object width (x axis).
Definition: BND2d.h:60
Posición en dos dimensiones.
Definition: Pos2d.h:41
Line in a two-dimensional space.
Definition: Line2d.h:61
BND2d(void)
Constructor.
Definition: BND2d.cc:40
Base class for two-dimensional transformations.
Definition: Trf2d.h:40
GEOM_FT getHeight(void) const
Return object height (z axis).
Definition: BND2d.h:63
virtual GEOM_FT Ix(void) const
Moment of inertia with respect to the center of mass en local axis.
Definition: BND2d.cc:148
Vector en dos dimensiones.
Definition: Vector2d.h:40
virtual GEOM_FT getVolume(void) const
Return the volume of the object.
Definition: BND2d.h:75
Base class for the two-dimensional geometric objects.
Definition: GeomObj2d.h:37
virtual unsigned short int Dimension(void) const
Return the dimension of the object 0, 1, 2 or 3.
Definition: BND2d.h:56
virtual GEOM_FT getLength(void) const
Return the object length.
Definition: BND2d.h:70
Polígono en dos dimensiones.
Definition: Polygon2d.h:38
Segment in a two-dimensional space.
Definition: Segment2d.h:38
boost::python::list getVertexListPy(void) const
Return a Python list with the object vertices.
Definition: BND2d.cc:115
void Transform(const Trf2d &trf2d)
Aplica al objeto la transformación que se pasa como parámetro.
Definition: BND2d.cc:290
Polyline in a two-dimensional space.
Definition: Polyline2d.h:41
virtual GEOM_FT Iy(void) const
Moment of inertia with respect to the center of mass en local axis.
Definition: BND2d.cc:155
Clase base para las entidades geométricas.
Definition: GeomObj.h:40
Ray in a two-dimensional space.
Definition: Ray2d.h:35
GEOM_FT GetMin(unsigned short int i) const
Return the minimum value of the i-th coordinate.
Definition: BND2d.h:90