Compare commits

..

5 Commits

5 changed files with 15 additions and 21 deletions

View File

@ -21,8 +21,7 @@ public class Coordinates
if (obj == null || obj.GetType() != this.GetType()) if (obj == null || obj.GetType() != this.GetType())
return false; return false;
Coordinates convObj = (Coordinates)obj; Coordinates convObj = (Coordinates)obj;
// ReSharper disable twice CompareOfFloatsByEqualityOperator static values return convObj.latitude.Equals(this.latitude) && convObj.longitude.Equals(longitude);
return convObj.latitude == this.latitude && convObj.longitude == this.longitude;
} }
public static ulong GetRegionHashCode(float latitude, float longitude) public static ulong GetRegionHashCode(float latitude, float longitude)
@ -49,6 +48,6 @@ public class Coordinates
public override string ToString() public override string ToString()
{ {
return return
$"lat:{latitude.ToString(NumberFormatInfo.InvariantInfo)} lon:{longitude.ToString(CultureInfo.InvariantCulture)}"; $"Coordinates lat:{latitude.ToString(NumberFormatInfo.InvariantInfo)} lon:{longitude.ToString(CultureInfo.InvariantCulture)}";
} }
} }

View File

@ -22,6 +22,6 @@ public class OsmEdge
public override string ToString() public override string ToString()
{ {
return $"w:{wayId} n1:{startId} n2:{neighborId} in r:{neighborRegion}"; return $"Edge wayId:{wayId} n1:{startId} n2:{neighborId} in regionId:{neighborRegion}";
} }
} }

View File

@ -40,6 +40,6 @@ public class OsmNode
public override string ToString() public override string ToString()
{ {
return $"{nodeId} {coordinates} ec:{edges.Count}"; return $"Node id:{nodeId} coordinates:{coordinates} edges-count:{edges.Count}";
} }
} }

View File

@ -18,7 +18,7 @@ public class Tag
switch (key) switch (key)
{ {
case TagType.highway: case TagType.highway:
this.value = (WayType)value.GetByte(); this.value = value.GetByte();
break; break;
case TagType.maxspeed: case TagType.maxspeed:
this.value = value.GetByte(); this.value = value.GetByte();

View File

@ -23,17 +23,13 @@ namespace Pathfinding
public Region? GetRegion(ulong id) public Region? GetRegion(ulong id)
{ {
if (!_regions.ContainsKey(id))
if(_regions.TryGetValue(id, out Region? retRegion)) {
return retRegion; Region? loadedRegion = RegionFromId(id);
if (loadedRegion is not null)
Region? loadedRegion = RegionFromId(id); _regions.TryAdd(loadedRegion.regionHash, loadedRegion);
return _regions[id]; //return from _regions instead of loadedRegion for multithreading/pointers
if(_regions.TryGetValue(id, out Region? retRegion2)) //Prevent other thread from changing collection }
return retRegion2;
if(loadedRegion is not null)
_regions.TryAdd(loadedRegion.regionHash, loadedRegion);
return _regions[id]; return _regions[id];
} }
@ -46,7 +42,7 @@ namespace Pathfinding
{ {
if (!File.Exists(filePath)) if (!File.Exists(filePath))
{ {
throw new FileNotFoundException(filePath); //throw new FileNotFoundException(filePath);
return null; return null;
} }
@ -70,10 +66,9 @@ namespace Pathfinding
public bool TestValidConnectionForType(OsmNode node1, OsmNode node2, SpeedType type) public bool TestValidConnectionForType(OsmNode node1, OsmNode node2, SpeedType type)
{ {
foreach (OsmEdge edge in node1.edges) foreach (OsmEdge edge in node1.edges.Where(edge => edge.neighborId.Equals(node2.nodeId)))
{ {
if (edge.neighborId.Equals(node2.nodeId)) return TestValidConnectionForType(node1, edge, type);
return TestValidConnectionForType(node1, edge, type);
} }
return false; return false;