tools/drawMapTest/drawmapscene.cpp
changeset 4434 34c305fbc63c
parent 4427 c5193713055f
child 4439 27a896207aae
--- a/tools/drawMapTest/drawmapscene.cpp	Sun Nov 28 15:07:26 2010 -0500
+++ b/tools/drawMapTest/drawmapscene.cpp	Mon Nov 29 22:23:56 2010 +0300
@@ -5,6 +5,11 @@
 
 #include "drawmapscene.h"
 
+template <class T> T sqr(const T & x)
+{
+    return x*x;
+}
+
 DrawMapScene::DrawMapScene(QObject *parent) :
     QGraphicsScene(parent),
     m_pen(Qt::yellow),
@@ -98,3 +103,25 @@
 
     return b;
 }
+
+void DrawMapScene::simplify()
+{
+    for(int pit = 0; pit < paths.size(); ++pit)
+    {
+        QList<QPoint> points = paths[pit];
+
+        QPoint prevPoint = points.first();
+        int i = 1;
+        while(i < points.size())
+        {
+            if(sqr(prevPoint.x() - points[i].x()) + sqr(prevPoint.y() - points[i].y()) < 1000)
+                points.removeAt(i);
+            else
+                ++i;
+        }
+
+        paths[pit] = points;
+    }
+
+    emit pathChanged();
+}