insilmaril@789
|
1 |
#ifndef GEOMETRY
|
insilmaril@789
|
2 |
#define GEOMETRY
|
insilmaril@650
|
3 |
|
insilmaril@656
|
4 |
#include <QPolygonF>
|
insilmaril@650
|
5 |
|
insilmaril@650
|
6 |
QRectF addBBox(QRectF r1, QRectF r2);
|
insilmaril@754
|
7 |
bool isInBox(const QPointF &p, const QRectF &box);
|
insilmaril@650
|
8 |
|
insilmaril@792
|
9 |
|
insilmaril@792
|
10 |
class Vector:public QPointF
|
insilmaril@792
|
11 |
{
|
insilmaril@792
|
12 |
public:
|
insilmaril@792
|
13 |
Vector ();
|
insilmaril@792
|
14 |
Vector (const QPointF &p);
|
insilmaril@792
|
15 |
Vector (qreal x, qreal y);
|
insilmaril@792
|
16 |
|
insilmaril@792
|
17 |
friend inline bool operator==(const Vector &v1, const Vector &v2 )
|
insilmaril@792
|
18 |
{ return v1.x()==v2.x() && v1.y()==v2.y(); }
|
insilmaril@792
|
19 |
|
insilmaril@792
|
20 |
virtual void normalize ();
|
insilmaril@792
|
21 |
virtual qreal dotProduct (const QPointF &b);
|
insilmaril@792
|
22 |
virtual void scale (const qreal &f);
|
insilmaril@792
|
23 |
virtual void invert ();
|
insilmaril@798
|
24 |
virtual QPointF toQPointF();
|
insilmaril@792
|
25 |
};
|
insilmaril@792
|
26 |
|
insilmaril@789
|
27 |
class ConvexPolygon:public QPolygonF
|
insilmaril@789
|
28 |
{
|
insilmaril@789
|
29 |
public:
|
insilmaril@789
|
30 |
ConvexPolygon ();
|
insilmaril@789
|
31 |
ConvexPolygon (QPolygonF p);
|
insilmaril@789
|
32 |
void calcCentroid() ;
|
insilmaril@789
|
33 |
QPointF centroid() const;
|
insilmaril@789
|
34 |
qreal weight() const;
|
insilmaril@792
|
35 |
std::string toStdString ();
|
insilmaril@792
|
36 |
Vector at (const int &i) const ;
|
insilmaril@792
|
37 |
virtual void translate ( const Vector &offset );
|
insilmaril@792
|
38 |
virtual void translate ( qreal dx, qreal dy );
|
insilmaril@789
|
39 |
private:
|
insilmaril@792
|
40 |
Vector _centroid;
|
insilmaril@789
|
41 |
qreal _area;
|
insilmaril@789
|
42 |
};
|
insilmaril@789
|
43 |
|
insilmaril@662
|
44 |
class PolygonCollisionResult {
|
insilmaril@662
|
45 |
public:
|
insilmaril@662
|
46 |
// Are the polygons going to intersect forward in time?
|
insilmaril@662
|
47 |
bool willIntersect;
|
insilmaril@662
|
48 |
|
insilmaril@662
|
49 |
// Are the polygons currently intersecting?
|
insilmaril@662
|
50 |
bool intersect;
|
insilmaril@662
|
51 |
|
insilmaril@662
|
52 |
// The translation to apply to the first polygon to push the polygons apart.
|
insilmaril@662
|
53 |
QPointF minTranslation;
|
insilmaril@662
|
54 |
};
|
insilmaril@662
|
55 |
|
insilmaril@662
|
56 |
|
insilmaril@792
|
57 |
void projectPolygon(Vector axis, ConvexPolygon polygon, qreal &min, qreal &max) ;
|
insilmaril@789
|
58 |
|
insilmaril@662
|
59 |
qreal intervalDistance(qreal minA, qreal maxA, qreal minB, qreal maxB);
|
insilmaril@792
|
60 |
PolygonCollisionResult polygonCollision(ConvexPolygon polygonA,
|
insilmaril@792
|
61 |
ConvexPolygon polygonB, Vector velocity);
|
insilmaril@662
|
62 |
|
insilmaril@789
|
63 |
#endif |