21 #include "ns3/assert.h"
22 #include "ns3/fatal-error.h"
23 #include "ns3/vector.h"
52 return position.x <= this->
xMax && position.x >= this->
xMin && position.y <= this->
yMax &&
53 position.y >= this->
yMin;
59 return position.x == this->
xMax || position.x == this->
xMin || position.y == this->
yMax ||
60 position.y == this->
yMin;
66 std::array<double, 4> distanceFromBorders{
67 std::abs(position.x - this->xMin),
68 std::abs(this->
xMax - position.x),
69 std::abs(position.y - this->yMin),
70 std::abs(this->
yMax - position.y),
74 for (
int i = 0; i < 4; i++)
76 if (distanceFromBorders[i] > minDist)
82 if (distanceFromBorders[i] < minDist)
84 minDist = distanceFromBorders[i];
87 flags |= (0b1000 >> i);
155 double xMaxY = current.y + (this->
xMax - current.x) / speed.x * speed.y;
156 double xMinY = current.y + (this->xMin - current.x) / speed.x * speed.y;
157 double yMaxX = current.x + (this->
yMax - current.y) / speed.y * speed.x;
158 double yMinX = current.x + (this->yMin - current.y) / speed.y * speed.x;
159 bool xMaxYOk = (xMaxY <= this->
yMax && xMaxY >= this->
yMin);
160 bool xMinYOk = (xMinY <= this->
yMax && xMinY >= this->
yMin);
161 bool yMaxXOk = (yMaxX <= this->
xMax && yMaxX >= this->
xMin);
162 bool yMinXOk = (yMinX <= this->
xMax && yMinX >= this->
xMin);
163 if (xMaxYOk && speed.x >= 0)
165 return Vector(this->
xMax, xMaxY, 0.0);
167 else if (xMinYOk && speed.x <= 0)
169 return Vector(this->
xMin, xMinY, 0.0);
171 else if (yMaxXOk && speed.y >= 0)
173 return Vector(yMaxX, this->
yMax, 0.0);
175 else if (yMinXOk && speed.y <= 0)
177 return Vector(yMinX, this->
yMin, 0.0);
183 return Vector(0.0, 0.0, 0.0);
199 os << rectangle.
xMin <<
"|" << rectangle.
xMax <<
"|" << rectangle.
yMin <<
"|" << rectangle.
yMax;
216 is >> rectangle.
xMin >> c1 >> rectangle.
xMax >> c2 >> rectangle.
yMin >> c3 >> rectangle.
yMax;
217 if (c1 !=
'|' || c2 !=
'|' || c3 !=
'|')
219 is.setstate(std::ios_base::failbit);
249 os <<
"TOPRIGHTCORNER";
252 os <<
"TOPLEFTCORNER";
255 os <<
"BOTTOMRIGHTCORNER";
258 os <<
"BOTTOMLEFTCORNER";
double yMax
The y coordinate of the top bound of the rectangle.
Side GetClosestSideOrCorner(const Vector &position) const
bool IsInside(const Vector &position) const
bool IsOnTheBorder(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(ValueClassTest)
std::istream & operator>>(std::istream &is, Angles &a)
std::ostream & operator<<(std::ostream &os, const Angles &a)