Fréchet View  1.6.0
A Tool for Exploring Fréchet Distance Algorithms
path.h
Go to the documentation of this file.
1 #ifndef PATH_H
2 #define PATH_H
3 
4 #include <QObject>
5 #include <QTransform>
6 #include <QPolygonF>
7 
8 #include <string>
9 #include <grid.h>
10 
11 
12 
30 class Path : public QObject {
31  Q_OBJECT
32 private:
34  QPolygonF points;
36  std::string opcode;
38  double turtle_angle;
39 
46 
47 public:
48  /*
49  * All methods that are marked as Q_INVOKABLE
50  * are exposed to JavaScript.
51  * */
52 
57  Q_INVOKABLE
58  Path(QObject* parent=0);
59 
64  Q_INVOKABLE
65  Path(const Path& that);
66 // Path(const Path&& that) : points(that.points), rel(that.rel) { }
67 
72  Q_INVOKABLE
73  Path(const Path* that);
74 // Path(const Path&& that) : points(that.points), rel(that.rel) { }
75 
83  Q_INVOKABLE
84  Path(QString svg, bool forceAbsolute=false, QObject* parent=0);
85 
93  static Path svgPath(QString str, bool forceAbsolute=false);
99  static Path ipePath(QString str);
100 
106  const QPolygonF& toCurve(int precision=0);
107 
113  Q_INVOKABLE
114  Path& operator= (const Path& that);
115  // Path& operator= (const Path&&);
116 
122  Q_INVOKABLE
123  Path& operator+= (const Path& that);
124 
131  Q_INVOKABLE
132  Path& operator+= (QString svg);
133 
134 public slots:
136  int size() const { return points.size(); }
137 
138  /*
139  * All public slots are exposed to JavaScript.
140  * Cool. But works only with Path*.
141  **/
147  Path* appendPath(Path* that) { (*this) += (*that); return this; }
154  Path* appendString(QString svg) { (*this) += svg; return this; }
155 
156  /*
157  * append points
158  * absolute:
159  */
165  Path* M(QPointF p) { append(p,'M'); return this; }
172  Path* M(double x, double y) { return M(QPointF(x,y)); }
178  Path* H(double h) { append(QPointF(h,0),'H'); return this; }
184  Path* V(double v) { append(QPointF(0,v),'V'); return this; }
189  Path* close();
194  Path* Z();
199  Path* undo();
204  Path* ensureClosed();
205 
206  /*
207  * append points
208  * relative:
209  */
215  Path* m(QPointF p) { append(p,'m'); return this; }
222  Path* m(double x, double y) { return m(QPointF(x,y)); }
228  Path* h(double h) { append(QPointF(h,0),'h'); return this; }
234  Path* v(double v) { append(QPointF(0,v),'v'); return this; }
241  Path* polar(double angle,double distance);
242 
243  /*
244  * Transforms
245  */
251  Path* map(QTransform tf);
257  Path* map(QMatrix mx);
258 
264  Path* scale(double scale);
271  Path* scale(double scalex, double scaley);
277  Path* rotate(double angle);
278 
284  Path* translate(QPointF offset);
291  Path* translate(double dx, double dy);
296  Path* mirrorx();
301  Path* mirrory();
306  Path* revert();
307 
308  /*
309  * Turtle Graphics
310  * */
316  Path* left(double angle);
322  Path* right(double angle);
328  Path* reset(double angle=0.0);
334  Path* forward(double distance);
335 
340  void lineStyle(int);
345  void setDefaultLineStyle(int);
350  void outerLineStyle(int);
351 
352 public:
353  /*
354  * String parsing
355  */
357  void parseSvg(QString str, bool forceAbsolute=false);
359  void parseIpe(QString str);
363  const LineStyleVector& getLineStyles() const { return lineStyles; }
364 
365 private:
369  void append(QPointF p, char opcode);
371  void absolutize();
373  void setPrecision(int precision);
375  void removeDuplicates();
376  // void concat(QBitArray& a, const QBitArray& b);
377 };
378 
379 #endif // PATH_H
const LineStyleVector & getLineStyles() const
Definition: path.h:363
void parseIpe(QString str)
pare an IPE input string
Definition: path.cpp:300
QPolygonF points
the list of vertexes
Definition: path.h:34
Path * M(double x, double y)
append a new vertex at an absolute position
Definition: path.h:172
Path * mirrorx()
mirror the curve about the x-axis
Definition: path.cpp:157
static int distance(int a, int b, int n)
Definition: poly_utils.cpp:210
static Path svgPath(QString str, bool forceAbsolute=false)
static constructor from SVG input string
Definition: path.cpp:33
void parseSvg(QString str, bool forceAbsolute=false)
parse an SVG input string
Definition: path.cpp:236
static Path ipePath(QString str)
static constructor from IPE input string
Definition: path.cpp:40
std::vector< LineStyle > LineStyleVector
Definition: grid.h:26
void removeDuplicates()
remove all duplicate points
Definition: path.cpp:413
Path * translate(QPointF offset)
translate the curve
Definition: path.cpp:147
Path * appendString(QString svg)
appends a copy of an SVG path
Definition: path.h:154
Path * left(double angle)
turn the turtle's head to the left
Definition: path.cpp:192
Path * H(double h)
horizontal move to an absolute position
Definition: path.h:178
void append(QPointF p, char opcode)
Definition: path.cpp:354
LineStyle defaultLineStyle
default style for grid disaplay
Definition: path.h:42
Path * reset(double angle=0.0)
turn the turtle's head to a given angle
Definition: path.cpp:202
Path * map(QTransform tf)
apply a transformation to all vertexes
Definition: path.cpp:121
Path * rotate(double angle)
rotate the curve
Definition: path.cpp:141
Path * ensureClosed()
make sure the curve is closed
Definition: path.cpp:108
Path * undo()
remove the last vertex
Definition: path.cpp:100
Path * h(double h)
horizontal move, relative to the current position
Definition: path.h:228
void setDefaultLineStyle(int)
change the default style of grid lines
Definition: path.cpp:211
Represents a polygonal curve.
Definition: path.h:30
int size() const
Definition: path.h:136
Path * appendPath(Path *that)
appends a copy of another Path
Definition: path.h:147
Path * revert()
revert the order of vertexes
Definition: path.cpp:179
Path * mirrory()
mirror the curve about the y-axis
Definition: path.cpp:162
void outerLineStyle(int)
set the style of outermost grid lines
Definition: path.cpp:229
Path * V(double v)
vertical move to an absolute position
Definition: path.h:184
Path * close()
return to the first vertex, creating a closed curve
Definition: path.cpp:90
Path * forward(double distance)
append a new vertex, relative to the current position
Definition: path.cpp:207
Path * scale(double scale)
scale the polygonal curve
Definition: path.cpp:131
Path * Z()
return to the first vertex, creating a closed curve
Definition: path.cpp:96
Q_INVOKABLE Path & operator+=(const Path &that)
append operator
Definition: path.cpp:66
const QPolygonF & toCurve(int precision=0)
convert to a QPolygonF object, ready for processing by the Frechet distance algorithms
Definition: path.cpp:47
Path * polar(double angle, double distance)
append a new vertex, given by polar coordinates
Definition: path.cpp:116
void absolutize()
replace all relative movements by absolute positions
Definition: path.cpp:364
LineStyleVector lineStyles
line styles for grid disaplay
Definition: path.h:45
double turtle_angle
turtle_angle current direction of the turtle
Definition: path.h:38
Q_INVOKABLE Path(QObject *parent=0)
default constructor
Definition: path.cpp:7
Path * v(double v)
vertical move, relative to the current position
Definition: path.h:234
#define str(S)
Q_INVOKABLE Path & operator=(const Path &that)
assignment operator
Definition: path.cpp:57
LineStyle
display style of grid lines in free-space diagram
Definition: grid.h:15
std::string opcode
used during assembly of a path: the next "move" operation
Definition: path.h:36
Path * M(QPointF p)
append a new vertex at an absolute position
Definition: path.h:165
void lineStyle(int)
change the style of grid lines
Definition: path.cpp:218
void setPrecision(int precision)
set the numerical precision for input data (default is unlimited)
Definition: path.cpp:398
Path * m(double x, double y)
append a new vertex, relative to the current position
Definition: path.h:222
LineStyle getDefaultLineStyle() const
Definition: path.h:361
Path * m(QPointF p)
append a new vertex, relative to the current position
Definition: path.h:215
Path * right(double angle)
turn the turtle's head to the right
Definition: path.cpp:197