/// <summary>
        ///     Records the current value
        /// </summary>
        /// <param name="currentPosition"></param>
        /// <param name="relocatedPosition"></param>
        public virtual void RecordCurrentValue(double currentPosition, double relocatedPosition)
        {
            SpeedDistancePoint currentPoint = GetValue(relocatedPosition);

            if (currentPoint != null)
            {
                PreviousData.Add(new SpeedDistancePoint(currentPosition, currentPoint.Speed));
            }
        }
        /// <summary>
        ///     Computes the function value according to the provided parameter
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        protected override SpeedDistancePoint GetValue(double parameter)
        {
            SpeedDistancePoint retVal = null;

            if (Function != null)
            {
                retVal = new SpeedDistancePoint(parameter, Function.Evaluate(parameter));
            }

            return retVal;
        }
        /// <summary>
        ///     Computes the function value according to the provided parameter
        /// </summary>
        /// <param name="parameter"></param>
        /// <returns></returns>
        protected override SpeedDistancePoint GetValue(double parameter)
        {
            SpeedDistancePoint retVal = null;

            if (Function != null)
            {
                retVal = new SpeedDistancePoint(parameter, Function.Evaluate(parameter));
            }

            return(retVal);
        }
 /// <summary>
 /// Adds a new point
 /// </summary>
 /// <param name="point"></param>
 protected override void AddPoint(SpeedDistancePoint point)
 {
     DataPoint newPoint = new DataPoint(point.Distance, point.Speed);
     if (Data.Points.Count > 0 && Data.Points[Data.Points.Count - 1].XValue == point.Distance)
     {
         Data.Points[Data.Points.Count - 1] = newPoint;
     }
     else
     {
         Data.Points.Add(newPoint);
     }
 }
Beispiel #5
0
        /// <summary>
        /// Displays the previously recorded data
        /// </summary>
        /// <returns></returns>
        protected SpeedDistancePoint DisplayPreviousData()
        {
            SpeedDistancePoint retVal = new SpeedDistancePoint(0, 0);

            foreach (SpeedDistancePoint point in Function.PreviousData.Points)
            {
                AddPoint(point);
                retVal.Distance = point.Distance;
                retVal.Speed    = point.Speed;
            }
            return(retVal);
        }
        /// <summary>
        ///     Adds a new point
        /// </summary>
        /// <param name="point"></param>
        protected override void AddPoint(SpeedDistancePoint point)
        {
            DataPoint newPoint = new DataPoint(point.Distance, point.Speed);

            if (Data.Points.Count > 0 && Data.Points[Data.Points.Count - 1].XValue == point.Distance)
            {
                Data.Points[Data.Points.Count - 1] = newPoint;
            }
            else
            {
                Data.Points.Add(newPoint);
            }
        }
        /// <summary>
        /// Displays the provided function
        /// </summary>
        /// <param name="graph"></param>
        /// <param name="maxDistance"></param>
        /// <param name="startingPoint"></param>
        private void DisplayGraph(IGraph graph, double maxDistance, SpeedDistancePoint startingPoint)
        {
            if (graph != null)
            {
                if (startingPoint != null)
                {
                    for (int i = 0; i < graph.CountSegments(); i++)
                    {
                        ISegment segment = graph.GetSegment(i);
                        if (segment.D0 <= maxDistance &&
                            (segment.D0 >= startingPoint.Distance ||
                             (segment.Length == double.MaxValue || segment.D0 + segment.Length > startingPoint.Distance)))
                        {
                            double startLocation = Math.Max(startingPoint.Distance, segment.D0);
                            double endLocation   = maxDistance;
                            if (!double.IsNaN(segment.Length))
                            {
                                endLocation = Math.Min(segment.D0 + segment.Length, endLocation);
                            }

                            if (segment.A == 0) // this is a flat segment
                            {
                                AddPoint(new DataPoint(startLocation, segment.V0));
                                AddPoint(new DataPoint(endLocation, segment.V0));
                            }
                            else // this is a curve
                            {
                                double distanceInterval = (endLocation - startLocation) /
                                                          GraphVisualizer.DecelerationCurvePrecision;
                                double distance = startLocation;
                                for (int j = 0; j < GraphVisualizer.DecelerationCurvePrecision; j++)
                                {
                                    AddDataPoint(distance, segment);
                                    distance += distanceInterval;
                                }
                                AddDataPoint(distance, segment);
                            }
                        }
                    }

                    // This empty data point is added in order to allow displaying several
                    // deceleration curves without linking the end of the previous curve
                    // with the start of the following curve

                    DataPoint dataPoint = new DataPoint(0, 0);
                    dataPoint.IsEmpty = true;
                    AddPoint(dataPoint);
                }
            }
        }
Beispiel #8
0
        /// <summary>
        ///     Displays the previously recorded data until the provided distance
        /// </summary>
        /// <param name="maxDistance"></param>
        /// <returns></returns>
        protected SpeedDistancePoint DisplayPreviousData(double maxDistance)
        {
            SpeedDistancePoint        retVal = new SpeedDistancePoint(0, 0);
            List <SpeedDistancePoint> tmp    = new List <SpeedDistancePoint>(Function.PreviousData.Points);

            foreach (SpeedDistancePoint point in tmp)
            {
                if (point.Distance <= maxDistance)
                {
                    AddPoint(point);
                    retVal.Distance = point.Distance;
                    retVal.Speed    = point.Speed;
                }
            }
            return(retVal);
        }
        /// <summary>
        ///     Handles the display
        /// </summary>
        /// <param name="maxDistance"></param>
        /// <param name="minDistance"></param>
        /// <param name="height"></param>
        protected override void HandleDisplay(double maxDistance, double minDistance, double height)
        {
            ProfileSetFunction profileSetFunction = Function as ProfileSetFunction;

            if (profileSetFunction != null && profileSetFunction.Functions.Count > 0)
            {
                ClearData();
                SpeedDistancePoint startingPoint = DisplayPreviousData(maxDistance);
                foreach (IGraph graph in profileSetFunction.Functions)
                {
                    DisplayGraph(graph, maxDistance, startingPoint);
                }
            }
            else
            {
                ProfileFunction profileFunction = Function as ProfileFunction;
                if (profileFunction != null && profileFunction.Function != null)
                {
                    ClearData();
                    SpeedDistancePoint startingPoint = DisplayPreviousData(maxDistance);
                    DisplayGraph(profileFunction.Function, maxDistance, startingPoint);
                }
            }
        }
        /// <summary>
        /// Displays the provided function
        /// </summary>
        /// <param name="graph"></param>
        /// <param name="maxDistance"></param>
        /// <param name="startingPoint"></param>
        private void DisplayGraph(IGraph graph, double maxDistance, SpeedDistancePoint startingPoint)
        {
            if (graph != null && startingPoint != null)
            {
                // This empty data point is added in order to allow displaying several
                // deceleration curves without linking the end of the previous curve
                // with the start of the following curve

                DataPoint dataPoint = new DataPoint(0, 0);
                for (int i = 0; i < graph.CountSegments(); i++)
                {
                    ISegment segment = graph.GetSegment(i);
                    if (segment.D0 <= maxDistance && (segment.D0 >= startingPoint.Distance || (segment.Length == double.MaxValue || segment.D0 + segment.Length > startingPoint.Distance)))
                    {
                        double startLocation = Math.Max(startingPoint.Distance, segment.D0);
                        double endLocation = maxDistance;
                        if (!double.IsNaN(segment.Length))
                        {
                            endLocation = Math.Min(segment.D0 + segment.Length, endLocation);
                        }

                        if (segment.A == 0) // this is a flat segment
                        {
                            AddPoint(new DataPoint(startLocation, segment.V0));
                            AddPoint(new DataPoint(endLocation, segment.V0));
                        }
                        else // this is a curve
                        {
                            double distanceInterval = (endLocation - startLocation) /
                                                      GraphVisualizer.DecelerationCurvePrecision;
                            double distance = startLocation;
                            for (int j = 0; j < GraphVisualizer.DecelerationCurvePrecision; j++)
                            {
                                AddDataPoint(distance, segment);
                                distance += distanceInterval;
                            }
                            AddDataPoint(distance, segment);
                        }
                    }
                }
                dataPoint = new DataPoint(0, 0);
                dataPoint.IsEmpty = true;
                AddPoint(dataPoint);
            }
        }
Beispiel #11
0
 /// <summary>
 /// Adds a new point
 /// </summary>
 /// <param name="point"></param>
 protected virtual void AddPoint(SpeedDistancePoint point)
 {
     Data.Points.Add(new DataPoint(point.Distance, point.Speed));
 }
 /// <summary>
 ///     Constructor
 /// </summary>
 public PointFunction()
 {
     Point = new SpeedDistancePoint();
     SimulatedValues = new List<SpeedDistanceProfile>();
 }
Beispiel #13
0
 /// <summary>
 /// Displays the previously recorded data until the provided distance
 /// </summary>
 /// <param name="maxDistance"></param>
 /// <returns></returns>
 protected SpeedDistancePoint DisplayPreviousData(double maxDistance)
 {
     SpeedDistancePoint retVal = new SpeedDistancePoint(0, 0);
     List<SpeedDistancePoint> tmp = new List<SpeedDistancePoint>(Function.PreviousData.Points);
     foreach (SpeedDistancePoint point in tmp)
     {
         if (point.Distance <= maxDistance)
         {
             AddPoint(point);
             retVal.Distance = point.Distance;
             retVal.Speed = point.Speed;
         }
     }
     return retVal;
 }
Beispiel #14
0
 /// <summary>
 ///     Clears the data related to that function
 /// </summary>
 public override void ClearData()
 {
     base.ClearData();
     Point           = new SpeedDistancePoint();
     SimulatedValues = new List <SpeedDistanceProfile>();
 }
Beispiel #15
0
 /// <summary>
 ///     Constructor
 /// </summary>
 public PointFunction()
 {
     Point           = new SpeedDistancePoint();
     SimulatedValues = new List <SpeedDistanceProfile>();
 }
 /// <summary>
 /// Adds a new point
 /// </summary>
 /// <param name="point"></param>
 protected virtual void AddPoint(SpeedDistancePoint point)
 {
     Data.Points.Add(new DataPoint(point.Distance, point.Speed));
 }
 /// <summary>
 /// Displays the previously recorded data
 /// </summary>
 /// <returns></returns>
 protected SpeedDistancePoint DisplayPreviousData()
 {
     SpeedDistancePoint retVal = new SpeedDistancePoint(0, 0);
     foreach (SpeedDistancePoint point in Function.PreviousData.Points)
     {
         AddPoint(point);
         retVal.Distance = point.Distance;
         retVal.Speed = point.Speed;
     }
     return retVal;
 }
 /// <summary>
 ///     Clears the data related to that function
 /// </summary>
 public override void ClearData()
 {
     base.ClearData();
     Point = new SpeedDistancePoint();
     SimulatedValues = new List<SpeedDistanceProfile>();
 }