]> git.sven.stormbind.net Git - sven/vym.git/blob - geometry.h
Import Upstream version 2.6.11
[sven/vym.git] / geometry.h
1 #ifndef GEOMETRY
2 #define GEOMETRY
3
4 #include <QPolygonF>
5
6 namespace Geometry {
7     qreal distance (const QPointF &p, const QPointF &q);
8 };
9
10 QRectF addBBox(QRectF r1, QRectF r2);
11 QSize addBBoxSize(QSize s1, QSize s2);
12 bool isInBox(const QPointF &p, const QRectF &box);
13
14 class Vector:public QPointF
15 {
16 public:
17         Vector ();
18         Vector (const QPointF &p);
19         Vector (qreal x, qreal y);
20         virtual ~Vector ();
21
22         friend inline bool operator==(const Vector &v1, const Vector &v2 )
23         { return v1.x()==v2.x() && v1.y()==v2.y(); }
24
25         bool isNull();
26         virtual void normalize ();
27         virtual qreal dotProduct (const QPointF &b);
28         virtual void scale  (const qreal &f);
29         virtual void invert ();
30         virtual QPointF toQPointF();
31 };
32
33 class ConvexPolygon:public QPolygonF
34 {
35 public:
36         ConvexPolygon ();
37         ConvexPolygon (QPolygonF p);
38         virtual ~ConvexPolygon();
39         void calcCentroid() ;
40         QPointF centroid() const;
41         qreal weight() const;
42         std::string toStdString ();
43         Vector at (const int &i) const ; 
44         virtual void translate ( const Vector &offset );
45         virtual void translate ( qreal dx, qreal dy );
46 private:
47         Vector _centroid;
48         qreal _area;
49 };
50
51 class PolygonCollisionResult {
52 public:
53     // Are the polygons going to intersect forward in time?
54     bool willIntersect;
55
56     // Are the polygons currently intersecting?
57     bool intersect;
58
59     // The translation to apply to the first polygon to push the polygons apart.
60     QPointF minTranslation;
61 };
62
63
64 void projectPolygon(Vector axis, ConvexPolygon polygon, qreal &min, qreal &max) ;
65
66 qreal intervalDistance(qreal minA, qreal maxA, qreal minB, qreal maxB);
67 PolygonCollisionResult polygonCollision(ConvexPolygon polygonA, 
68                               ConvexPolygon polygonB, Vector velocity);
69
70 #endif