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