Board  0.9.5
Path.h
Go to the documentation of this file.
1 /* -*- mode: c++ -*- */
26 #ifndef BOARD_PATH_H
27 #define BOARD_PATH_H
28 
29 #include <initializer_list>
30 #include <iostream>
31 #include <vector>
32 #include "board/Point.h"
33 #include "board/Rect.h"
34 #include "board/Transforms.h"
35 
36 // TODO : Add a resample (uniformly wrt to length) method
37 
38 namespace LibBoard
39 {
40 
45 struct Path {
46 
47  typedef std::vector<Point>::size_type size_type;
48 
49  enum OpenClosed
50  {
51  OpenPath,
52  ClosedPath
53  };
54 
55  Path() : _openClosed(OpenPath) {}
56 
57  Path(const std::vector<Point> & points, OpenClosed openClosed) : _points(points), _openClosed(openClosed) {}
58 
59  Path(std::initializer_list<Point> points);
60 
61  // Path(std::initializer_list<Point> points);
62 
63  explicit Path(OpenClosed openClosed) : _openClosed(openClosed) {}
64 
65  inline void clear();
66 
67  inline bool isClosed() const;
68 
69  inline bool isOpen() const;
70 
71  inline bool empty() const;
72 
73  inline std::size_t size() const;
74 
75  inline void close();
76 
77  inline OpenClosed openClosed() const;
78 
79  inline void open();
80 
81  inline void setOpenClosed(OpenClosed openClosed);
82 
87  Point center() const;
88 
96  Path & operator<<(const Point & p);
97 
105  Path & operator<<(const std::vector<Point> & v);
106 
112  Path & pop_back();
113 
119  Path & push_back(const Point & p);
120 
126  inline const Point & front() const;
127 
133  inline const Point & back() const;
134 
142  inline Point & operator[](const std::size_t n);
143 
151  inline const Point & operator[](const std::size_t n) const;
152 
161  Path & rotate(double angle, const Point & center);
162 
172  Path & rotateDeg(double angle, const Point & center);
173 
183  Path rotated(double angle, const Point & center) const;
184 
194  Path rotatedDeg(double angle, const Point & center) const;
195 
203  Path & rotate(double angle);
204 
212  Path & rotateDeg(double angle);
213 
221  Path rotated(double angle) const;
222 
230  Path rotatedDeg(double angle) const;
231 
240  Path & translate(double dx, double dy);
241 
250  Path translated(double dx, double dy) const;
251 
258  Path & moveCenter(double x, double y);
259 
265  Path & moveCenter(Point p);
266 
275  Path & scale(double sx, double sy);
276 
284  Path & scale(double s);
285 
294  Path scaled(double sx, double sy) const;
295 
303  Path scaled(double s) const;
304 
310  void scaleAll(double s);
311 
312  void flushPostscript(std::ostream & stream, const TransformEPS & transform) const;
313 
314  void flushFIG(std::ostream & stream, const TransformFIG & transform) const;
315 
316  void flushSVGPoints(std::ostream & stream, const TransformSVG & transform) const;
317 
318  void flushSVGCommands(std::ostream & stream, const TransformSVG & transform) const;
319 
320  void flushTikZPoints(std::ostream & stream, const TransformTikZ & transform) const;
321 
322  Path transformed(const Transform & transform) const;
323 
328  bool isClockwise() const;
329 
334  bool isCounterclockwise() const;
335 
339  void setClockwise();
340 
344  void setCounterclockwise();
345 
350  Path getClockwise() const;
351 
356  Path getCounterclockwise() const;
357 
363  Rect boundingBox() const;
364 
365  const std::vector<Point> & points() const;
366 
367  std::ostream & flush(std::ostream &) const;
368 
369  inline std::vector<Point>::const_iterator begin() const;
370  inline std::vector<Point>::const_iterator cbegin() const;
371  inline std::vector<Point>::const_iterator end() const;
372  inline std::vector<Point>::const_iterator cend() const;
373 
374 protected:
375  std::vector<Point> _points;
376  OpenClosed _openClosed;
377 };
378 
386 Path mid(const Path & a, const Path & b, double time);
387 
388 // Inline methods
389 
390 void Path::clear()
391 {
392  _points.clear();
393 }
394 
395 Point & Path::operator[](const std::size_t n)
396 {
397  return _points[n];
398 }
399 
400 const Point & Path::operator[](const std::size_t n) const
401 {
402  return _points[n];
403 }
404 
405 std::vector<Point>::const_iterator Path::begin() const
406 {
407  return _points.begin();
408 }
409 
410 std::vector<Point>::const_iterator Path::cbegin() const
411 {
412  return _points.begin();
413 }
414 
415 std::vector<Point>::const_iterator Path::end() const
416 {
417  return _points.end();
418 }
419 
420 std::vector<Point>::const_iterator Path::cend() const
421 {
422  return _points.cend();
423 }
424 
425 bool Path::isClosed() const
426 {
427  return _openClosed == ClosedPath;
428 }
429 
430 bool Path::isOpen() const
431 {
432  return _openClosed == OpenPath;
433 }
434 
435 bool Path::empty() const
436 {
437  return _points.empty();
438 }
439 
440 std::size_t Path::size() const
441 {
442  return _points.size();
443 }
444 
445 void Path::close()
446 {
447  _openClosed = ClosedPath;
448 }
449 
450 Path::OpenClosed Path::openClosed() const
451 {
452  return _openClosed;
453 }
454 
455 void Path::open()
456 {
457  _openClosed = OpenPath;
458 }
459 
460 const Point & Path::front() const
461 {
462  return _points.front();
463 }
464 
465 const Point & Path::back() const
466 {
467  return _points.back();
468 }
469 
470 } // namespace LibBoard
471 
472 std::ostream & operator<<(std::ostream & out, const LibBoard::Path & path);
473 
474 #endif /* BOARD_PATH_H */
LibBoard::Path::front
const Point & front() const
Definition: Path.h:460
LibBoard::Path::center
Point center() const
Definition: Path.cpp:70
LibBoard::Path::scale
Path & scale(double sx, double sy)
Definition: Path.cpp:167
Point.h
The Point structure. @copyright This source code is part of the Board project, a C++ library whose pu...
LibBoard::Path::getCounterclockwise
Path getCounterclockwise() const
Return a counterclockwise copy of the path.
Definition: Path.cpp:349
Transforms.h
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
LibBoard::Path::setCounterclockwise
void setCounterclockwise()
Make the path counterclockwise.
Definition: Path.cpp:335
LibBoard::Path::rotated
Path rotated(double angle, const Point &center) const
Definition: Path.cpp:91
LibBoard::mid
Path mid(const Path &a, const Path &b, double time)
Definition: Path.cpp:387
LibBoard::Path::isCounterclockwise
bool isCounterclockwise() const
Tell if the points of the path are ordered counterclockwise.
Definition: Path.cpp:323
LibBoard::Rect
Struct representing a rectangle on the plane.
Definition: Rect.h:39
LibBoard::Path::moveCenter
Path & moveCenter(double x, double y)
Translate the center to a given position.
Definition: Path.cpp:153
LibBoard::Path::operator<<
Path & operator<<(const Point &p)
Definition: Path.cpp:47
LibBoard::Path::rotatedDeg
Path rotatedDeg(double angle, const Point &center) const
Definition: Path.cpp:103
LibBoard::Path::translate
Path & translate(double dx, double dy)
Definition: Path.cpp:128
LibBoard::Path::scaleAll
void scaleAll(double s)
Definition: Path.cpp:194
LibBoard::Path::getClockwise
Path getClockwise() const
Return a clockwise copy of the path.
Definition: Path.cpp:342
LibBoard::Transform
Definition: Transforms.h:46
LibBoard::Path::pop_back
Path & pop_back()
Definition: Path.cpp:35
LibBoard::Path::scaled
Path scaled(double sx, double sy) const
Definition: Path.cpp:184
LibBoard::Point
Struct representing a 2D point.
Definition: Point.h:42
LibBoard::Path::back
const Point & back() const
Definition: Path.h:465
LibBoard::Path::push_back
Path & push_back(const Point &p)
Definition: Path.cpp:41
LibBoard::TransformEPS
Structure representing a scaling and translation suitable for an EPS output.
Definition: Transforms.h:71
LibBoard::Path::boundingBox
Rect boundingBox() const
Definition: Path.cpp:356
LibBoard::Path::rotate
Path & rotate(double angle, const Point &center)
Definition: Path.cpp:75
LibBoard::Path::isClockwise
bool isClockwise() const
Tell if the points of the path are ordered clockwise.
Definition: Path.cpp:302
LibBoard::Path
A path, according to Postscript and SVG definition.
Definition: Path.h:45
LibBoard::Path::operator[]
Point & operator[](const std::size_t n)
Definition: Path.h:395
LibBoard::TransformTikZ
Structure representing a scaling and translation suitable for an TikZ output.
Definition: Transforms.h:126
LibBoard::Path::translated
Path translated(double dx, double dy) const
Definition: Path.cpp:140
LibBoard::TransformFIG
Structure representing a scaling and translation suitable for an XFig output.
Definition: Transforms.h:87
LibBoard::Path::setClockwise
void setClockwise()
Make the path clockwise.
Definition: Path.cpp:328
LibBoard::Path::rotateDeg
Path & rotateDeg(double angle, const Point &center)
Definition: Path.cpp:86
Rect.h
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
LibBoard::TransformSVG
Structure representing a scaling and translation suitable for an SVG output.
Definition: Transforms.h:109