From 02e3b1e5a37ee1d9dd31fed282a1ee0b94ad7601 Mon Sep 17 00:00:00 2001 From: glax Date: Wed, 24 Jul 2024 22:09:45 +0200 Subject: [PATCH] Add strings with info every 1 minute of route travelled --- Graph_Renderer/Renderer.cs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Graph_Renderer/Renderer.cs b/Graph_Renderer/Renderer.cs index c5e9fef..86d3f59 100644 --- a/Graph_Renderer/Renderer.cs +++ b/Graph_Renderer/Renderer.cs @@ -16,11 +16,12 @@ public static class Renderer float deltaLat = maxCoordinates.Item1 - minCoordinates.Item1; float deltaLon = maxCoordinates.Item2 - minCoordinates.Item2; float multiplier = deltaLat > deltaLon ? longestEdge / deltaLat : longestEdge / deltaLon; + int width = (int)(deltaLon * multiplier); + int height = (int)(deltaLat * multiplier); - - Bitmap bitmap = new((int)(deltaLon * multiplier), (int)(deltaLat * multiplier), System.Drawing.Imaging.PixelFormat.Format32bppPArgb); + Bitmap bitmap = new(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics graphics = Graphics.FromImage(bitmap); - Pen previous = new (Color.White, 2); + Pen previous = new (Color.LightSeaGreen, 2); using(GraphicsPath capPath = new ()) { // A triangle @@ -50,15 +51,27 @@ public static class Renderer if (r.RouteFound) { - Pen route = new(Color.Red, 2); + Pen route = new(Color.Blue, 4); + TimeSpan previousPrint = TimeSpan.Zero; + float distance = 0; + TimeSpan time = TimeSpan.Zero; foreach (Step step in r.Steps) { Point startCoordinates = PixelCoordinatesFromGeoCoordinates(step.Node1, minCoordinates, multiplier, bitmap.Height); Point endCoordinates = PixelCoordinatesFromGeoCoordinates(step.Node2, minCoordinates, multiplier, bitmap.Height); graphics.DrawLine(route, startCoordinates, endCoordinates); + distance += step.Distance; + time += TimeSpan.FromHours(step.Distance / 1000 / step.Speed); + if (time - previousPrint > TimeSpan.FromSeconds(60)) + { + previousPrint += TimeSpan.FromSeconds(60); + Point printCoordinates = new(endCoordinates.X + 30, endCoordinates.Y + 30); + graphics.DrawLine(route, endCoordinates, printCoordinates); + graphics.DrawString($"{distance:000000}m\n{time:hh\\:mm\\:ss}", new Font(FontFamily.GenericMonospace, 8), new SolidBrush(Color.Blue), printCoordinates); + } } - graphics.DrawString($"Distance: {r.Distance:000000.00}m\nTime: {r.Time:hh\\:mm\\:ss}", new Font(FontFamily.GenericMonospace, 18), new SolidBrush(Color.White), 2, 2); + graphics.DrawString($"Distance: {r.Distance:000000.00}m\nTime: {r.Time:hh\\:mm\\:ss}", new Font(FontFamily.GenericMonospace, 24), new SolidBrush(Color.White), 2, 2); } Directory.CreateDirectory(new FileInfo(outputPath).DirectoryName!);