21 #include "ns3/vector.h"
22 #include "ns3/assert.h"
23 #include "ns3/fatal-error.h"
31 double _yMin,
double _yMax)
51 position.x <= this->
xMax && position.x >= this->
xMin &&
52 position.y <= this->
yMax && 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)
132 NS_FATAL_ERROR (
"This region should have been reached if the IsInside check was true");
142 if (position.y < this->yMin)
144 double yDiff = this->
yMin - position.y;
145 double xDiff = position.x - this->
xMin;
155 else if (position.y < this->yMax)
161 double yDiff = position.y - this->
yMax;
162 double xDiff = position.x - this->
xMin;
180 double xMaxY = current.y + (this->
xMax - current.x) / speed.x * speed.y;
181 double xMinY = current.y + (this->xMin - current.x) / speed.x * speed.y;
182 double yMaxX = current.x + (this->
yMax - current.y) / speed.y * speed.x;
183 double yMinX = current.x + (this->yMin - current.y) / speed.y * speed.x;
184 bool xMaxYOk = (xMaxY <= this->
yMax && xMaxY >= this->
yMin);
185 bool xMinYOk = (xMinY <= this->
yMax && xMinY >= this->
yMin);
186 bool yMaxXOk = (yMaxX <= this->
xMax && yMaxX >= this->
xMin);
187 bool yMinXOk = (yMinX <= this->
xMax && yMinX >= this->
xMin);
188 if (xMaxYOk && speed.x >= 0)
190 return Vector (this->
xMax, xMaxY, 0.0);
192 else if (xMinYOk && speed.x <= 0)
194 return Vector (this->
xMin, xMinY, 0.0);
196 else if (yMaxXOk && speed.y >= 0)
198 return Vector (yMaxX, this->
yMax, 0.0);
200 else if (yMinXOk && speed.y <= 0)
202 return Vector (yMinX, this->
yMin, 0.0);
208 return Vector (0.0, 0.0, 0.0);
225 os << rectangle.
xMin <<
"|" << rectangle.
xMax <<
"|" << rectangle.
yMin <<
"|" << rectangle.
yMax;
239 is >> rectangle.
xMin >> c1 >> rectangle.
xMax >> c2 >> rectangle.
yMin >> c3 >> rectangle.
yMax;
244 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 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.
ATTRIBUTE_HELPER_CPP(Length)
std::istream & operator>>(std::istream &is, Angles &a)
std::ostream & operator<<(std::ostream &os, const Angles &a)