Пример #1
0
        public CutRouteData Cut(ParameterizedLocation parameterizedLocation, CutType cutType)
        {
            var cutRoute = new CutRouteData { CutType = cutType };
              switch (cutType)
              {
            case CutType.Before:
              cutRoute.Segments.AddRange(segments.GetRange(0, parameterizedLocation.SegmentIndex));
              if (!parameterizedLocation.IsNode)
              {
            // cut between two waypoints: create cut waypoint
            Waypoint cutWaypoint = CreateWaypointFromParameterizedLocation(parameterizedLocation);
            var rs = new RouteSegment();
            segments.RemoveRange(0, parameterizedLocation.SegmentIndex);
            rs.Waypoints.AddRange(segments[0].Waypoints.GetRange(0, (int)parameterizedLocation.Ceiling().Value));
            cutRoute.Segments.Add(rs);
            segments[0].Waypoints.RemoveRange(0, (int)parameterizedLocation.Ceiling().Value);
            segments[0].Waypoints.Insert(0, cutWaypoint);
            cutRoute.WaypointInsertedAtCut = cutWaypoint;
              }
              else
              {
            // cut exactly at a waypoint
            var rs = new RouteSegment();
            segments.RemoveRange(0, parameterizedLocation.SegmentIndex);
            rs.Waypoints.AddRange(segments[0].Waypoints.GetRange(0, (int)parameterizedLocation.Value));
            cutRoute.Segments.Add(rs);
            segments[0].Waypoints.RemoveRange(0, (int)parameterizedLocation.Value);
              }
              // handle map readings nicely
              if (waypointAttributeExists[WaypointAttribute.MapReadingDuration] &&
             segments[0].FirstWaypoint.MapReadingState == MapReadingState.Reading)
              {
            segments[0].FirstWaypoint.MapReadingState = MapReadingState.StartReading;
              }
              break;

            case CutType.After:
              if (parameterizedLocation.SegmentIndex < segments.Count - 1)
              {
            cutRoute.Segments.AddRange(segments.GetRange(parameterizedLocation.SegmentIndex + 1,
                                                         segments.Count - 1 - parameterizedLocation.SegmentIndex));
            segments.RemoveRange(parameterizedLocation.SegmentIndex + 1,
                                 segments.Count - 1 - parameterizedLocation.SegmentIndex);
              }
              var i = (int)parameterizedLocation.Ceiling().Value;
              int count = segments[parameterizedLocation.SegmentIndex].Waypoints.Count;
              if (!parameterizedLocation.IsNode)
              {
            // cut between two waypoints: create cut waypoint
            Waypoint cutWaypoint = CreateWaypointFromParameterizedLocation(parameterizedLocation);
            var rs = new RouteSegment();
            rs.Waypoints.AddRange(segments[parameterizedLocation.SegmentIndex].Waypoints.GetRange(i, count - i));
            cutRoute.Segments.Insert(0, rs);
            segments[parameterizedLocation.SegmentIndex].Waypoints.RemoveRange(i, count - i);
            segments[parameterizedLocation.SegmentIndex].Waypoints.Insert(i, cutWaypoint);
            cutRoute.WaypointInsertedAtCut = cutWaypoint;
              }
              else
              {
            // cut exactly at a waypoint
            var rs = new RouteSegment();
            rs.Waypoints.AddRange(segments[parameterizedLocation.SegmentIndex].Waypoints.GetRange(i + 1, count - 1 - i));
            cutRoute.Segments.Insert(0, rs);
            segments[parameterizedLocation.SegmentIndex].Waypoints.RemoveRange(i + 1, count - 1 - i);
              }
              // handle map readings nicely
              var lastWaypoint = segments[segments.Count - 1].LastWaypoint;
              if (waypointAttributeExists[WaypointAttribute.MapReadingDuration] &&
             lastWaypoint.MapReadingState == MapReadingState.Reading)
              {
            lastWaypoint.MapReadingState = MapReadingState.EndReading;
              }
              break;
              }
              return cutRoute;
        }
Пример #2
0
 public ParameterizedLocation GetNextPLNode(ParameterizedLocation pl, ParameterizedLocation.Direction direction)
 {
     if (direction == ParameterizedLocation.Direction.Forward)
       {
     if (pl.Floor().Value + 1 > segments[pl.SegmentIndex].Waypoints.Count - 1)
     {
       if (pl.SegmentIndex + 1 > segments.Count - 1) return null;
       return new ParameterizedLocation(pl.SegmentIndex + 1, 0);
     }
     return new ParameterizedLocation(pl.SegmentIndex, pl.Floor().Value + 1);
       }
       else
       {
     if (pl.Ceiling().Value - 1 < 0)
     {
       if (pl.SegmentIndex <= 0) return null;
       return new ParameterizedLocation(pl.SegmentIndex - 1, segments[pl.SegmentIndex - 1].Waypoints.Count - 1);
     }
     return new ParameterizedLocation(pl.SegmentIndex, pl.Ceiling().Value - 1);
       }
 }
Пример #3
0
 private ParameterizedLocation GetParameterizedLocationOfNextWaypoint(ParameterizedLocation parameterizedLocation,
     bool forceAdvance)
 {
     if (!parameterizedLocation.IsNode)
       {
     return new ParameterizedLocation(parameterizedLocation.SegmentIndex, parameterizedLocation.Ceiling().Value);
       }
       else if (parameterizedLocation.Value < segments[parameterizedLocation.SegmentIndex].Waypoints.Count - 1)
       {
     return new ParameterizedLocation(parameterizedLocation.SegmentIndex,
                                  parameterizedLocation.Value + (forceAdvance ? 1 : 0));
       }
       else if (forceAdvance && parameterizedLocation.SegmentIndex < segments.Count - 1)
       {
     return new ParameterizedLocation(parameterizedLocation.SegmentIndex + 1, 0);
       }
       else
       {
     return new ParameterizedLocation(parameterizedLocation.SegmentIndex,
                                  segments[parameterizedLocation.SegmentIndex].Waypoints.Count - 1);
       }
 }