changed speeds and return type to byte
This commit is contained in:
parent
9448187452
commit
6e836db79b
@ -98,18 +98,19 @@ public class Tag
|
|||||||
|
|
||||||
public static readonly Dictionary<WayType, byte> defaultSpeedCar = new() {
|
public static readonly Dictionary<WayType, byte> defaultSpeedCar = new() {
|
||||||
{ WayType.NONE, 0 },
|
{ WayType.NONE, 0 },
|
||||||
{ WayType.motorway, 110 },
|
{ WayType.motorway, 130 },
|
||||||
{ WayType.trunk, 100 },
|
{ WayType.motorroad, 90 },
|
||||||
|
{ WayType.trunk, 85 },
|
||||||
{ WayType.primary, 80 },
|
{ WayType.primary, 80 },
|
||||||
{ WayType.secondary, 80 },
|
{ WayType.secondary, 80 },
|
||||||
{ WayType.tertiary, 70 },
|
{ WayType.tertiary, 70 },
|
||||||
{ WayType.unclassified, 20 },
|
{ WayType.unclassified, 15 },
|
||||||
{ WayType.residential, 10 },
|
{ WayType.residential, 10 },
|
||||||
{ WayType.motorway_link, 50 },
|
{ WayType.motorway_link, 60 },
|
||||||
{ WayType.trunk_link, 50 },
|
{ WayType.trunk_link, 50 },
|
||||||
{ WayType.primary_link, 30 },
|
{ WayType.primary_link, 50 },
|
||||||
{ WayType.secondary_link, 25 },
|
{ WayType.secondary_link, 50 },
|
||||||
{ WayType.tertiary_link, 25 },
|
{ WayType.tertiary_link, 50 },
|
||||||
{ WayType.living_street, 5 },
|
{ WayType.living_street, 5 },
|
||||||
{ WayType.service, 1 },
|
{ WayType.service, 1 },
|
||||||
{ WayType.pedestrian, 0 },
|
{ WayType.pedestrian, 0 },
|
||||||
@ -160,7 +161,7 @@ public class Tag
|
|||||||
{ WayType.construction, 0 }
|
{ WayType.construction, 0 }
|
||||||
};
|
};
|
||||||
// ReSharper disable InconsistentNaming
|
// ReSharper disable InconsistentNaming
|
||||||
public enum WayType : byte { NONE, motorway, trunk, primary, secondary, tertiary, unclassified, residential, motorway_link, trunk_link, primary_link, secondary_link, tertiary_link, living_street, service, pedestrian, track, bus_guideway, escape, raceway, road, busway, footway, bridleway, steps, corridor, path, cycleway, construction }
|
public enum WayType : byte { NONE, motorway, motorroad, trunk, primary, secondary, tertiary, unclassified, residential, motorway_link, trunk_link, primary_link, secondary_link, tertiary_link, living_street, service, pedestrian, track, bus_guideway, escape, raceway, road, busway, footway, bridleway, steps, corridor, path, cycleway, construction }
|
||||||
// ReSharper restore InconsistentNaming
|
// ReSharper restore InconsistentNaming
|
||||||
|
|
||||||
public enum SpeedType { pedestrian, car, any }
|
public enum SpeedType { pedestrian, car, any }
|
||||||
|
@ -25,10 +25,8 @@ public static partial class Pathfinder
|
|||||||
if (node2 is null)
|
if (node2 is null)
|
||||||
return double.MaxValue;
|
return double.MaxValue;
|
||||||
double distance = Utils.DistanceBetween(node1, node2);
|
double distance = Utils.DistanceBetween(node1, node2);
|
||||||
double speed = regionManager.GetSpeedForEdge(node1, edge.wayId, vehicle);
|
byte speed = regionManager.GetSpeedForEdge(node1, edge.wayId, vehicle);
|
||||||
if (speed is 0)
|
return speed is 0 ? double.MaxValue : distance / speed;
|
||||||
return double.MaxValue;
|
|
||||||
return distance / speed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<PathNode> GetRouteFromCalc(OsmNode goalNode, RegionManager regionManager)
|
private static List<PathNode> GetRouteFromCalc(OsmNode goalNode, RegionManager regionManager)
|
||||||
|
@ -76,10 +76,8 @@ namespace Pathfinding
|
|||||||
{
|
{
|
||||||
if (type == Tag.SpeedType.any)
|
if (type == Tag.SpeedType.any)
|
||||||
return true;
|
return true;
|
||||||
double speed = GetSpeedForEdge(node1, edge.wayId, type);
|
byte speed = GetSpeedForEdge(node1, edge.wayId, type);
|
||||||
if (speed != 0)
|
return (speed is not 0);
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public OsmNode? ClosestNodeToCoordinates(Coordinates coordinates, Tag.SpeedType vehicle)
|
public OsmNode? ClosestNodeToCoordinates(Coordinates coordinates, Tag.SpeedType vehicle)
|
||||||
@ -97,7 +95,7 @@ namespace Pathfinding
|
|||||||
hasConnectionUsingVehicle = false;
|
hasConnectionUsingVehicle = false;
|
||||||
foreach (OsmEdge edge in node.edges)
|
foreach (OsmEdge edge in node.edges)
|
||||||
{
|
{
|
||||||
double speed = GetSpeedForEdge(node, edge.wayId, vehicle);
|
byte speed = GetSpeedForEdge(node, edge.wayId, vehicle);
|
||||||
if (speed != 0)
|
if (speed != 0)
|
||||||
hasConnectionUsingVehicle = true;
|
hasConnectionUsingVehicle = true;
|
||||||
}
|
}
|
||||||
@ -114,25 +112,20 @@ namespace Pathfinding
|
|||||||
return closest;
|
return closest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double GetSpeedForEdge(OsmNode node1, ulong wayId, Tag.SpeedType vehicle)
|
public byte GetSpeedForEdge(OsmNode node1, ulong wayId, Tag.SpeedType vehicle)
|
||||||
{
|
{
|
||||||
TagManager tags = GetRegion(node1.coordinates)!.tagManager;
|
TagManager tags = GetRegion(node1.coordinates)!.tagManager;
|
||||||
Tag.WayType wayType = (Tag.WayType)tags.GetTag(wayId, Tag.TagType.highway)!;
|
Tag.WayType wayType = (Tag.WayType)tags.GetTag(wayId, Tag.TagType.highway)!;
|
||||||
|
byte speed = 0;
|
||||||
switch (vehicle)
|
switch (vehicle)
|
||||||
{
|
{
|
||||||
case Tag.SpeedType.pedestrian:
|
case Tag.SpeedType.pedestrian:
|
||||||
byte speed = Tag.defaultSpeedPedestrian[wayType];
|
speed = Tag.defaultSpeedPedestrian[wayType];
|
||||||
if (speed is not 0)
|
return speed is not 0 ? speed : (byte)0;
|
||||||
return speed;
|
|
||||||
return 0;
|
|
||||||
case Tag.SpeedType.car:
|
case Tag.SpeedType.car:
|
||||||
byte? maxSpeed = (byte?)tags.GetTag(wayId, Tag.TagType.maxspeed);
|
byte? maxSpeed = (byte?)tags.GetTag(wayId, Tag.TagType.maxspeed);
|
||||||
if (maxSpeed is not null)
|
speed = Tag.defaultSpeedCar[wayType];
|
||||||
return (double)maxSpeed;
|
return maxSpeed < speed ? (byte)maxSpeed : speed;
|
||||||
maxSpeed = Tag.defaultSpeedCar[wayType];
|
|
||||||
if(maxSpeed is not 0)
|
|
||||||
return (byte)maxSpeed;
|
|
||||||
return 0;
|
|
||||||
case Tag.SpeedType.any:
|
case Tag.SpeedType.any:
|
||||||
return 1;
|
return 1;
|
||||||
default:
|
default:
|
||||||
|
Reference in New Issue
Block a user