geometry.h
author insilmaril
Thu, 25 Feb 2010 11:03:52 +0000
changeset 824 36eb4b8f409e
parent 798 d251c7b2de54
child 835 31841b366d5e
permissions -rw-r--r--
Added dialog for HTML export. Grouping in Switchboard shortcuts
     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 	virtual void normalize ();
    22 	virtual qreal dotProduct (const QPointF &b);
    23 	virtual void scale  (const qreal &f);
    24 	virtual void invert ();
    25 	virtual QPointF toQPointF();
    26 };
    27 
    28 class ConvexPolygon:public QPolygonF
    29 {
    30 public:
    31 	ConvexPolygon ();
    32 	ConvexPolygon (QPolygonF p);
    33 	void calcCentroid() ;
    34 	QPointF centroid() const;
    35 	qreal weight() const;
    36 	std::string toStdString ();
    37 	Vector at (const int &i) const ; 
    38 	virtual void translate ( const Vector &offset );
    39 	virtual void translate ( qreal dx, qreal dy );
    40 private:
    41 	Vector _centroid;
    42 	qreal _area;
    43 };
    44 
    45 class PolygonCollisionResult {
    46 public:
    47     // Are the polygons going to intersect forward in time?
    48     bool willIntersect;
    49 
    50     // Are the polygons currently intersecting?
    51     bool intersect;
    52 
    53     // The translation to apply to the first polygon to push the polygons apart.
    54     QPointF minTranslation;
    55 };
    56 
    57 
    58 void projectPolygon(Vector axis, ConvexPolygon polygon, qreal &min, qreal &max) ;
    59 
    60 qreal intervalDistance(qreal minA, qreal maxA, qreal minB, qreal maxB);
    61 PolygonCollisionResult polygonCollision(ConvexPolygon polygonA, 
    62                               ConvexPolygon polygonB, Vector velocity);
    63 
    64 #endif