diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2009-04-04 17:34:24 -0400 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2009-04-04 17:34:24 -0400 |
| commit | b42e2378b1508808a4c9b40fe0f8da8089985fff (patch) | |
| tree | 12cdaabd6c9ef4c65a0b0b8c203cf2e61d953186 | |
| parent | e92126b4f664899cc3cd19066884b196bae43886 (diff) | |
Finish the algorithm for making polygons from the rectangles
| -rw-r--r-- | sigmodr/widgets/mapeditor/WorldMapPlacement.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/sigmodr/widgets/mapeditor/WorldMapPlacement.cpp b/sigmodr/widgets/mapeditor/WorldMapPlacement.cpp index 8992503c..ae8d0bc7 100644 --- a/sigmodr/widgets/mapeditor/WorldMapPlacement.cpp +++ b/sigmodr/widgets/mapeditor/WorldMapPlacement.cpp @@ -80,10 +80,47 @@ void WorldMapPlacement::finalize() { if (m_cacheGood) return; - // TODO: make polygons from rects + foreach (const QRect& rect, m_rects) + { + bool merged = false; + QMutableListIterator<QPolygon> i(m_polygons); + QMutableListIterator<QPolygon> j(m_polygons); + while (i.hasNext()) + { + i.next(); + if (!merged) + { + j.next(); + if (touches(i.value(), rect)) + { + i.value() = mergePolygons(i.value(), rect); + merged = true; + } + } + else if (touches(j.value(), i.value())) + { + j.value() = mergePolygons(j.value(), i.value()); + i.remove(); + } + } + if (!merged) + m_polygons.append(rect); + } m_cacheGood = true; } +bool WorldMapPlacement::touches(const QPolygon& polygon, const QPolygon& polygon2) +{ + // TODO: determine if the polygons touch + return false; +} + +QPolygon WorldMapPlacement::mergePolygons(const QPolygon& polygon1, const QPolygon& polygon2) +{ + // TODO: merge the polygons + return polygon1; +} + QPoint WorldMapPlacement::find(const QPoint& point) { if (!m_cacheGood) |
