コード例 #1
0
        public void Split()
        {
            firstSubSegment  = new ReduceSegment(Points.Take(maxDistanceIndex + 1).ToArray());
            secondSubSegment = new ReduceSegment(Points.Skip(maxDistanceIndex).ToArray());

            Splitted = true;
        }
コード例 #2
0
        private List <TrackPoint> GetPoints(ReduceSegment segment)
        {
            var points = new List <TrackPoint>();

            if (!segment.Splitted)
            {
                return(points);
            }

            points.AddRange(GetPoints(segment.firstSubSegment));
            points.Add(segment.maxDistancePoint);
            points.AddRange(GetPoints(segment.secondSubSegment));

            return(points);
        }
コード例 #3
0
        private ReduceSegment FindSegmentWithMaxDistance(ReduceSegment segment)
        {
            if (!segment.Splitted)
            {
                return(segment);
            }

            var firstSegment  = FindSegmentWithMaxDistance(segment.firstSubSegment);
            var secondSegment = FindSegmentWithMaxDistance(segment.secondSubSegment);

            if (firstSegment.maxDistance >= secondSegment.maxDistance)
            {
                return(firstSegment);
            }

            return(secondSegment);
        }
コード例 #4
0
        public TrackPoint[] Process(TrackPoint[] points)
        {
            List <TrackPoint> result = new List <TrackPoint>();

            if (points.Length <= MaxNrOfPoints)
            {
                return(points);
            }

            var rootSegment = new ReduceSegment(points);

            for (var i = 0; i < MaxNrOfPoints; i++)
            {
                var segment = FindSegmentWithMaxDistance(rootSegment);

                segment.Split();
            }

            result.Add(rootSegment.Points.First());
            result.AddRange(GetPoints(rootSegment));
            result.Add(rootSegment.Points.Last());

            return(result.ToArray());
        }