Cleanup of unnecessary code

This commit is contained in:
glax 2023-04-20 23:02:38 +02:00
parent d456275fc1
commit 2b252e2b06
9 changed files with 20 additions and 31 deletions

View File

@ -1,4 +1,3 @@
using System.Text.Json.Serialization;
using OSMDatastructure;
using OSMDatastructure.Graph;
using Pathfinding;

View File

@ -12,15 +12,15 @@ public class OsmNode
public OsmNode(ulong nodeId, float lat, float lon)
{
this.nodeId = nodeId;
this.edges = new();
this.coordinates = new Coordinates(lat, lon);
edges = new();
coordinates = new Coordinates(lat, lon);
}
[JsonConstructor]
public OsmNode(ulong nodeId, Coordinates coordinates)
{
this.nodeId = nodeId;
this.edges = new();
edges = new();
this.coordinates = coordinates;
}
@ -29,7 +29,8 @@ public class OsmNode
HashSet<OsmEdge> e = edges.Where(edge => edge.neighborId == n.nodeId).ToHashSet();
if (e.Count > 0)
return e.First();
else return null;
return null;
}
public override bool Equals(object? obj)

View File

@ -47,16 +47,12 @@ public class Region
public OsmNode? GetNode(ulong id)
{
if (ContainsNode(id))
return nodes.First(node => node.nodeId == id);
else return null;
return ContainsNode(id) ? nodes.First(node => node.nodeId == id) : null;
}
public OsmNode? GetNode(Coordinates coordinates)
{
if (ContainsNode(coordinates))
return nodes.First(node => node.coordinates.Equals(coordinates));
else return null;
return ContainsNode(coordinates) ? nodes.First(node => node.coordinates.Equals(coordinates)) : null;
}
}

View File

@ -1,5 +1,4 @@
using System.Text.Json.Serialization;
using OSMDatastructure.Graph;
namespace OSMDatastructure;

View File

@ -1,4 +1,3 @@
using System.Diagnostics.Tracing;
using System.Text.Json.Serialization;
using OSMDatastructure;
using OSMDatastructure.Graph;

View File

@ -50,7 +50,7 @@ public class Pathfinder
if (currentNode.Equals(goalNode))
{
Console.WriteLine("Path found.");
this.pathResult = GetPath(goalNode, DateTime.Now - startCalc);
pathResult = GetPath(goalNode, DateTime.Now - startCalc);
return this;
}

View File

@ -23,29 +23,26 @@ namespace Pathfinding
{
if(_regions.TryGetValue(id, out Region? value))
return value;
else
{
Region? loadedRegion = RegionFromId(id);
if(loadedRegion is not null)
_regions.Add(loadedRegion!.regionHash, value: loadedRegion);
return loadedRegion;
}
Region? loadedRegion = RegionFromId(id);
if(loadedRegion is not null)
_regions.Add(loadedRegion!.regionHash, value: loadedRegion);
return loadedRegion;
}
public Region[] GetAllRegions()
{
return this._regions.Values.ToArray();
return _regions.Values.ToArray();
}
private Region? RegionFromFile(string filePath)
{
Region? retRegion = null;
if (File.Exists(filePath))
{
FileStream regionFile = new FileStream(filePath, FileMode.Open);
retRegion = JsonSerializer.Deserialize<Region>(regionFile, Region.serializerOptions)!;
regionFile.Dispose();
}
if (!File.Exists(filePath))
return null;
FileStream regionFile = new (filePath, FileMode.Open);
Region retRegion = JsonSerializer.Deserialize<Region>(regionFile, Region.serializerOptions)!;
regionFile.Dispose();
return retRegion;
}

View File

@ -1,7 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text.Json;
using OSMDatastructure.Graph;
using Pathfinding;

View File

@ -1,4 +1,3 @@
using System.Globalization;
using System.Text;
namespace Server;