summaryrefslogtreecommitdiffstats
path: root/src/CS340.Plotter/TourPlot.cs
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2021-04-23 17:06:43 -0500
committerToby Vincent <tobyv13@gmail.com>2021-04-23 17:06:43 -0500
commit9af3c3f53beb82efe1e690d45852a79238ac11df (patch)
tree877d9afe07e05b0d6523a15ede352a7599b3692c /src/CS340.Plotter/TourPlot.cs
parent66ecdbf20f2a29af26e4bfefb255e7fbe1061eac (diff)
implimented saving graphs
Diffstat (limited to 'src/CS340.Plotter/TourPlot.cs')
-rw-r--r--src/CS340.Plotter/TourPlot.cs21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/CS340.Plotter/TourPlot.cs b/src/CS340.Plotter/TourPlot.cs
index 7c03957..30d0f2a 100644
--- a/src/CS340.Plotter/TourPlot.cs
+++ b/src/CS340.Plotter/TourPlot.cs
@@ -24,7 +24,9 @@ namespace Plotter
public void Render()
{
- const int Scaler = 125;
+ const int Scaler = 25;
+ const int PlotSize = 100;
+
using Bitmap bmp = new(Canvas.Width, Canvas.Height);
using Graphics gfx = Graphics.FromImage(bmp);
using Pen pen = new(Color.Black);
@@ -54,6 +56,7 @@ namespace Plotter
gfx.DrawString(i.ToString(), gridFont, brush, bottom, stringFormat);
}
+ // iterate through each city and draw line from Location to parent.Location
foreach (City city in Tour.Cities.Where(city => city.Parent != -1))
{
City parent = Tour[city.Parent];
@@ -69,27 +72,23 @@ namespace Plotter
Canvas.Image?.Dispose();
Canvas.Image = (Bitmap)bmp.Clone();
+ // set runtime and weight labels
RuntimeLabel.Text = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
RunTime.Hours, RunTime.Minutes, RunTime.Seconds, RunTime.Milliseconds / 10);
WeightLabel.Text = Tour.Weight.ToString("F3");
+ // helper function to unify the scaling of images
Point ScaleLocation(Coordinate coordinate)
{
- int x = Canvas.Width * (coordinate.X + 12) / Scaler;
- int y = Canvas.Height * ((coordinate.Y - 100) * -1 + 12) / Scaler;
+ int x = Canvas.Width * (coordinate.X + Scaler / 2) / (Scaler + PlotSize);
+ int y = Canvas.Height * ((coordinate.Y - PlotSize) * -1 + Scaler / 2) / (Scaler + PlotSize);
return new Point(x, y);
}
}
- public void WriteDebug()
- {
- Debug.WriteLine(Tour);
-
- foreach (City city in Tour.Cities)
- Debug.WriteLine(city.Location);
- }
-
+ public void Save(string filename) =>
+ Canvas.Image.Save(filename);
}
}