diff --git a/TMI-practicum/Program.cs b/TMI-practicum/Program.cs index d28a9d3..29da9eb 100644 --- a/TMI-practicum/Program.cs +++ b/TMI-practicum/Program.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using System.IO; +using System.Linq; namespace TMI_practicum { @@ -18,29 +20,83 @@ namespace TMI_practicum Console.WriteLine("File {0} not found.", args[0]); Environment.Exit(1); } - - Console.WriteLine("HOOOOOOOOOOOIIII"); } - private static void ParseFile(string path) + private static Tuple> ParseFile(string path) { - int algoritme = 0; + byte algoritm = 0; int nbCircles = 0; - + var circles = new List(); + using (StreamReader file = new StreamReader(path)) { - if (!int.TryParse(file.ReadLine(), out algoritme) || !int.TryParse(file.ReadLine(), out nbCircles)) + try { - throw new ArgumentException("An error occured parsing the input file."); - } + algoritm = byte.Parse(file.ReadLine()); + nbCircles = int.Parse(file.ReadLine()); - string line; - while ((line = file.ReadLine()) != null) - { - line.Split(' '); + string line; + while ((line = file.ReadLine()) != null) + { + double[] parts = line.Split(' ').Select(double.Parse).ToArray(); + circles.Add(new Circle(parts[0], parts[1], parts[2])); + } } + catch (Exception) + { + Console.WriteLine("An error occured parsing the input file.\r\n" + + "Make sure the file has all required values and consists only of numbers."); + Environment.Exit(1); + } + } + + return new Tuple>(algoritm, nbCircles, circles); + } + + private static readonly string OutputFile = "output.txt"; + + private static void WriteOutput(IEnumerable intersections, double time) + { + if (File.Exists(OutputFile)) + { + File.Delete(OutputFile); + } + + using (StreamWriter sw = File.CreateText(OutputFile)) + { + foreach (var intersection in intersections) + { + sw.WriteLine("{0}\t{1}", intersection.X, intersection.Y); + } + sw.WriteLine("\r\n{0}", time); + } + } + + private struct Circle + { + public readonly double X; + public readonly double Y; + public readonly double R; + + public Circle(double x, double y, double r) + { + X = x; + Y = y; + R = r; + } + } + + private struct Intersection + { + public readonly double X; + public readonly double Y; + + public Intersection(double x, double y) + { + X = x; + Y = y; } } } diff --git a/TMI-practicum/TMI-practicum.csproj b/TMI-practicum/TMI-practicum.csproj index e64941e..41368d9 100644 --- a/TMI-practicum/TMI-practicum.csproj +++ b/TMI-practicum/TMI-practicum.csproj @@ -37,19 +37,12 @@ - - ..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll - True - - - -