summaryrefslogtreecommitdiffstats
path: root/sigmodr/widgets/mapeditor
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-04-26 18:05:30 -0400
committerBen Boeckel <MathStuf@gmail.com>2009-04-26 18:05:30 -0400
commitf4da40a9bcafd9c64b729f864e47deca83c43922 (patch)
tree2174b2285416ddf8b3dd043befc9574c96a5ce48 /sigmodr/widgets/mapeditor
parent2c5ccfdedf79016d63380139c72de03d3cbc07a7 (diff)
downloadsigen-f4da40a9bcafd9c64b729f864e47deca83c43922.tar.gz
sigen-f4da40a9bcafd9c64b729f864e47deca83c43922.tar.xz
sigen-f4da40a9bcafd9c64b729f864e47deca83c43922.zip
Move turn direction finding code out to a function
Diffstat (limited to 'sigmodr/widgets/mapeditor')
-rw-r--r--sigmodr/widgets/mapeditor/WorldMapPlacement.cpp31
-rw-r--r--sigmodr/widgets/mapeditor/WorldMapPlacement.h9
2 files changed, 22 insertions, 18 deletions
diff --git a/sigmodr/widgets/mapeditor/WorldMapPlacement.cpp b/sigmodr/widgets/mapeditor/WorldMapPlacement.cpp
index 3c4ada7b..12a7fb09 100644
--- a/sigmodr/widgets/mapeditor/WorldMapPlacement.cpp
+++ b/sigmodr/widgets/mapeditor/WorldMapPlacement.cpp
@@ -32,6 +32,14 @@
using namespace Sigmodr::Widgets;
+enum Corner
+{
+ Invalid = -1,
+ TopLeft = 0,
+ TopRight = 1,
+ BottomRight = 2,
+ BottomLeft = 3
+};
enum Resolution
{
Include = 1,
@@ -69,6 +77,19 @@ static bool touches(const QPolygon& polygon1, const QPolygon& polygon2)
return false;
}
+static Corner turnDirection(const QPoint& previous, const QPoint& current, const QPoint& next)
+{
+ if ((current.x() < previous.x()) && (current.y() < next.y()))
+ return TopLeft;
+ if ((current.y() < previous.y()) && (next.x() < current.x()))
+ return TopRight;
+ if ((previous.x() < current.x()) && (next.y() < current.y()))
+ return BottomRight;
+ if ((previous.y() < current.y()) && (current.x() < next.x()))
+ return BottomLeft;
+ return Invalid;
+}
+
static CollisionInfo findCollisions(const QPolygon& polygon1, const QPolygon& polygon2)
{
CollisionInfo data;
@@ -291,15 +312,7 @@ QPoint WorldMapPlacement::find(const QPoint& point)
rect.moveCenter(QPoint(cur.x() + ((((point.x() < cur.x()) ? 1 : -1) * m_size.width()) / 2), point.y()));
best = closer(best, rect.toRect(), point);
}
- Corner corner = Invalid;
- if ((cur.x() < last.x()) && (cur.y() < next.y()))
- corner = TopLeft;
- else if ((cur.y() < last.y()) && (next.x() < cur.x()))
- corner = TopRight;
- else if ((last.x() < cur.x()) && (next.y() < cur.y()))
- corner = BottomRight;
- else if ((last.y() < cur.y()) && (cur.x() < next.x()))
- corner = BottomLeft;
+ const Corner corner = turnDirection(last, cur, next);
if (corner != Invalid)
{
switch (corner)
diff --git a/sigmodr/widgets/mapeditor/WorldMapPlacement.h b/sigmodr/widgets/mapeditor/WorldMapPlacement.h
index 697ac134..fd948c48 100644
--- a/sigmodr/widgets/mapeditor/WorldMapPlacement.h
+++ b/sigmodr/widgets/mapeditor/WorldMapPlacement.h
@@ -41,15 +41,6 @@ class SIGMODRWIDGETS_NO_EXPORT WorldMapPlacement
static void invalidateCache();
private:
- enum Corner
- {
- Invalid = -1,
- TopLeft = 0,
- TopRight = 1,
- BottomRight = 2,
- BottomLeft = 3
- };
-
void finalize();
static bool m_cacheGood;