Compare commits

..

No commits in common. "56ac9dc948d89043e83af9ab48cdf1123f29e7f9" and "e53d1086cc9d2afd08b34a0be0d11a8dea165b76" have entirely different histories.

5 changed files with 21 additions and 15 deletions

View File

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

View File

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

View File

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

View File

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

View File

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