DGtal  0.9.2
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 #if defined(__clang__)
26 #pragma clang diagnostic push
27 #pragma clang diagnostic ignored "-Wdocumentation"
28 #endif
29 #include <cairo.h>
30 #if defined(__clang__)
31 #pragma clang diagnostic pop
32 #endif
33 #endif
34 
35 namespace LibBoard {
36 
37 
38 
43 struct Path {
44 
45  Path() : _closed( false ) { }
46 
47  Path( const std::vector<Point> & points, bool closedPath )
48  : _points( points ), _closed( closedPath ) { }
49 
50  Path( bool closedPath ) : _closed( closedPath ) { }
51 
52  inline void clear();
53 
54  inline bool closed() const;
55 
56  inline bool empty() const;
57 
58  inline unsigned int size() const;
59 
60  inline void setClosed( bool closed );
61 
66  Point center() const;
67 
75  Path & operator<<( const Point & p );
76 
83  Path & pop_back();
84 
92  Point & operator[]( const unsigned int n ) {
93  return _points[ n ];
94  }
95 
103  const Point & operator[]( const unsigned int n ) const {
104  return _points[ n ];
105  }
106 
115  Path & rotate( double angle, const Point & center );
116 
125  Path rotated( double angle, const Point & center ) const;
126 
134  Path & rotate( double angle );
135 
143  Path rotated( double angle ) const;
144 
153  Path & translate( double dx, double dy );
154 
163  Path translated( double dx, double dy ) const;
164 
173  Path & scale( double sx, double sy );
174 
182  Path & scale( double s );
183 
192  Path scaled( double sx, double sy ) const;
193 
194  Path scaled( double s ) const;
195 
201  void scaleAll( double s );
202 
203  void flushPostscript( std::ostream & stream,
204  const TransformEPS & transform ) const;
205 
206  void flushFIG( std::ostream & stream,
207  const TransformFIG & transform ) const;
208 
209  void flushSVGPoints( std::ostream & stream,
210  const TransformSVG & transform ) const;
211 
212  void flushSVGCommands( std::ostream & stream,
213  const TransformSVG & transform ) const;
214 
215 #ifdef WITH_CAIRO
216  void flushCairoPoints( cairo_t *cr,
217  const TransformCairo & transform ) const;
218 #endif
219 
220  void flushTikZPoints( std::ostream & stream,
221  const TransformTikZ & transform ) const;
222 
223  Rect boundingBox() const;
224 
225 protected:
226  std::vector<Point> _points;
227  bool _closed;
228 };
229 
230 void
232 {
233  _points.clear();
234 }
235 
236 bool
238 {
239  return _closed;
240 }
241 
242 bool
243 Path::empty() const
244 {
245  return _points.empty();
246 }
247 
248 unsigned int
249 Path::size() const
250 {
251  return (unsigned int)_points.size();
252 }
253 
254 void
255 Path::setClosed( bool closedPath )
256 {
257  _closed = closedPath;
258 }
259 
260 } // namespace LibBoard
261 
262 #endif /* _PATH_H_ */
263 
Path & scale(double sx, double sy)
Definition: Path.cpp:108
void flushTikZPoints(std::ostream &stream, const TransformTikZ &transform) const
Definition: Path.cpp:255
Path & operator<<(const Point &p)
Definition: Path.cpp:29
void flushSVGCommands(std::ostream &stream, const TransformSVG &transform) const
Definition: Path.cpp:193
void flushSVGPoints(std::ostream &stream, const TransformSVG &transform) const
Definition: Path.cpp:215
Structure representing a scaling and translation suitable for an TikZ output.
Definition: Transforms.h:129
Rect boundingBox() const
Definition: Path.cpp:272
Point & operator[](const unsigned int n)
Definition: Path.h:92
Path & translate(double dx, double dy)
Definition: Path.cpp:81
Structure representing a scaling and translation suitable for an Cairo output.
Definition: Transforms.h:112
unsigned int size() const
Definition: Path.h:249
Point center() const
Definition: Path.cpp:36
void setClosed(bool closed)
Definition: Path.h:255
Path(const std::vector< Point > &points, bool closedPath)
Definition: Path.h:47
A path, according to Postscript and SVG definition.
Definition: Path.h:43
Path scaled(double sx, double sy) const
Definition: Path.cpp:131
Struct representing a 2D point.
Definition: Point.h:27
Path rotated(double angle, const Point &center) const
Definition: Path.cpp:55
Path & pop_back()
Definition: Path.cpp:22
Structure representing a scaling and translation suitable for an XFig output.
Definition: Transforms.h:73
std::vector< Point > _points
Definition: Path.h:226
bool empty() const
Definition: Path.h:243
Path & rotate(double angle, const Point &center)
Definition: Path.cpp:43
Structure representing a scaling and translation suitable for an SVG output.
Definition: Transforms.h:95
void scaleAll(double s)
Definition: Path.cpp:143
bool _closed
Definition: Path.h:227
void clear()
Definition: Path.h:231
Path translated(double dx, double dy) const
Definition: Path.cpp:94
const Point & operator[](const unsigned int n) const
Definition: Path.h:103
Structure representing a scaling and translation suitable for an EPS output.
Definition: Transforms.h:59
bool closed() const
Definition: Path.h:237
Struct representing a rectangle on the plane.
Definition: Rect.h:26
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition: Path.cpp:154
void flushCairoPoints(cairo_t *cr, const TransformCairo &transform) const
Definition: Path.cpp:235
Path(bool closedPath)
Definition: Path.h:50
void flushFIG(std::ostream &stream, const TransformFIG &transform) const
Definition: Path.cpp:173