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;
58 double xMinDist = std::abs (position.x - this->xMin);
59 double xMaxDist = std::abs (this->
xMax - position.x);
60 double yMinDist = std::abs (position.y - this->yMin);
61 double yMaxDist = std::abs (this->
yMax - position.y);
62 double minX =
std::min (xMinDist, xMaxDist);
63 double minY =
std::min (yMinDist, yMaxDist);
66 if (xMinDist < xMaxDist)
77 if (yMinDist < yMaxDist)
92 double xMaxY = current.y + (this->
xMax - current.x) / speed.x * speed.y;
93 double xMinY = current.y + (this->xMin - current.x) / speed.x * speed.y;
94 double yMaxX = current.x + (this->
yMax - current.y) / speed.y * speed.x;
95 double yMinX = current.x + (this->yMin - current.y) / speed.y * speed.x;
96 bool xMaxYOk = (xMaxY <= this->
yMax && xMaxY >= this->
yMin);
97 bool xMinYOk = (xMinY <= this->
yMax && xMinY >= this->
yMin);
98 bool yMaxXOk = (yMaxX <= this->
xMax && yMaxX >= this->
xMin);
99 bool yMinXOk = (yMinX <= this->
xMax && yMinX >= this->
xMin);
100 if (xMaxYOk && speed.x >= 0)
102 return Vector (this->
xMax, xMaxY, 0.0);
104 else if (xMinYOk && speed.x <= 0)
106 return Vector (this->
xMin, xMinY, 0.0);
108 else if (yMaxXOk && speed.y >= 0)
110 return Vector (yMaxX, this->
yMax, 0.0);
112 else if (yMinXOk && speed.y <= 0)
114 return Vector (yMinX, this->
yMin, 0.0);
120 return Vector (0.0, 0.0, 0.0);
137 os << rectangle.
xMin <<
"|" << rectangle.
xMax <<
"|" << rectangle.
yMin <<
"|" << rectangle.
yMax;
151 is >> rectangle.
xMin >> c1 >> rectangle.
xMax >> c2 >> rectangle.
yMin >> c3 >> rectangle.
yMax;
156 is.setstate (std::ios_base::failbit);
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
bool IsInside(const Vector &position) const
#define ATTRIBUTE_HELPER_CPP(type)
Define the attribute value, accessor and checkers for class type.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
double yMax
The y coordinate of the top bound of the rectangle.
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)
Vector CalculateIntersection(const Vector ¤t, const Vector &speed) const
double xMax
The x coordinate of the right bound of the rectangle.
Side
enum for naming sides
double yMin
The y coordinate of the bottom bound of the rectangle.
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Side GetClosestSide(const Vector &position) const