X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fglobals.cpp;fp=src%2Fglobals.cpp;h=7be74e16e1112e3c15f2c9ebdae981b9db4728e2;hb=075de16b7430454597f1cde039405b18232f0058;hp=804960c7ad98ba96e9c86d49357de94f3da2c8d7;hpb=ae70f6ff733c4642fe3a9f8b3635a0a0b40cf82a;p=guemap diff --git a/src/globals.cpp b/src/globals.cpp index 804960c..7be74e1 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -9,7 +9,7 @@ #include "globals.h" #include - +#include "mathconstants.h" // // Class MapEdge: @@ -29,11 +29,16 @@ MapEdge::MapEdge(): room1(0), room2(0), end1(rcNone), end2(rcNone), type1(0), ty { } - MapEdge::MapEdge(RoomNum r1, RoomNum r2, EdgeType t1, EdgeType t2, RoomCorner e1, RoomCorner e2): room1(r1), room2(r2), end1(e1), end2(e2), type1(t1), type2(t2) { } +void MapEdge::Clear(void) +{ + room1 = room2 = 0; + end1 = end2 = rcNone; + type1 = type2 = 0; +} // // Actually swap the rooms for this edge @@ -53,7 +58,6 @@ void MapEdge::Swap(void) end2 = tc; } - bool MapEdge::HasRoom(RoomNum r) { if ((room1 != r) && (room2 != r)) @@ -62,7 +66,6 @@ bool MapEdge::HasRoom(RoomNum r) return true; } - // // Return the MapEdge but with the RoomNums, EdgeTypes, & RoomCorners swapped // @@ -72,7 +75,6 @@ MapEdge MapEdge::Swapped(void) const return MapEdge(room2, room1, type2 | (type1 & etObstructed), type1 & ~etObstructed, end2, end1); } - // // Class MapRoom: // @@ -91,13 +93,11 @@ MapRoom::MapRoom(): flags(0) { } - MapRoom::MapRoom(const MapRoom & o) { *this = o; } - MapRoom & MapRoom::operator=(const MapRoom & source) { pos = source.pos; @@ -107,21 +107,18 @@ MapRoom & MapRoom::operator=(const MapRoom & source) return *this; } - QRect MapRoom::getRect(void) { return QRect(pos, (flags & rfCorner ? QSize(gridX, gridY) : QSize(roomWidth, roomHeight))); } - QRect MapRoom::getTranslatedRect(QPoint t) { return QRect(pos + t, (flags & rfCorner ? QSize(gridX, gridY) : QSize(roomWidth, roomHeight))); } - QPoint MapRoom::GetCenter(void) { return QPoint(pos + @@ -130,13 +127,11 @@ QPoint MapRoom::GetCenter(void) : QPoint(roomWidth / 2, roomHeight / 2))); } - RoomFlags MapRoom::isCorner() const { return (flags & rfCorner); } - bool MapRoom::operator!=(const MapRoom & mr) const { if (pos != mr.pos) @@ -151,7 +146,6 @@ bool MapRoom::operator!=(const MapRoom & mr) const return true; } - // // Miscellaneous functions: //-------------------------------------------------------------------- @@ -166,7 +160,6 @@ void trimLeft(string & s) s.erase(0, p); } - // // Trim whitespace from right of string: // @@ -178,7 +171,6 @@ void trimRight(string & s) s.erase(p + 1); } - // // Consolidates action creation from a multi-step process to a single-step one. // @@ -194,7 +186,6 @@ QAction * CreateAction(QString name, QString tooltip, return action; } - // // This is essentially the same as the previous function, but this allows more // than one key sequence to be added as key shortcuts. @@ -215,7 +206,6 @@ QAction * CreateAction(QString name, QString tooltip, return action; } - // // Miscellaneous geometrical helper functions // @@ -224,7 +214,6 @@ double Magnitude(QPointF p) return sqrt((p.x() * p.x()) + (p.y() * p.y())); } - QPointF UnitVector(QPointF p) { double magnitude = Magnitude(p); @@ -235,31 +224,36 @@ QPointF UnitVector(QPointF p) return QPointF(p.x() / magnitude, p.y() / magnitude); } - double Angle(QPointF p) { - return atan2(p.y(), p.x()); -} + double angle = atan2(p.y(), p.x()); + if (angle < 0) + angle += TAU; + + return angle; +} double Angle(QPoint p) { - return atan2((double)p.y(), (double)p.x()); -} + double angle = atan2((double)p.y(), (double)p.x()); + + if (angle < 0) + angle += TAU; + return angle; +} double Dot(QPointF a, QPointF b) { return (a.x() * b.x()) + (a.y() * b.y()); } - double Determinant(QPointF a, QPointF b) { return (a.x() * b.y()) - (b.x() * a.y()); } - // Returns the parameter of a point in space to this vector. If the parameter // is between 0 and 1, the normal of the vector to the point is on the vector. double ParameterOfLineAndPoint(QPointF tail, QPointF head, QPointF point) @@ -274,6 +268,6 @@ double ParameterOfLineAndPoint(QPointF tail, QPointF head, QPointF point) double magnitude = Magnitude(lineSegment); QPointF pointSegment = point - tail; double t = Dot(lineSegment, pointSegment) / (magnitude * magnitude); + return t; } -