Finished parsing
This commit is contained in:
@@ -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<byte, int, ICollection<Circle>> ParseFile(string path)
|
||||
{
|
||||
|
||||
int algoritme = 0;
|
||||
byte algoritm = 0;
|
||||
int nbCircles = 0;
|
||||
|
||||
var circles = new List<Circle>();
|
||||
|
||||
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<byte, int, ICollection<Circle>>(algoritm, nbCircles, circles);
|
||||
}
|
||||
|
||||
private static readonly string OutputFile = "output.txt";
|
||||
|
||||
private static void WriteOutput(IEnumerable<Intersection> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user