static void Main(string[] args) { List <Point> points = Data.Array.Select(d => new Point(d[0], d[1])).ToList(); points.Add(points[0]); Console.WriteLine(points.Count().ToString("#,0") + " points"); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); List <Point> reducedPoints = RamerDouglasPeucker.Reduce(points, 0.5f); stopwatch.Stop(); Console.WriteLine("To " + reducedPoints.Count().ToString("#,0") + " points in " + stopwatch.ElapsedMilliseconds + "ms"); Console.WriteLine(); stopwatch = new Stopwatch(); stopwatch.Start(); List <Point> reducedPoints2 = RamerDouglasPeucker.Reduce(points); stopwatch.Stop(); Console.WriteLine("To " + reducedPoints2.Count().ToString("#,0") + " points in " + stopwatch.ElapsedMilliseconds + "ms"); Console.ReadKey(); }
static void Main(string[] args) { Point[] points = File.ReadAllLines(@"D:\Trading\Quantitative\Research\Data\large_random.csv") .Select(line => new Point(DateTime.Parse(line.Split(',')[0].Trim()).ToOADate(), double.Parse(line.Split(',')[1].Trim()))).ToArray(); points = points.Concat(points).ToArray(); points = points.Concat(points).ToArray(); points = points.Concat(points).ToArray(); points = points.Concat(points).ToArray(); points = points.Concat(points).ToArray(); Console.WriteLine(points.Count().ToString("#,0")); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); var reducePoints = RamerDouglasPeucker.Reduce(points, 0.5); stopwatch.Stop(); Console.WriteLine(stopwatch.ElapsedMilliseconds / 1_000.0 + "s"); Console.WriteLine(reducePoints.Count().ToString("#,0")); Console.ReadKey(); //File.WriteAllLines(@"screenpoints_reduced.csv", reducePoints.Select(x => x.X + "," + x.Y)); }
private void Button_LineSimplification_Click(object sender, RoutedEventArgs e) { var simplifier = new RamerDouglasPeucker(5); _mapLocations = simplifier.DouglasPeuckerReduction(_mapLocations); Canvas_Main.Children.Clear(); foreach (var clusterableLocation in _mapLocations) { DrawPoint(clusterableLocation, Colors.Green); } }