tools/drawMapTest/drawmapscene.cpp
changeset 4434 34c305fbc63c
parent 4427 c5193713055f
child 4439 27a896207aae
equal deleted inserted replaced
4433:e0092290b7c5 4434:34c305fbc63c
     2 #include <QGraphicsSceneMouseEvent>
     2 #include <QGraphicsSceneMouseEvent>
     3 #include <QGraphicsPathItem>
     3 #include <QGraphicsPathItem>
     4 #include <QtEndian>
     4 #include <QtEndian>
     5 
     5 
     6 #include "drawmapscene.h"
     6 #include "drawmapscene.h"
       
     7 
       
     8 template <class T> T sqr(const T & x)
       
     9 {
       
    10     return x*x;
       
    11 }
     7 
    12 
     8 DrawMapScene::DrawMapScene(QObject *parent) :
    13 DrawMapScene::DrawMapScene(QObject *parent) :
     9     QGraphicsScene(parent),
    14     QGraphicsScene(parent),
    10     m_pen(Qt::yellow),
    15     m_pen(Qt::yellow),
    11     m_brush(Qt::yellow)
    16     m_brush(Qt::yellow)
    96 
   101 
    97     }
   102     }
    98 
   103 
    99     return b;
   104     return b;
   100 }
   105 }
       
   106 
       
   107 void DrawMapScene::simplify()
       
   108 {
       
   109     for(int pit = 0; pit < paths.size(); ++pit)
       
   110     {
       
   111         QList<QPoint> points = paths[pit];
       
   112 
       
   113         QPoint prevPoint = points.first();
       
   114         int i = 1;
       
   115         while(i < points.size())
       
   116         {
       
   117             if(sqr(prevPoint.x() - points[i].x()) + sqr(prevPoint.y() - points[i].y()) < 1000)
       
   118                 points.removeAt(i);
       
   119             else
       
   120                 ++i;
       
   121         }
       
   122 
       
   123         paths[pit] = points;
       
   124     }
       
   125 
       
   126     emit pathChanged();
       
   127 }