diff options
author | Ben Boeckel <MathStuf@gmail.com> | 2009-04-26 19:08:39 -0400 |
---|---|---|
committer | Ben Boeckel <MathStuf@gmail.com> | 2009-04-26 19:09:03 -0400 |
commit | ecd9dc076d10db60f956b200d23c9dd6b796ce6c (patch) | |
tree | d27cbe6263f6f6212e6e670f7cf05fbac12aa372 | |
parent | f4da40a9bcafd9c64b729f864e47deca83c43922 (diff) | |
download | sigen-ecd9dc076d10db60f956b200d23c9dd6b796ce6c.tar.gz sigen-ecd9dc076d10db60f956b200d23c9dd6b796ce6c.tar.xz sigen-ecd9dc076d10db60f956b200d23c9dd6b796ce6c.zip |
Move between test out to a function
-rw-r--r-- | sigmodr/widgets/mapeditor/WorldMapPlacement.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/sigmodr/widgets/mapeditor/WorldMapPlacement.cpp b/sigmodr/widgets/mapeditor/WorldMapPlacement.cpp index 12a7fb09..82b4d0cb 100644 --- a/sigmodr/widgets/mapeditor/WorldMapPlacement.cpp +++ b/sigmodr/widgets/mapeditor/WorldMapPlacement.cpp @@ -90,6 +90,11 @@ static Corner turnDirection(const QPoint& previous, const QPoint& current, const return Invalid; } +template<typename T> static bool between(const T& middle, const T& end1, const T& end2) +{ + return (qMin(end1, end2) < middle) && (middle < qMax(end1, end2)); +} + static CollisionInfo findCollisions(const QPolygon& polygon1, const QPolygon& polygon2) { CollisionInfo data; @@ -99,12 +104,6 @@ static CollisionInfo findCollisions(const QPolygon& polygon1, const QPolygon& po QPoint prevPoint2 = polygon2.last(); foreach (const QPoint& point2, polygon2) { - const bool shareX = point1.x() == point2.x(); - const bool betweenY1 = (qMin(prevPoint2.y(), point2.y()) < point1.y()) && (point1.y() < qMax(prevPoint2.y(), point2.y())); - const bool betweenY2 = (qMin(prevPoint1.y(), point1.y()) < point2.y()) && (point2.y() < qMax(prevPoint1.y(), point1.y())); - const bool shareY = point1.y() == point2.y(); - const bool betweenX1 = (qMin(prevPoint2.x(), point2.x()) < point1.x()) && (point1.x() < qMax(prevPoint2.x(), point2.x())); - const bool betweenX2 = (qMin(prevPoint1.x(), point1.x()) < point2.x()) && (point2.x() < qMax(prevPoint1.x(), point1.x())); if (point1 == prevPoint2) { Resolutions flags = 0; @@ -113,7 +112,7 @@ static CollisionInfo findCollisions(const QPolygon& polygon1, const QPolygon& po data[point1] = NextTarget(flags, point1); break; } - else if ((shareX && betweenY1) || (shareY && betweenX1)) + else if ((((point2.x() == point1.x()) && between(point1.y(), prevPoint2.y(), point2.y())) || ((point2.y() == point1.y()) && between(point1.x(), prevPoint2.x(), point2.x())))) { data[point1] = NextTarget(Include, point2); break; |