insilmaril@139
|
1 |
#include <math.h>
|
insilmaril@139
|
2 |
|
insilmaril@0
|
3 |
#include <qregexp.h>
|
insilmaril@164
|
4 |
#include <stdlib.h>
|
insilmaril@0
|
5 |
|
insilmaril@0
|
6 |
#include "misc.h"
|
insilmaril@0
|
7 |
|
insilmaril@792
|
8 |
#include "geometry.h"
|
insilmaril@792
|
9 |
|
insilmaril@129
|
10 |
QString qpointToString (const QPoint &p)
|
insilmaril@792
|
11 |
{ return "(" + QString("%1").arg(p.x()) +","+ QString ("%1").arg (p.y()) +")"; }
|
insilmaril@0
|
12 |
|
insilmaril@792
|
13 |
QString qpointFToString (const QPointF &p)
|
insilmaril@792
|
14 |
{ return "(" + QString("%1").arg(p.x()) +","+ QString ("%1").arg (p.y()) +")"; }
|
insilmaril@792
|
15 |
|
insilmaril@792
|
16 |
QString VectorToString (const Vector &p)
|
insilmaril@792
|
17 |
{ return "(" + QString("%1").arg(p.x()) +","+ QString ("%1").arg (p.y()) +")"; }
|
insilmaril@408
|
18 |
|
insilmaril@0
|
19 |
ostream &operator<< (ostream &stream, QPoint const &p)
|
insilmaril@0
|
20 |
{
|
insilmaril@366
|
21 |
stream << "("<<p.x()<<","<<p.y()<<")";
|
insilmaril@366
|
22 |
return stream;
|
insilmaril@0
|
23 |
}
|
insilmaril@0
|
24 |
|
insilmaril@408
|
25 |
ostream &operator<< (ostream &stream, QPointF const &p)
|
insilmaril@408
|
26 |
{
|
insilmaril@408
|
27 |
stream << "("<<p.x()<<","<<p.y()<<")";
|
insilmaril@408
|
28 |
return stream;
|
insilmaril@408
|
29 |
}
|
insilmaril@408
|
30 |
|
insilmaril@802
|
31 |
ostream &operator<< (ostream &stream, QRectF const &r)
|
insilmaril@802
|
32 |
{
|
insilmaril@802
|
33 |
stream << "tL="<<r.topLeft()<<" - bR="<<r.bottomRight();
|
insilmaril@802
|
34 |
return stream;
|
insilmaril@802
|
35 |
}
|
insilmaril@802
|
36 |
|
insilmaril@792
|
37 |
ostream &operator<< (ostream &stream, Vector const &p)
|
insilmaril@792
|
38 |
{
|
insilmaril@792
|
39 |
stream << "("<<p.x()<<","<<p.y()<<")";
|
insilmaril@792
|
40 |
return stream;
|
insilmaril@792
|
41 |
}
|
insilmaril@792
|
42 |
|
insilmaril@408
|
43 |
qreal getAngle(const QPointF &p)
|
insilmaril@0
|
44 |
{
|
insilmaril@0
|
45 |
// Calculate angle of vector to y-axis
|
insilmaril@0
|
46 |
if (p.y()==0)
|
insilmaril@0
|
47 |
{
|
insilmaril@0
|
48 |
if (p.x()>=0)
|
insilmaril@0
|
49 |
return M_PI_2;
|
insilmaril@0
|
50 |
else
|
insilmaril@0
|
51 |
return 3* M_PI_2;
|
insilmaril@0
|
52 |
} else
|
insilmaril@0
|
53 |
{
|
insilmaril@0
|
54 |
if (p.y()>0)
|
insilmaril@408
|
55 |
return (qreal)(M_PI - atan ( (qreal)(p.x()) / (qreal)(p.y()) ) );
|
insilmaril@0
|
56 |
else
|
insilmaril@0
|
57 |
if (p.x()<0)
|
insilmaril@408
|
58 |
return (qreal)( 2*M_PI - atan ( (qreal)(p.x()) / (qreal)(p.y()) ) );
|
insilmaril@0
|
59 |
else
|
insilmaril@408
|
60 |
return (qreal)( - atan ( (qreal)(p.x()) / (qreal)(p.y()) ) );
|
insilmaril@0
|
61 |
}
|
insilmaril@0
|
62 |
}
|
insilmaril@0
|
63 |
|
insilmaril@408
|
64 |
qreal max(qreal a, qreal b)
|
insilmaril@0
|
65 |
{
|
insilmaril@0
|
66 |
if (a>b)
|
insilmaril@0
|
67 |
return a;
|
insilmaril@0
|
68 |
return b;
|
insilmaril@0
|
69 |
}
|
insilmaril@0
|
70 |
|