# HG changeset patch # User insilmaril # Date 1251124747 0 # Node ID d85834ad8c541d04048b2bccd6172edb08db1d85 # Parent 78ba80b54bc4ced34f0acc7909bf1c1d46c06754 Fixed collision methods, segfault for wrong flagname diff -r 78ba80b54bc4 -r d85834ad8c54 branchobj.cpp --- a/branchobj.cpp Tue Aug 18 12:39:07 2009 +0000 +++ b/branchobj.cpp Mon Aug 24 14:39:07 2009 +0000 @@ -147,7 +147,7 @@ if (parObj->getTreeItem()->depth()==0) { // new parent is a mapcenter - QPointF p= normalise ( QPointF (m.x() - o->getChildPos().x(), + QPointF p= normalize ( QPointF (m.x() - o->getChildPos().x(), m.y() - o->getChildPos().y() )); if (p.x()<0) p.setX( p.x()-bbox.width() ); move2RelPos (p); diff -r 78ba80b54bc4 -r d85834ad8c54 geometry.cpp --- a/geometry.cpp Tue Aug 18 12:39:07 2009 +0000 +++ b/geometry.cpp Mon Aug 24 14:39:07 2009 +0000 @@ -1,11 +1,12 @@ #include "geometry.h" #include -#include #include "misc.h" +#include using namespace std; + QRectF addBBox(QRectF r1, QRectF r2) { // Find smallest QRectF containing given rectangles @@ -45,6 +46,50 @@ return false; } +ConvexPolygon::ConvexPolygon () +{ +} + +ConvexPolygon::ConvexPolygon (QPolygonF p):QPolygonF (p) +{ +} + +void ConvexPolygon::calcCentroid() +{ + // Calculate area and centroid + // http://en.wikipedia.org/wiki/Centroid + qreal cx,cy,p; + cx=cy=0; + _area=0; + + append (at(0)); + for (int i=0;i max) max = d; - } + // cout << "p="< 0) - result.intersect = false; - else - result.intersect = true; + qreal d = intervalDistance(minA, maxA, minB, maxB); + if (d > 0) result.intersect = false; - // ===== 2. Now find if the polygons *will* intersect ===== + // ===== 2. Now find if the polygons *will* intersect ===== // Project the velocity on the current axis @@ -181,30 +234,25 @@ minA += velocityProjection; else maxA += velocityProjection; - // Do the same test as above for the new projection - qreal d = intervalDistance(minA, maxA, minB, maxB); - if (d > 0) result.willIntersect = false; + // d = intervalDistance(minA, maxA, minB, maxB); + //if (d > 0) result.willIntersect = false; /* - */ cout <<" "; - cout <<"minA="<load(flagsPath+"flag-lifebelt.png"); diff -r 78ba80b54bc4 -r d85834ad8c54 misc.cpp --- a/misc.cpp Tue Aug 18 12:39:07 2009 +0000 +++ b/misc.cpp Mon Aug 24 14:39:07 2009 +0000 @@ -49,40 +49,6 @@ } } -QPointF normalise(const QPointF &p) -{ - // Calculate normalised position (fixed length) - - qreal px=p.x(); - qreal py=p.y(); - qreal x; - qreal y; - qreal r=150; - - if (px==0) - { - x=0; - if (py>=0) - y=r; - else - y=-r; - } else - { - qreal sign; - qreal a; - if (px>0) - sign=1; - else - sign=-1; - - a=atan (py / px); - x=cos (a) * r *sign; - y=sin (a) * r *sign; - } - return QPoint ((int) (x),(int) (y)); -} - - qreal max(qreal a, qreal b) { if (a>b) diff -r 78ba80b54bc4 -r d85834ad8c54 misc.h --- a/misc.h Tue Aug 18 12:39:07 2009 +0000 +++ b/misc.h Mon Aug 24 14:39:07 2009 +0000 @@ -14,9 +14,6 @@ extern ostream &operator<< (ostream &stream, QPoint const &p); extern ostream &operator<< (ostream &stream, QPointF const &p); qreal getAngle(const QPointF &); -QPointF normalise (const QPointF &); qreal max (qreal,qreal); -class BranchObj; -class MapEditor; #endif diff -r 78ba80b54bc4 -r d85834ad8c54 treemodel.cpp --- a/treemodel.cpp Tue Aug 18 12:39:07 2009 +0000 +++ b/treemodel.cpp Mon Aug 24 14:39:07 2009 +0000 @@ -66,14 +66,14 @@ TreeItem *parentItem; if (!parent.isValid()) - { //FIXME-1 + { //FIXME-3 left here for testing only, seems to work now... parentItem = rootItem; /* cout << "TM::index() no parent?! xxx\n"; cout << " row="<