summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-04-22 15:39:08 -0400
committerBen Boeckel <MathStuf@gmail.com>2009-04-22 15:39:08 -0400
commit935e6b128edeb6ffbd163ccc489c9821807ecfc3 (patch)
tree6eebb2478eb43fbac1f710e7712e31a82e21634e
parent7abd20284ac0ec7191a3c3eee576b26718eb556f (diff)
downloadsigen-935e6b128edeb6ffbd163ccc489c9821807ecfc3.tar.gz
sigen-935e6b128edeb6ffbd163ccc489c9821807ecfc3.tar.xz
sigen-935e6b128edeb6ffbd163ccc489c9821807ecfc3.zip
Move mergePolygons out of the class and find the outlines
-rw-r--r--sigmodr/widgets/mapeditor/WorldMapPlacement.cpp63
-rw-r--r--sigmodr/widgets/mapeditor/WorldMapPlacement.h1
2 files changed, 57 insertions, 7 deletions
diff --git a/sigmodr/widgets/mapeditor/WorldMapPlacement.cpp b/sigmodr/widgets/mapeditor/WorldMapPlacement.cpp
index e4a51b4b..d6bd483e 100644
--- a/sigmodr/widgets/mapeditor/WorldMapPlacement.cpp
+++ b/sigmodr/widgets/mapeditor/WorldMapPlacement.cpp
@@ -100,6 +100,63 @@ static QPoint findOuterPoint(const QPolygon& polygon)
return curPoint;
}
+static QList<QPolygon> mergePolygons(QPolygon polygon1, QPolygon polygon2)
+{
+ QList<QPolygon> polygons;
+ CollisionInfo cData1 = findCollisions(polygon1, polygon2);
+ CollisionInfo cData2 = findCollisions(polygon2, polygon1);
+ while (polygon1.size() || polygon2.size())
+ {
+ QPolygon polygon;
+ QPolygon* curPolygon;
+ QPolygon* otherPolygon;
+ CollisionInfo* curData;
+ CollisionInfo* otherData;
+ const QPoint point1 = findOuterPoint(polygon1);
+ const QPoint point2 = findOuterPoint(polygon2);
+ QPoint curPoint;
+ if (point1 < point2)
+ {
+ curPoint = point1;
+ curPolygon = &polygon1;
+ curData = &cData1;
+ otherPolygon = &polygon2;
+ otherData = &cData2;
+ }
+ else
+ {
+ curPoint = point2;
+ curPolygon = &polygon2;
+ curData = &cData2;
+ otherPolygon = &polygon1;
+ otherData = &cData1;
+ }
+ int curPos = curPolygon->indexOf(curPoint);
+ while (polygon.isEmpty() || (curPoint != polygon.first()))
+ {
+ polygon.append(curPoint);
+ curPolygon->remove(curPos);
+ if (curData->contains(curPoint))
+ {
+ curPos = otherPolygon->indexOf(curData->value(curPoint).second);
+ if (!curData->value(curPoint).first)
+ polygon.append(otherPolygon->at(curPos));
+ otherPolygon->remove(curPos);
+ curPoint = otherPolygon->at(curPos);
+ CollisionInfo* tempData = curData;
+ curData = otherData;
+ otherData = tempData;
+ QPolygon* tempPolygon = curPolygon;
+ curPolygon = otherPolygon;
+ otherPolygon = tempPolygon;
+ }
+ curPoint = curPolygon->at(curPos);
+ }
+ polygons.append(polygons);
+ }
+ return polygons;
+}
+
static const QRect& closer(const QRect& rect1, const QRect& rect2, const QPoint& point)
{
if (rect1.isNull())
@@ -256,9 +313,3 @@ void WorldMapPlacement::finalize()
}
m_cacheGood = true;
}
-
-QPolygon WorldMapPlacement::mergePolygons(const QPolygon& polygon1, const QPolygon& polygon2)
-{
- // TODO: merge the polygons
- return polygon1;
-}
diff --git a/sigmodr/widgets/mapeditor/WorldMapPlacement.h b/sigmodr/widgets/mapeditor/WorldMapPlacement.h
index 6627c33e..d81cc731 100644
--- a/sigmodr/widgets/mapeditor/WorldMapPlacement.h
+++ b/sigmodr/widgets/mapeditor/WorldMapPlacement.h
@@ -51,7 +51,6 @@ class SIGMODRWIDGETS_NO_EXPORT WorldMapPlacement
};
void finalize();
- QPolygon mergePolygons(const QPolygon& polygon1, const QPolygon& polygon2);
static bool m_cacheGood;
static QSize m_size;