Bug 1301 - Ns2MobilityHelper causes Node GetPosition() to return NaN: fixed.
--- a/src/mobility/helper/ns2-mobility-helper.cc Wed Dec 14 18:50:28 2011 +0300
+++ b/src/mobility/helper/ns2-mobility-helper.cc Wed Dec 14 19:00:11 2011 +0300
@@ -642,6 +642,10 @@
// first calculate the time; time = distance / speed
double time = sqrt (pow (xFinalPosition - retval.m_finalPosition.x, 2) + pow (yFinalPosition - retval.m_finalPosition.y, 2)) / speed;
NS_LOG_DEBUG ("at=" << at << " time=" << time);
+ if (time == 0)
+ {
+ return retval;
+ }
// now calculate the xSpeed = distance / time
double xSpeed = (xFinalPosition - retval.m_finalPosition.x) / time;
double ySpeed = (yFinalPosition - retval.m_finalPosition.y) / time; // & same with ySpeed
@@ -653,10 +657,7 @@
NS_LOG_DEBUG ("Calculated Speed: X=" << xSpeed << " Y=" << ySpeed << " Z=" << zSpeed);
// Set the Values
- if (time >= 0)
- {
- Simulator::Schedule (Seconds (at), &ConstantVelocityMobilityModel::SetVelocity, model, Vector (xSpeed, ySpeed, zSpeed));
- }
+ Simulator::Schedule (Seconds (at), &ConstantVelocityMobilityModel::SetVelocity, model, Vector (xSpeed, ySpeed, zSpeed));
retval.m_stopEvent = Simulator::Schedule (Seconds (at + time), &ConstantVelocityMobilityModel::SetVelocity, model, Vector (0, 0, 0));
retval.m_finalPosition.x += xSpeed * time;
retval.m_finalPosition.y += ySpeed * time;
--- a/src/mobility/test/ns2-mobility-helper-test-suite.cc Wed Dec 14 18:50:28 2011 +0300
+++ b/src/mobility/test/ns2-mobility-helper-test-suite.cc Wed Dec 14 19:00:11 2011 +0300
@@ -439,6 +439,17 @@
// id t position velocity
t->AddReferencePoint ("0", 0, Vector (10, 0, 0), Vector (0, 0, 0));
AddTestCase (t);
+ t = new Ns2MobilityHelperTest ("Bug 1301 testcase", Seconds (16));
+ t->SetTrace ("$node_(0) set X_ 10.0\n"
+ "$node_(0) set Y_ 0.0\n"
+ "$ns_ at 1.0 \"$node_(0) setdest 10 0 1\"\n"
+ );
+ // id t position velocity
+ // Moving to the current position must change nothing. No NaN
+ // speed must be.
+ t->AddReferencePoint ("0", 0, Vector (10, 0, 0), Vector (0, 0, 0));
+ AddTestCase (t);
+
}
} g_ns2TransmobilityHelperTestSuite;