Exemplo n.º 1
0
        public static void EnrichWithIntemediatePoints(ICollection <PathData> paths, float pointsStep)
        {
            if (paths == null)
            {
                return;
            }

            var pathList = (List <PathData>)paths;

            for (var i = 0; i < pathList.Count; ++i)
            {
                GpsCoordinate prevPoint = null;

                var enrichedPoints = new List <GpsCoordinate>();

                var pathData = pathList[i];

                foreach (var currentPoint in pathData.Points)
                {
                    if (enrichedPoints.Count > 0)
                    {
                        prevPoint = enrichedPoints[enrichedPoints.Count - 1];
                    }

                    if (prevPoint != null)
                    {
                        var dist = PointUtils.GetDistance(prevPoint, currentPoint);

                        var direction = new GpsCoordinate
                        {
                            x = currentPoint.x - prevPoint.x,
                            y = currentPoint.y - prevPoint.y,
                            z = currentPoint.z - prevPoint.z
                        };

                        if (dist > 0)
                        {
                            var lenMultiplier = pointsStep / dist;

                            direction.x *= lenMultiplier;
                            direction.y *= lenMultiplier;
                            direction.z *= lenMultiplier;
                        }

                        var incrementalPoint = prevPoint;

                        while (dist > pointsStep)
                        {
                            var point = new GpsCoordinate
                            {
                                x = incrementalPoint.x + direction.x,
                                y = incrementalPoint.y + direction.y,
                                z = incrementalPoint.z + direction.z
                            };

                            enrichedPoints.Add(point);

                            incrementalPoint = point;

                            dist -= pointsStep;
                        }

                        enrichedPoints.Add(currentPoint);
                    }
                    else
                    {
                        enrichedPoints.Add(currentPoint);
                    }
                }

                pathData.Points = enrichedPoints;
            }
        }