21#include "ns3/assert.h"
22#include "ns3/fatal-error.h"
23#include "ns3/vector.h"
51 return position.x <= this->
xMax && position.x >= this->
xMin && position.y <= this->
yMax &&
52 position.y >= this->
yMin;
60 double xMinDist = std::abs(position.x - this->xMin);
61 double xMaxDist = std::abs(this->
xMax - position.x);
62 double yMinDist = std::abs(position.y - this->yMin);
63 double yMaxDist = std::abs(this->
yMax - position.y);
64 double minX = std::min(xMinDist, xMaxDist);
65 double minY = std::min(yMinDist, yMaxDist);
68 if (xMinDist < xMaxDist)
79 if (yMinDist < yMaxDist)
91 if (position.x < this->xMin)
93 if (position.y < this->yMin)
95 double yDiff = this->
yMin - position.y;
96 double xDiff = this->
xMin - position.x;
106 else if (position.y < this->yMax)
112 double yDiff = position.y - this->
yMax;
113 double xDiff = this->
xMin - position.x;
124 else if (position.x < this->xMax)
126 if (position.y < this->yMin)
130 else if (position.y < this->yMax)
133 "This region should have been reached if the IsInside check was true");
143 if (position.y < this->yMin)
145 double yDiff = this->
yMin - position.y;
146 double xDiff = position.x - this->
xMin;
156 else if (position.y < this->yMax)
162 double yDiff = position.y - this->
yMax;
163 double xDiff = position.x - this->
xMin;
181 double xMaxY = current.y + (this->
xMax - current.x) / speed.x * speed.y;
182 double xMinY = current.y + (this->xMin - current.x) / speed.x * speed.y;
183 double yMaxX = current.x + (this->
yMax - current.y) / speed.y * speed.x;
184 double yMinX = current.x + (this->yMin - current.y) / speed.y * speed.x;
185 bool xMaxYOk = (xMaxY <= this->
yMax && xMaxY >= this->
yMin);
186 bool xMinYOk = (xMinY <= this->
yMax && xMinY >= this->
yMin);
187 bool yMaxXOk = (yMaxX <= this->
xMax && yMaxX >= this->
xMin);
188 bool yMinXOk = (yMinX <= this->
xMax && yMinX >= this->
xMin);
189 if (xMaxYOk && speed.x >= 0)
191 return Vector(this->
xMax, xMaxY, 0.0);
193 else if (xMinYOk && speed.x <= 0)
195 return Vector(this->
xMin, xMinY, 0.0);
197 else if (yMaxXOk && speed.y >= 0)
199 return Vector(yMaxX, this->
yMax, 0.0);
201 else if (yMinXOk && speed.y <= 0)
203 return Vector(yMinX, this->
yMin, 0.0);
209 return Vector(0.0, 0.0, 0.0);
225 os << rectangle.
xMin <<
"|" << rectangle.
xMax <<
"|" << rectangle.
yMin <<
"|" << rectangle.
yMax;
242 is >> rectangle.
xMin >> c1 >> rectangle.
xMax >> c2 >> rectangle.
yMin >> c3 >> rectangle.
yMax;
243 if (c1 !=
'|' || c2 !=
'|' || c3 !=
'|')
245 is.setstate(std::ios_base::failbit);
Side GetClosestSide(const Vector &position) const
double yMax
The y coordinate of the top bound of the rectangle.
bool IsInside(const Vector &position) const
double xMax
The x coordinate of the right bound of the rectangle.
Vector CalculateIntersection(const Vector ¤t, const Vector &speed) const
Side
enum for naming sides
double xMin
The x coordinate of the left bound of the rectangle.
Rectangle()
Create a zero-sized rectangle located at coordinates (0.0,0.0)
double yMin
The y coordinate of the bottom bound of the rectangle.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define ATTRIBUTE_HELPER_CPP(type)
Define the attribute value, accessor and checkers for class type
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
std::istream & operator>>(std::istream &is, Angles &a)