Board 0.9.6
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 <board/Point.h>
30#include <board/Rect.h>
31#include <board/Transforms.h>
32#include <initializer_list>
33#include <iostream>
34#include <vector>
35
36// TODO : Add a resample (uniformly wrt to length) method
37
38namespace LibBoard
39{
40
45struct Path {
46
47 typedef std::vector<Point>::size_type size_type;
48
53 {
55 Closed
56 };
57
59
65 Path(const std::vector<Point> & points, OpenClosed openClosed) : _points(points), _openClosed(openClosed) {}
66
71 Path(std::initializer_list<Point> points);
72
78
82 inline void clear();
83
88 inline bool isClosed() const;
89
94 inline bool isOpen() const;
95
100 inline bool empty() const;
101
106 inline std::size_t size() const;
107
111 inline void close();
112
116 inline void open();
117
122 inline OpenClosed openClosed() const;
123
129
134 Point center() const;
135
141 Path & operator<<(const Point & p);
142
148 Path & operator<<(const std::vector<Point> & v);
149
154 Path & pop_back();
155
160 Path & push_back(const Point & p);
161
166 inline const Point & front() const;
167
172 inline const Point & back() const;
173
179 inline Point & operator[](const std::size_t n);
180
186 inline const Point & operator[](const std::size_t n) const;
187
194 Path & rotate(double angle, const Point & center);
195
202 Path & rotateDeg(double angle, const Point & center);
203
210 Path rotated(double angle, const Point & center) const;
211
218 Path rotatedDeg(double angle, const Point & center) const;
219
225 Path & rotate(double angle);
226
232 Path & rotateDeg(double angle);
233
239 Path rotated(double angle) const;
240
246 Path rotatedDeg(double angle) const;
247
254 Path & translate(double dx, double dy);
255
262 Path translated(double dx, double dy) const;
263
270 Path & moveCenter(double x, double y);
271
277 Path & moveCenter(Point p);
278
285 Path & scale(double sx, double sy);
286
292 Path & scale(double s);
293
300 Path scaled(double sx, double sy) const;
301
307 Path scaled(double s) const;
308
313 void scaleAll(double s);
314
315 void flushPostscript(std::ostream & stream, const TransformEPS & transform) const;
316
317 void flushFIG(std::ostream & stream, const TransformFIG & transform) const;
318
319 void flushSVGPoints(std::ostream & stream, const TransformSVG & transform) const;
320
321 void flushSVGCommands(std::ostream & stream, const TransformSVG & transform) const;
322
323 void flushTikZPoints(std::ostream & stream, const TransformTikZ & transform) const;
324
330 Path transformed(const Transform & transform) const;
331
336 bool isClockwise() const;
337
342 bool isCounterclockwise() const;
343
347 void setClockwise();
348
352 void setCounterclockwise();
353
358 Path getClockwise() const;
359
365
371 Rect boundingBox() const;
372
373 const std::vector<Point> & points() const;
374
375 std::ostream & flush(std::ostream &) const;
376
377 inline std::vector<Point>::const_iterator begin() const;
378 inline std::vector<Point>::const_iterator cbegin() const;
379 inline std::vector<Point>::const_iterator end() const;
380 inline std::vector<Point>::const_iterator cend() const;
381
382protected:
383 std::vector<Point> _points;
385};
386
394Path mix(const Path & a, const Path & b, double time);
395
396// Inline methods
397
399{
400 _points.clear();
401}
402
403Point & Path::operator[](const std::size_t n)
404{
405 return _points[n];
406}
407
408const Point & Path::operator[](const std::size_t n) const
409{
410 return _points[n];
411}
412
413std::vector<Point>::const_iterator Path::begin() const
414{
415 return _points.begin();
416}
417
418std::vector<Point>::const_iterator Path::cbegin() const
419{
420 return _points.begin();
421}
422
423std::vector<Point>::const_iterator Path::end() const
424{
425 return _points.end();
426}
427
428std::vector<Point>::const_iterator Path::cend() const
429{
430 return _points.cend();
431}
432
433bool Path::isClosed() const
434{
435 return _openClosed == Closed;
436}
437
438bool Path::isOpen() const
439{
440 return _openClosed == Open;
441}
442
443bool Path::empty() const
444{
445 return _points.empty();
446}
447
448std::size_t Path::size() const
449{
450 return _points.size();
451}
452
454{
456}
457
459{
460 return _openClosed;
461}
462
464{
466}
467
468const Point & Path::front() const
469{
470 return _points.front();
471}
472
473const Point & Path::back() const
474{
475 return _points.back();
476}
477
478} // namespace LibBoard
479
480std::ostream & operator<<(std::ostream & out, const LibBoard::Path & path);
481
482#endif /* BOARD_PATH_H */
std::ostream & operator<<(std::ostream &out, const LibBoard::Path &path)
Definition Path.cpp:407
The Point structure. @copyright This source code is part of the Board project, a C++ library whose pu...
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
@copyright This source code is part of the Board project, a C++ library whose purpose is to allow sim...
Definition Board.h:55
Path mix(const Path &a, const Path &b, double time)
Interpolate two paths according to a time (0 is a, 1 is b)
Definition Path.cpp:390
A path, according to Postscript and SVG definition.
Definition Path.h:45
const std::vector< Point > & points() const
Definition Path.cpp:371
void setCounterclockwise()
Make the path counterclockwise.
Definition Path.cpp:337
Path translated(double dx, double dy) const
Return a translated copy of the path.
Definition Path.cpp:142
bool isClosed() const
Is the path closed?
Definition Path.h:433
bool isOpen() const
Is the path open?
Definition Path.h:438
Path & push_back(const Point &p)
Add a point to the path.
Definition Path.cpp:43
std::vector< Point >::size_type size_type
Definition Path.h:47
Path & moveCenter(double x, double y)
Translate the center to a given position.
Definition Path.cpp:155
std::vector< Point >::const_iterator begin() const
Definition Path.h:413
void clear()
Remove all points of the path.
Definition Path.h:398
void setOpenClosed(OpenClosed openClosed)
Set the open/closed flag of the path.
Definition Path.cpp:67
std::vector< Point >::const_iterator cend() const
Definition Path.h:428
std::ostream & flush(std::ostream &) const
Definition Path.cpp:376
Path & pop_back()
Remove the last point of the path.
Definition Path.cpp:37
const Point & front() const
The first point of the path.
Definition Path.h:468
Path rotatedDeg(double angle, const Point &center) const
Return a rotated copy of the path, thanks to an angle and a rotation center.
Definition Path.cpp:105
std::vector< Point > _points
Definition Path.h:383
Path & scale(double sx, double sy)
Apply a scaling factor to the path along each axis.
Definition Path.cpp:169
void flushFIG(std::ostream &stream, const TransformFIG &transform) const
Definition Path.cpp:222
void close()
Close the path.
Definition Path.h:453
Path & operator<<(const Point &p)
Add a point at the end of the path.
Definition Path.cpp:49
Point center() const
Center of the bounding box of the path.
Definition Path.cpp:72
Point & operator[](const std::size_t n)
Get the n-th point of the path.
Definition Path.h:403
std::size_t size() const
The number of points in the path.
Definition Path.h:448
bool isCounterclockwise() const
Tell if the points of the path are ordered counterclockwise.
Definition Path.cpp:325
Path getCounterclockwise() const
Return a counterclockwise copy of the path.
Definition Path.cpp:351
Path getClockwise() const
Return a clockwise copy of the path.
Definition Path.cpp:344
OpenClosed
The OpenClosed enum.
Definition Path.h:53
@ Closed
The is closed.
Definition Path.h:55
@ Open
The path is open.
Definition Path.h:54
void flushSVGPoints(std::ostream &stream, const TransformSVG &transform) const
Definition Path.cpp:261
void setClockwise()
Make the path clockwise.
Definition Path.cpp:330
void open()
Open the path.
Definition Path.h:463
OpenClosed _openClosed
Definition Path.h:384
Path transformed(const Transform &transform) const
Compute the path obtained after a transform.
Definition Path.cpp:295
bool empty() const
Check if the path is empty (i.e. has no points)
Definition Path.h:443
std::vector< Point >::const_iterator cbegin() const
Definition Path.h:418
Path & rotateDeg(double angle, const Point &center)
Rotate the path by a given angle, in degrees, and according to a rotation center.
Definition Path.cpp:88
void scaleAll(double s)
Scale all the points.
Definition Path.cpp:196
Path scaled(double sx, double sy) const
Return a scaled copy of the path.
Definition Path.cpp:186
const Point & back() const
The last point of the path.
Definition Path.h:473
std::vector< Point >::const_iterator end() const
Definition Path.h:423
Path()
Definition Path.h:58
Rect boundingBox() const
Definition Path.cpp:358
Path(OpenClosed openClosed)
Construct an open or closed empty path.
Definition Path.h:77
Path rotated(double angle, const Point &center) const
Return a rotated copy of the path, thanks to an angle and a rotation center.
Definition Path.cpp:93
OpenClosed openClosed() const
The open/closed status of the path.
Definition Path.h:458
Path & translate(double dx, double dy)
Translate the path.
Definition Path.cpp:130
bool isClockwise() const
Tell if the points of the path are ordered clockwise.
Definition Path.cpp:304
void flushPostscript(std::ostream &stream, const TransformEPS &transform) const
Definition Path.cpp:206
void flushSVGCommands(std::ostream &stream, const TransformSVG &transform) const
Definition Path.cpp:238
void flushTikZPoints(std::ostream &stream, const TransformTikZ &transform) const
Definition Path.cpp:280
Path(const std::vector< Point > &points, OpenClosed openClosed)
Construct a path from a vector of points.
Definition Path.h:65
Path & rotate(double angle, const Point &center)
Rotate the path by a given angle and according to a rotation center.
Definition Path.cpp:77
Struct representing a 2D point.
Definition Point.h:42
Struct representing a rectangle on the plane.
Definition Rect.h:40
Structure representing a scaling and translation suitable for an EPS output.
Definition Transforms.h:71
Structure representing a scaling and translation suitable for an XFig output.
Definition Transforms.h:87
Structure representing a scaling and translation suitable for an SVG output.
Definition Transforms.h:109
Structure representing a scaling and translation suitable for an TikZ output.
Definition Transforms.h:126
Definition Transforms.h:46