#include "globals.h"
#include <math.h>
-
+#include "mathconstants.h"
//
// Class MapEdge:
{
}
-
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
end2 = tc;
}
-
bool MapEdge::HasRoom(RoomNum r)
{
if ((room1 != r) && (room2 != r))
return true;
}
-
//
// Return the MapEdge but with the RoomNums, EdgeTypes, & RoomCorners swapped
//
return MapEdge(room2, room1, type2 | (type1 & etObstructed), type1 & ~etObstructed, end2, end1);
}
-
//
// Class MapRoom:
//
{
}
-
MapRoom::MapRoom(const MapRoom & o)
{
*this = o;
}
-
MapRoom & MapRoom::operator=(const MapRoom & source)
{
pos = source.pos;
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 +
: QPoint(roomWidth / 2, roomHeight / 2)));
}
-
RoomFlags MapRoom::isCorner() const
{
return (flags & rfCorner);
}
-
bool MapRoom::operator!=(const MapRoom & mr) const
{
if (pos != mr.pos)
return true;
}
-
//
// Miscellaneous functions:
//--------------------------------------------------------------------
s.erase(0, p);
}
-
//
// Trim whitespace from right of string:
//
s.erase(p + 1);
}
-
//
// Consolidates action creation from a multi-step process to a single-step one.
//
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.
return action;
}
-
//
// Miscellaneous geometrical helper functions
//
return sqrt((p.x() * p.x()) + (p.y() * p.y()));
}
-
QPointF UnitVector(QPointF p)
{
double magnitude = Magnitude(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)
double magnitude = Magnitude(lineSegment);
QPointF pointSegment = point - tail;
double t = Dot(lineSegment, pointSegment) / (magnitude * magnitude);
+
return t;
}
-