DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Path.h
1 /* -*- mode: c++ -*- */
9 /*
10  * \@copyright This File is part of the Board library which is
11  * licensed under the terms of the GNU Lesser General Public Licence.
12  * See the LICENCE file for further details.
13  */
14 #ifndef _BOARD_PATH_H_
15 #define _BOARD_PATH_H_
16 
17 #include "Board/Point.h"
18 #include "Board/Rect.h"
19 #include "Board/Transforms.h"
20 #include <vector>
21 #include <iostream>
22 
23 #ifdef WITH_CAIRO
24 // cairo
25 #include <cairo.h>
26 #endif
27 
28 namespace LibBoard {
29 
30 
31 
36 struct Path {
37 
38  Path() : _closed( false ) { }
39 
40  Path( const std::vector<Point> & points, bool closedPath )
41  : _points( points ), _closed( closedPath ) { }
42 
43  Path( bool closedPath ) : _closed( closedPath ) { }
44 
45  inline void clear();
46 
47  inline bool closed() const;
48 
49  inline bool empty() const;
50 
51  inline unsigned int size() const;
52 
53  inline void setClosed( bool closed );
54 
59  Point center() const;
60 
68  Path & operator<<( const Point & p );
69 
76  Path & pop_back();
77 
85  Point & operator[]( const unsigned int n ) {
86  return _points[ n ];
87  }
88 
96  const Point & operator[]( const unsigned int n ) const {
97  return _points[ n ];
98  }
99 
108  Path & rotate( double angle, const Point & center );
109 
118  Path rotated( double angle, const Point & center ) const;
119 
127  Path & rotate( double angle );
128 
136  Path rotated( double angle ) const;
137 
146  Path & translate( double dx, double dy );
147 
156  Path translated( double dx, double dy ) const;
157 
166  Path & scale( double sx, double sy );
167 
175  Path & scale( double s );
176 
185  Path scaled( double sx, double sy ) const;
186 
187  Path scaled( double s ) const;
188 
194  void scaleAll( double s );
195 
196  void flushPostscript( std::ostream & stream,
197  const TransformEPS & transform ) const;
198 
199  void flushFIG( std::ostream & stream,
200  const TransformFIG & transform ) const;
201 
202  void flushSVGPoints( std::ostream & stream,
203  const TransformSVG & transform ) const;
204 
205  void flushSVGCommands( std::ostream & stream,
206  const TransformSVG & transform ) const;
207 
208 #ifdef WITH_CAIRO
209  void flushCairoPoints( cairo_t *cr,
210  const TransformCairo & transform ) const;
211 #endif
212 
213  void flushTikZPoints( std::ostream & stream,
214  const TransformTikZ & transform ) const;
215 
216  Rect boundingBox() const;
217 
218 protected:
219  std::vector<Point> _points;
220  bool _closed;
221 };
222 
223 void
224 Path::clear()
225 {
226  _points.clear();
227 }
228 
229 bool
230 Path::closed() const
231 {
232  return _closed;
233 }
234 
235 bool
236 Path::empty() const
237 {
238  return _points.empty();
239 }
240 
241 unsigned int
242 Path::size() const
243 {
244  return (unsigned int)_points.size();
245 }
246 
247 void
248 Path::setClosed( bool closedPath )
249 {
250  _closed = closedPath;
251 }
252 
253 } // namespace LibBoard
254 
255 #endif /* _PATH_H_ */
256