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())
return false;
Coordinates convObj = (Coordinates)obj;
// ReSharper disable twice CompareOfFloatsByEqualityOperator static values
return convObj.latitude == this.latitude && convObj.longitude == this.longitude;
return convObj.latitude.Equals(this.latitude) && convObj.longitude.Equals(longitude);
}
public static ulong GetRegionHashCode(float latitude, float longitude)
@ -49,6 +48,6 @@ public class Coordinates
public override string ToString()
{
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()
{
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()
{
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)
{
case TagType.highway:
this.value = (WayType)value.GetByte();
this.value = value.GetByte();
break;
case TagType.maxspeed:
this.value = value.GetByte();

View File

@ -23,17 +23,13 @@ namespace Pathfinding
public Region? GetRegion(ulong id)
{
if(_regions.TryGetValue(id, out Region? retRegion))
return retRegion;
if (!_regions.ContainsKey(id))
{
Region? loadedRegion = RegionFromId(id);
if(_regions.TryGetValue(id, out Region? retRegion2)) //Prevent other thread from changing collection
return retRegion2;
if(loadedRegion is not null)
if (loadedRegion is not null)
_regions.TryAdd(loadedRegion.regionHash, loadedRegion);
return _regions[id]; //return from _regions instead of loadedRegion for multithreading/pointers
}
return _regions[id];
}
@ -46,7 +42,7 @@ namespace Pathfinding
{
if (!File.Exists(filePath))
{
throw new FileNotFoundException(filePath);
//throw new FileNotFoundException(filePath);
return null;
}
@ -70,9 +66,8 @@ namespace Pathfinding
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);
}