Variables time and position in waypoint are public as in the original code
authorPhillip Sitbon <phillip.sitbon@gmail.com>
Wed Nov 11 11:57:14 2009 +0100 (3 months ago)
changeset 55010d210dbf36eb
parent 5500 61d8417157e5
child 5502 04acce3f7133
Variables time and position in waypoint are public as in the original code
src/mobility/waypoint-mobility-model.cc
src/mobility/waypoint.cc
src/mobility/waypoint.h
     1.1 --- a/src/mobility/waypoint-mobility-model.cc	Wed Nov 11 00:27:47 2009 +0300
     1.2 +++ b/src/mobility/waypoint-mobility-model.cc	Wed Nov 11 11:57:14 2009 +0100
     1.3 @@ -75,7 +75,7 @@
     1.4      }
     1.5    else
     1.6      {
     1.7 -      NS_ABORT_MSG_IF ( !m_waypoints.empty () && (m_waypoints.back ().GetTime () >= waypoint.GetTime ()),
     1.8 +      NS_ABORT_MSG_IF ( !m_waypoints.empty () && (m_waypoints.back ().time >= waypoint.time),
     1.9                          "Waypoints must be added in ascending time order");
    1.10        m_waypoints.push_back (waypoint);
    1.11      }
    1.12 @@ -98,25 +98,25 @@
    1.13    const Time now = Simulator::Now ();
    1.14    bool newWaypoint = false;
    1.15  
    1.16 -  if ( now <= m_current.GetTime () )
    1.17 +  if ( now <= m_current.time )
    1.18      {
    1.19        return;
    1.20      }
    1.21  
    1.22 -  while ( now >= m_next.GetTime ()  )
    1.23 +  while ( now >= m_next.time  )
    1.24      {
    1.25        if ( m_waypoints.empty () )
    1.26          {
    1.27 -          if ( m_current.GetTime () <= m_next.GetTime () )
    1.28 +          if ( m_current.time <= m_next.time )
    1.29              {
    1.30 -              m_current.SetPosition(m_next.GetPosition ());
    1.31 -              m_current.SetTime (now);
    1.32 +              m_current.position = m_next.position;
    1.33 +              m_current.time = now;
    1.34                m_velocity = Vector (0,0,0);
    1.35                NotifyCourseChange ();
    1.36              }
    1.37            else
    1.38              {
    1.39 -              m_current.SetTime (now);
    1.40 +              m_current.time = now;
    1.41              }
    1.42  
    1.43            return;
    1.44 @@ -127,21 +127,19 @@
    1.45        m_waypoints.pop_front ();
    1.46        newWaypoint = true;
    1.47  
    1.48 -      const double t_span = (m_next.GetTime () - m_current.GetTime ()).GetSeconds ();
    1.49 +      const double t_span = (m_next.time - m_current.time).GetSeconds ();
    1.50        NS_ASSERT (t_span > 0);
    1.51 -      m_velocity.x = (m_next.GetPosition ().x - m_current.GetPosition ().x) / t_span;
    1.52 -      m_velocity.y = (m_next.GetPosition ().y - m_current.GetPosition ().y) / t_span;
    1.53 -      m_velocity.z = (m_next.GetPosition ().z - m_current.GetPosition ().z) / t_span;
    1.54 +      m_velocity.x = (m_next.position.x - m_current.position.x) / t_span;
    1.55 +      m_velocity.y = (m_next.position.y - m_current.position.y) / t_span;
    1.56 +      m_velocity.z = (m_next.position.z - m_current.position.z) / t_span;
    1.57      }
    1.58  
    1.59  
    1.60 -  const double t_diff = (now - m_current.GetTime ()).GetSeconds();
    1.61 -  Vector pos;
    1.62 -  pos.x = m_current.GetPosition ().x + m_velocity.x * t_diff;
    1.63 -  pos.y = m_current.GetPosition ().y + m_velocity.y * t_diff;
    1.64 -  pos.z = m_current.GetPosition ().z + m_velocity.z * t_diff;
    1.65 -  m_current.SetPosition (pos);
    1.66 -  m_current.SetTime (now);
    1.67 +  const double t_diff = (now - m_current.time).GetSeconds();
    1.68 +  m_current.position.x += m_velocity.x * t_diff;
    1.69 +  m_current.position.y += m_velocity.y * t_diff;
    1.70 +  m_current.position.z += m_velocity.z * t_diff;
    1.71 +  m_current.time = now;
    1.72  
    1.73    if ( newWaypoint )
    1.74      {
    1.75 @@ -152,15 +150,15 @@
    1.76  WaypointMobilityModel::DoGetPosition (void) const
    1.77  {
    1.78    Update ();
    1.79 -  return m_current.GetPosition ();
    1.80 +  return m_current.position;
    1.81  }
    1.82  void
    1.83  WaypointMobilityModel::DoSetPosition (const Vector &position)
    1.84  {
    1.85    const Time now = Simulator::Now ();
    1.86    Update ();
    1.87 -  m_current.SetTime (std::max (now, m_next.GetTime ()));
    1.88 -  m_current.SetPosition (position);
    1.89 +  m_current.time = std::max (now, m_next.time);
    1.90 +  m_current.position = position;
    1.91    m_velocity = Vector (0,0,0);
    1.92    NotifyCourseChange ();
    1.93  }
    1.94 @@ -168,8 +166,8 @@
    1.95  WaypointMobilityModel::EndMobility (void)
    1.96  {
    1.97    m_waypoints.clear ();
    1.98 -  m_current.SetTime (Seconds (std::numeric_limits<double>::infinity ()));
    1.99 -  m_next.SetTime (m_current.GetTime ());
   1.100 +  m_current.time = Seconds (std::numeric_limits<double>::infinity ());
   1.101 +  m_next.time = m_current.time;
   1.102    m_first = true;
   1.103  }
   1.104  Vector
     2.1 --- a/src/mobility/waypoint.cc	Wed Nov 11 00:27:47 2009 +0300
     2.2 +++ b/src/mobility/waypoint.cc	Wed Nov 11 11:57:14 2009 +0100
     2.3 @@ -24,45 +24,23 @@
     2.4  ATTRIBUTE_HELPER_CPP (Waypoint);
     2.5  
     2.6  Waypoint::Waypoint (const Time &waypointTime, const Vector &waypointPosition)
     2.7 -  : m_time (waypointTime),
     2.8 -  m_position (waypointPosition)
     2.9 +  : time (waypointTime),
    2.10 +  position (waypointPosition)
    2.11  {}
    2.12  Waypoint::Waypoint ()
    2.13 -  : m_time (0.0),
    2.14 -  m_position (0,0,0)
    2.15 +  : time (0.0),
    2.16 +  position (0,0,0)
    2.17  {}
    2.18  
    2.19 -Time Waypoint::GetTime () const
    2.20 -{
    2.21 -  return m_time;
    2.22 -}
    2.23 -
    2.24 -void Waypoint::SetTime (Time time)
    2.25 -{
    2.26 -  m_time = time;
    2.27 -}
    2.28 -
    2.29 -Vector Waypoint::GetPosition () const
    2.30 -{
    2.31 -  return m_position;
    2.32 -}
    2.33 -
    2.34 -void Waypoint::SetPosition (Vector pos)
    2.35 -{
    2.36 -  m_position = pos;
    2.37 -}
    2.38 -
    2.39  std::ostream &operator << (std::ostream &os, const Waypoint &waypoint)
    2.40  {
    2.41 -  os << waypoint.GetTime ().GetSeconds () << "$" << waypoint.GetPosition ();
    2.42 +  os << waypoint.time.GetSeconds () << "$" << waypoint.position;
    2.43    return os;
    2.44  }
    2.45  std::istream &operator >> (std::istream &is, Waypoint &waypoint)
    2.46  {
    2.47    char separator;
    2.48 -  Time time = waypoint.GetTime ();
    2.49 -  Vector pos = waypoint.GetPosition ();
    2.50 -  is >> time >> separator >> pos;
    2.51 +  is >> waypoint.time >> separator >> waypoint.position;
    2.52    if (separator != '$')
    2.53      {
    2.54        is.setstate (std::ios_base::failbit);
     3.1 --- a/src/mobility/waypoint.h	Wed Nov 11 00:27:47 2009 +0300
     3.2 +++ b/src/mobility/waypoint.h	Wed Nov 11 11:57:14 2009 +0100
     3.3 @@ -46,15 +46,10 @@
     3.4     * Create a waypoint at time 0 and position (0,0,0).
     3.5     */
     3.6    Waypoint ();
     3.7 -  Time GetTime () const;
     3.8 -  void SetTime (Time time);
     3.9 -  Vector GetPosition () const;
    3.10 -  void SetPosition (Vector vec);
    3.11 -private:
    3.12    /* The waypoint time */
    3.13 -  Time m_time;
    3.14 +  Time time;
    3.15    /* The position of the waypoint */
    3.16 -  Vector m_position;
    3.17 +  Vector position;
    3.18  };
    3.19  
    3.20  /**