move around rectangle class and move IsInside method from Position to Rectangle
This commit is contained in:
@@ -63,8 +63,6 @@ core.add_sources([
|
||||
'uid-manager.cc',
|
||||
'default-value.cc',
|
||||
'random-variable-default-value.cc',
|
||||
'rectangle-default-value.cc',
|
||||
'rectangle.cc',
|
||||
'command-line.cc',
|
||||
'type-name.cc',
|
||||
'component-manager.cc',
|
||||
@@ -97,8 +95,6 @@ core.add_inst_headers([
|
||||
'rng-stream.h',
|
||||
'default-value.h',
|
||||
'random-variable-default-value.h',
|
||||
'rectangle-default-value.h',
|
||||
'rectangle.h',
|
||||
'command-line.h',
|
||||
'type-name.h',
|
||||
'component-manager.h',
|
||||
@@ -266,6 +262,8 @@ node.add_sources ([
|
||||
'speed.cc',
|
||||
'static-speed-helper.cc',
|
||||
'random-waypoint-mobility-model.cc',
|
||||
'rectangle-default-value.cc',
|
||||
'rectangle.cc',
|
||||
])
|
||||
node.add_inst_headers ([
|
||||
'node.h',
|
||||
@@ -299,6 +297,8 @@ node.add_inst_headers ([
|
||||
'speed.h',
|
||||
'static-speed-helper.h',
|
||||
'random-waypoint-mobility-model.h',
|
||||
'rectangle-default-value.h',
|
||||
'rectangle.h',
|
||||
])
|
||||
|
||||
applications = build.Ns3Module ('applications', 'src/applications')
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include "position.h"
|
||||
#include "ns3/rectangle.h"
|
||||
#include <cmath>
|
||||
|
||||
namespace ns3 {
|
||||
@@ -17,14 +16,6 @@ Position::Position ()
|
||||
z (0.0)
|
||||
{}
|
||||
|
||||
bool
|
||||
Position::IsInside (const Rectangle &rectangle) const
|
||||
{
|
||||
return
|
||||
x <= rectangle.xMax && x >= rectangle.xMin &&
|
||||
y <= rectangle.yMax && y >= rectangle.yMin;
|
||||
}
|
||||
|
||||
double
|
||||
CalculateDistance (const Position &a, const Position &b)
|
||||
{
|
||||
|
||||
@@ -3,14 +3,11 @@
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Rectangle;
|
||||
|
||||
class Position
|
||||
{
|
||||
public:
|
||||
Position (double x, double y, double z);
|
||||
Position ();
|
||||
bool IsInside (const Rectangle &rectangle) const;
|
||||
double x;
|
||||
double y;
|
||||
double z;
|
||||
|
||||
@@ -170,7 +170,7 @@ RandomWalk2dMobilityModel::DoGet (void) const
|
||||
void
|
||||
RandomWalk2dMobilityModel::DoSet (const Position &position)
|
||||
{
|
||||
NS_ASSERT (position.IsInside (m_parameters->m_bounds));
|
||||
NS_ASSERT (m_parameters->m_bounds.IsInside (position));
|
||||
m_helper.InitializePosition (position);
|
||||
Simulator::Remove (m_event);
|
||||
m_event = Simulator::ScheduleNow (&RandomWalk2dMobilityModel::Start, this);
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#define RECTANGLE_DEFAULT_VALUE_H
|
||||
|
||||
#include <string>
|
||||
#include "default-value.h"
|
||||
#include "ns3/default-value.h"
|
||||
#include "rectangle.h"
|
||||
|
||||
namespace ns3 {
|
||||
@@ -19,6 +19,9 @@
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
#include "rectangle.h"
|
||||
#include "position.h"
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
@@ -37,4 +40,46 @@ Rectangle::Rectangle ()
|
||||
yMax (0.0)
|
||||
{}
|
||||
|
||||
bool
|
||||
Rectangle::IsInside (const Position &position) const
|
||||
{
|
||||
return
|
||||
position.x <= xMax && position.x >= xMin &&
|
||||
position.y <= yMax && position.y >= yMin;
|
||||
}
|
||||
|
||||
Rectangle::Side
|
||||
Rectangle::GetClosestSide (const Position &position) const
|
||||
{
|
||||
double xMinDist = std::abs (position.x - xMin);
|
||||
double xMaxDist = std::abs (xMax - position.x);
|
||||
double yMinDist = std::abs (position.y - yMin);
|
||||
double yMaxDist = std::abs (yMax - position.y);
|
||||
double minX = std::min (xMinDist, xMaxDist);
|
||||
double minY = std::min (yMinDist, yMaxDist);
|
||||
if (minX < minY)
|
||||
{
|
||||
if (xMinDist < xMaxDist)
|
||||
{
|
||||
return LEFT;
|
||||
}
|
||||
else
|
||||
{
|
||||
return RIGHT;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (yMinDist < yMaxDist)
|
||||
{
|
||||
return BOTTOM;
|
||||
}
|
||||
else
|
||||
{
|
||||
return TOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace ns3
|
||||
@@ -23,12 +23,23 @@
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Position;
|
||||
|
||||
class Rectangle
|
||||
{
|
||||
public:
|
||||
enum Side {
|
||||
RIGHT,
|
||||
LEFT,
|
||||
TOP,
|
||||
BOTTOM
|
||||
};
|
||||
Rectangle (double _xMin, double _xMax,
|
||||
double _yMin, double _yMax);
|
||||
Rectangle ();
|
||||
bool IsInside (const Position &position) const;
|
||||
Side GetClosestSide (const Position &position) const;
|
||||
|
||||
double xMin;
|
||||
double xMax;
|
||||
double yMin;
|
||||
@@ -105,7 +105,7 @@ StaticSpeedHelper::GetDelayToNextPosition (const Rectangle &bounds, Time delayLe
|
||||
Position nextPosition = m_position;
|
||||
nextPosition.x += m_speed.dx * delayLeft.GetSeconds ();
|
||||
nextPosition.y += m_speed.dy * delayLeft.GetSeconds ();
|
||||
if (nextPosition.IsInside (bounds))
|
||||
if (bounds.IsInside (nextPosition))
|
||||
{
|
||||
return delayLeft;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user