move delay calculation code from helper to random walk class
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 19 Jul 2007 10:01:42 +0200
changeset 1619 82612ea8b2a7
parent 1618 35f814bf6e4b
child 1620 69baa7b1c487
move delay calculation code from helper to random walk class
src/node/random-walk-2d-mobility-model.cc
src/node/static-speed-helper.cc
src/node/static-speed-helper.h
--- a/src/node/random-walk-2d-mobility-model.cc	Thu Jul 19 09:54:57 2007 +0200
+++ b/src/node/random-walk-2d-mobility-model.cc	Thu Jul 19 10:01:42 2007 +0200
@@ -133,18 +133,22 @@
 void
 RandomWalk2dMobilityModel::DoWalk (Time delayLeft)
 {
-  Time delay = m_helper.GetDelayToNextPosition (m_parameters->m_bounds, 
-                                                delayLeft);
-  if (delay < delayLeft)
+  Position position = m_helper.GetCurrentPosition ();
+  Speed speed = m_helper.GetSpeed ();
+  Position nextPosition = position;
+  nextPosition.x += speed.dx * delayLeft.GetSeconds ();
+  nextPosition.y += speed.dy * delayLeft.GetSeconds ();
+  if (m_parameters->m_bounds.IsInside (nextPosition))
     {
-      m_event = Simulator::Schedule (delay, &RandomWalk2dMobilityModel::Rebound, this,
-                                     delayLeft - delay);
+      m_event = Simulator::Schedule (delayLeft, &RandomWalk2dMobilityModel::Start, this);
     }
   else
     {
-      NS_ASSERT (delay == delayLeft);
-      m_event = Simulator::Schedule (delay, &RandomWalk2dMobilityModel::Start, this);
-    }
+      nextPosition = m_parameters->m_bounds.CalculateIntersection (position, speed);
+      Time delay = Seconds ((nextPosition.x - position.x) / speed.dx);
+      m_event = Simulator::Schedule (delay, &RandomWalk2dMobilityModel::Rebound, this,
+                                     delayLeft - delay);      
+    }  
   NotifyCourseChange ();
 }
 
--- a/src/node/static-speed-helper.cc	Thu Jul 19 09:54:57 2007 +0200
+++ b/src/node/static-speed-helper.cc	Thu Jul 19 10:01:42 2007 +0200
@@ -64,23 +64,6 @@
   m_speed = speed;
   m_pauseEnd = Simulator::Now ();
 }
-Time 
-StaticSpeedHelper::GetDelayToNextPosition (const Rectangle &bounds, Time delayLeft)
-{
-  UpdateFull (bounds);
-  Position nextPosition = m_position;
-  nextPosition.x += m_speed.dx * delayLeft.GetSeconds ();
-  nextPosition.y += m_speed.dy * delayLeft.GetSeconds ();
-  if (bounds.IsInside (nextPosition))
-    {
-      return delayLeft;
-    }
-  
-  nextPosition = bounds.CalculateIntersection (m_position, m_speed);
-  Time delay = Seconds ((nextPosition.x - m_position.x) / m_speed.dx);
-  return delay;
-}
-
 void
 StaticSpeedHelper::UpdateFull (const Rectangle &bounds) const
 {
--- a/src/node/static-speed-helper.h	Thu Jul 19 09:54:57 2007 +0200
+++ b/src/node/static-speed-helper.h	Thu Jul 19 10:01:42 2007 +0200
@@ -16,11 +16,8 @@
   void InitializePosition (const Position &position);
 
   void Reset (const Speed &speed, const Time &pauseDelay);
-
   void Reset (const Speed &speed);
-  Time GetDelayToNextPosition (const Rectangle &bounds, Time delayLeft);
   Position GetCurrentPosition (const Rectangle &bounds) const;
-
   Position GetCurrentPosition (void) const;
   Speed GetSpeed (void) const;