Made speedtype any generic.
Will use any connection (highway), and return the same speed for all highways.
This commit is contained in:
parent
d8f8a41dcc
commit
0f53ae579c
@ -37,7 +37,7 @@ app.MapGet("/getRouteTime", (float latStart, float lonStart, float latEnd, float
|
||||
app.MapGet("/getClosestNode", (float lat, float lon) =>
|
||||
{
|
||||
RegionManager regionManager = new RegionManager("D:/stuttgart-regbez-latest");
|
||||
return regionManager.ClosestNodeToCoordinates(new Coordinates(lat, lon), Tag.SpeedType.road);
|
||||
return regionManager.ClosestNodeToCoordinates(new Coordinates(lat, lon), Tag.SpeedType.any);
|
||||
});
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
|
@ -163,5 +163,5 @@ public class Tag
|
||||
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 }
|
||||
// ReSharper restore InconsistentNaming
|
||||
|
||||
public enum SpeedType { pedestrian, car, road }
|
||||
public enum SpeedType { pedestrian, car, any }
|
||||
}
|
@ -9,8 +9,8 @@ public static partial class Pathfinder
|
||||
private static ValueTuple<OsmNode?, OsmNode?> SetupNodes(Coordinates startCoordinates, Coordinates goalCoordinates, RegionManager regionManager )
|
||||
{
|
||||
ValueTuple<OsmNode?, OsmNode?> retTuple = new();
|
||||
retTuple.Item1 = regionManager.ClosestNodeToCoordinates(startCoordinates, Tag.SpeedType.road);
|
||||
retTuple.Item2 = regionManager.ClosestNodeToCoordinates(goalCoordinates, Tag.SpeedType.road);
|
||||
retTuple.Item1 = regionManager.ClosestNodeToCoordinates(startCoordinates, Tag.SpeedType.any);
|
||||
retTuple.Item2 = regionManager.ClosestNodeToCoordinates(goalCoordinates, Tag.SpeedType.any);
|
||||
if (retTuple.Item1 is null || retTuple.Item2 is null)
|
||||
return retTuple;
|
||||
retTuple.Item1.currentPathWeight = 0;
|
||||
|
@ -74,6 +74,8 @@ namespace Pathfinding
|
||||
|
||||
public bool TestValidConnectionForType(OsmNode node1, OsmEdge edge, Tag.SpeedType type)
|
||||
{
|
||||
if (type == Tag.SpeedType.any)
|
||||
return true;
|
||||
double speed = GetSpeedForEdge(node1, edge.wayId, type);
|
||||
if (speed != 0)
|
||||
return true;
|
||||
@ -89,13 +91,18 @@ namespace Pathfinding
|
||||
return null;
|
||||
foreach (OsmNode node in region.nodes)
|
||||
{
|
||||
bool hasConnectionUsingVehicle = false;
|
||||
foreach (OsmEdge edge in node.edges)
|
||||
bool hasConnectionUsingVehicle = true;
|
||||
if (vehicle is not Tag.SpeedType.any)
|
||||
{
|
||||
double speed = GetSpeedForEdge(node, edge.wayId, vehicle);
|
||||
if (speed != 0)
|
||||
hasConnectionUsingVehicle = true;
|
||||
hasConnectionUsingVehicle = false;
|
||||
foreach (OsmEdge edge in node.edges)
|
||||
{
|
||||
double speed = GetSpeedForEdge(node, edge.wayId, vehicle);
|
||||
if (speed != 0)
|
||||
hasConnectionUsingVehicle = true;
|
||||
}
|
||||
}
|
||||
|
||||
double nodeDistance = Utils.DistanceBetween(node, coordinates);
|
||||
if (nodeDistance < distance && hasConnectionUsingVehicle)
|
||||
{
|
||||
@ -119,7 +126,6 @@ namespace Pathfinding
|
||||
return speed;
|
||||
return 0;
|
||||
case Tag.SpeedType.car:
|
||||
case Tag.SpeedType.road:
|
||||
byte? maxSpeed = (byte?)tags.GetTag(wayId, Tag.TagType.maxspeed);
|
||||
if (maxSpeed is not null)
|
||||
return (double)maxSpeed;
|
||||
@ -127,6 +133,8 @@ namespace Pathfinding
|
||||
if(maxSpeed is not 0)
|
||||
return (byte)maxSpeed;
|
||||
return 0;
|
||||
case Tag.SpeedType.any:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user