diff options
Diffstat (limited to 'src/CS340.Plotter/TourPlot.cs')
-rw-r--r-- | src/CS340.Plotter/TourPlot.cs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/CS340.Plotter/TourPlot.cs b/src/CS340.Plotter/TourPlot.cs index 09cd514..a5d9f30 100644 --- a/src/CS340.Plotter/TourPlot.cs +++ b/src/CS340.Plotter/TourPlot.cs @@ -1,5 +1,6 @@ using System; using System.Drawing; +using System.IO; using System.Linq; using System.Windows.Forms; using TSP; @@ -13,7 +14,7 @@ namespace Plotter public PictureBox Canvas { get; set; } public Label WeightLabel { get; set; } public Label RuntimeLabel { get; set; } - public TimeSpan RunTime { get; set; } + public TimeSpan Runtime { get; set; } public TourPlot(string graphName, PictureBox canvas, Label weightLabel, Label runtimeLabel) { @@ -26,8 +27,11 @@ namespace Plotter public void Save(string filename) => Save(filename, Canvas.Width, Canvas.Height); - public void Save(string filename, int width, int height) => - Draw(300, 300).Save(filename); + public void Save(string filename, int width, int height) + { + Draw(300, 300).Save($"{filename}.png"); + File.WriteAllText($"{filename}.txt", $"{this}"); + } public void Render() { @@ -39,14 +43,14 @@ namespace Plotter // 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); + Runtime.Hours, Runtime.Minutes, Runtime.Seconds, Runtime.Milliseconds / 10); WeightLabel.Text = Tour.Weight.ToString("F3"); } public Bitmap Draw(int width, int height) { - const int Scaler = 25; + const int Offset = 25; const int PlotSize = 100; using Bitmap bmp = new(width, height); @@ -95,12 +99,15 @@ namespace Plotter // helper function to unify the scaling of images Point ScaleLocation(Coordinate coordinate) { - int x = width * (coordinate.X + Scaler / 2) / (Scaler + PlotSize); - int y = height * ((coordinate.Y - PlotSize) * -1 + Scaler / 2) / (Scaler + PlotSize); + int x = width * (coordinate.X + Offset / 2) / (Offset + PlotSize); + int y = height * ((coordinate.Y - PlotSize) * -1 + Offset / 2) / (Offset + PlotSize); return new Point(x, y); } + } + public override string ToString() => $"{Tour}\n" + + $"runtime: {Runtime}"; } } |