diff -r f1006de05c54 -r 7d67be709091 geometry.cpp --- a/geometry.cpp Mon Sep 07 15:36:57 2009 +0000 +++ b/geometry.cpp Tue Sep 08 12:15:39 2009 +0000 @@ -3,6 +3,8 @@ #include #include "misc.h" +#include + #include using namespace std; @@ -46,6 +48,48 @@ return false; } +Vector::Vector ():QPointF () +{ +} + +Vector::Vector (const QPointF &p):QPointF (p) +{ +} + +Vector::Vector (qreal x, qreal y):QPointF (x,y) +{ +} + +//! Normalize vector +void Vector::normalize () +{ + if (x()==0 && y()==0) return; + qreal l=sqrt ( x()*x() + y()*y() ); + setX (x()/l); + setY (y()/l); +} + +//! Dot product of two vectors +qreal Vector::dotProduct (const QPointF &b) +{ + return x()*b.x() + y()*b.y(); +} + + +void Vector::scale (const qreal &f) +{ + setX (x()*f); + setY (y()*f); +} + +void Vector::invert () +{ + setX (-x()); + setY (-y()); +} + +/*! Calculate the projection of a polygon on an axis + and returns it as a [min, max] interval */ ConvexPolygon::ConvexPolygon () { } @@ -89,45 +133,43 @@ return _area; } -//! Normalize vector -QPointF normalize (const QPointF &p) +std::string ConvexPolygon::toStdString() { - if (p==QPointF(0,0)) return p; - qreal l=sqrt ( p.x()*p.x() + p.y()*p.y() ); - return QPointF (p.x()/l,p.y()/l); + QString s ("("); + for (int i=0;i