--- a/src/node/random-walk-2d-mobility-model.cc Thu Jul 19 09:48:10 2007 +0200
+++ b/src/node/random-walk-2d-mobility-model.cc Thu Jul 19 09:54:57 2007 +0200
@@ -151,7 +151,20 @@
void
RandomWalk2dMobilityModel::Rebound (Time delayLeft)
{
- m_helper.Rebound (m_parameters->m_bounds);
+ Position position = m_helper.GetCurrentPosition (m_parameters->m_bounds);
+ Speed speed = m_helper.GetSpeed ();
+ switch (m_parameters->m_bounds.GetClosestSide (position))
+ {
+ case Rectangle::RIGHT:
+ case Rectangle::LEFT:
+ speed.dx = - speed.dx;
+ break;
+ case Rectangle::TOP:
+ case Rectangle::BOTTOM:
+ speed.dy = - speed.dy;
+ break;
+ }
+ m_helper.Reset (speed);
DoWalk (delayLeft);
}
--- a/src/node/static-speed-helper.cc Thu Jul 19 09:48:10 2007 +0200
+++ b/src/node/static-speed-helper.cc Thu Jul 19 09:54:57 2007 +0200
@@ -31,7 +31,7 @@
}
Speed
-StaticSpeedHelper::GetCurrentSpeed (void) const
+StaticSpeedHelper::GetSpeed (void) const
{
return m_speed;
}
@@ -80,25 +80,6 @@
Time delay = Seconds ((nextPosition.x - m_position.x) / m_speed.dx);
return delay;
}
-void
-StaticSpeedHelper::Rebound (const Rectangle &bounds)
-{
- UpdateFull (bounds);
- double xMinDist = m_position.x - bounds.xMin;
- double xMaxDist = bounds.xMax - m_position.x;
- double yMinDist = m_position.y - bounds.yMin;
- double yMaxDist = bounds.yMax - m_position.y;
- double minX = std::min (xMinDist, xMaxDist);
- double minY = std::min (yMinDist, yMaxDist);
- if (minY < minX)
- {
- m_speed.dy = - m_speed.dy;
- }
- else
- {
- m_speed.dx = - m_speed.dx;
- }
-}
void
StaticSpeedHelper::UpdateFull (const Rectangle &bounds) const
--- a/src/node/static-speed-helper.h Thu Jul 19 09:48:10 2007 +0200
+++ b/src/node/static-speed-helper.h Thu Jul 19 09:54:57 2007 +0200
@@ -19,11 +19,10 @@
void Reset (const Speed &speed);
Time GetDelayToNextPosition (const Rectangle &bounds, Time delayLeft);
- void Rebound (const Rectangle &bounds);
Position GetCurrentPosition (const Rectangle &bounds) const;
Position GetCurrentPosition (void) const;
- Speed GetCurrentSpeed (void) const;
+ Speed GetSpeed (void) const;
private:
void Update (void) const;