fix routing exception if origin and destination can be directly connected
This commit is contained in:
parent
f8e6e69b0f
commit
8394521800
3 changed files with 23 additions and 1 deletions
|
@ -11,9 +11,10 @@ from scipy.sparse.csgraph._tools import csgraph_from_dense
|
||||||
from c3nav.mapdata.models import Elevator, Level
|
from c3nav.mapdata.models import Elevator, Level
|
||||||
from c3nav.mapdata.models.geometry import LevelConnector
|
from c3nav.mapdata.models.geometry import LevelConnector
|
||||||
from c3nav.mapdata.models.locations import AreaLocation, Location, LocationGroup, PointLocation
|
from c3nav.mapdata.models.locations import AreaLocation, Location, LocationGroup, PointLocation
|
||||||
|
from c3nav.routing.connection import GraphConnection
|
||||||
from c3nav.routing.level import GraphLevel
|
from c3nav.routing.level import GraphLevel
|
||||||
from c3nav.routing.point import GraphPoint
|
from c3nav.routing.point import GraphPoint
|
||||||
from c3nav.routing.route import NoRoute
|
from c3nav.routing.route import NoRoute, Route
|
||||||
from c3nav.routing.routesegments import (GraphRouteSegment, LevelRouteSegment, RoomRouteSegment, SegmentRoute,
|
from c3nav.routing.routesegments import (GraphRouteSegment, LevelRouteSegment, RoomRouteSegment, SegmentRoute,
|
||||||
SegmentRouteWrapper)
|
SegmentRouteWrapper)
|
||||||
|
|
||||||
|
@ -281,6 +282,14 @@ class Graph:
|
||||||
dest_rooms = set(point.room for point in dest_points)
|
dest_rooms = set(point.room for point in dest_points)
|
||||||
common_rooms = orig_rooms & dest_rooms
|
common_rooms = orig_rooms & dest_rooms
|
||||||
|
|
||||||
|
if add_orig_point and add_dest_point and common_rooms:
|
||||||
|
room = tuple(common_rooms)[0]
|
||||||
|
ctype = room.check_connection((add_orig_point.x, add_orig_point.y), (add_dest_point.x, add_dest_point.y))
|
||||||
|
if ctype is not None:
|
||||||
|
from_point = GraphPoint(add_orig_point.x, add_orig_point.y, room)
|
||||||
|
to_point = GraphPoint(add_dest_point.x, add_dest_point.y, room)
|
||||||
|
return Route((GraphConnection(from_point, to_point, ctype=ctype), ))
|
||||||
|
|
||||||
# get origin points for each room (points as point index within room)
|
# get origin points for each room (points as point index within room)
|
||||||
orig_room_points = {room: self._allowed_points_index(room.points, orig_points_i) for room in orig_rooms}
|
orig_room_points = {room: self._allowed_points_index(room.points, orig_points_i) for room in orig_rooms}
|
||||||
dest_room_points = {room: self._allowed_points_index(room.points, dest_points_i) for room in dest_rooms}
|
dest_room_points = {room: self._allowed_points_index(room.points, dest_points_i) for room in dest_rooms}
|
||||||
|
|
|
@ -304,5 +304,15 @@ class GraphRoom():
|
||||||
connections.update(area.connected_points(point, mode))
|
connections.update(area.connected_points(point, mode))
|
||||||
return connections
|
return connections
|
||||||
|
|
||||||
|
def check_connection(self, from_point, to_point):
|
||||||
|
from_point = np.array(from_point)
|
||||||
|
to_point = np.array(to_point)
|
||||||
|
for area in self.areas:
|
||||||
|
if area.contains_point(from_point) and area.contains_point(to_point):
|
||||||
|
there, back = area.check_connection(from_point, to_point)
|
||||||
|
if there is not None:
|
||||||
|
return there
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
RoomRouter = namedtuple('RoomRouter', ('shortest_paths', 'predecessors', ))
|
RoomRouter = namedtuple('RoomRouter', ('shortest_paths', 'predecessors', ))
|
||||||
|
|
|
@ -20,6 +20,9 @@ class Route:
|
||||||
return ('<Route (\n %s\n) distance=%f>' %
|
return ('<Route (\n %s\n) distance=%f>' %
|
||||||
('\n '.join(repr(connection) for connection in self.connections), self.distance))
|
('\n '.join(repr(connection) for connection in self.connections), self.distance))
|
||||||
|
|
||||||
|
def split(self):
|
||||||
|
return self
|
||||||
|
|
||||||
def create_routeparts(self):
|
def create_routeparts(self):
|
||||||
routeparts = []
|
routeparts = []
|
||||||
connections = []
|
connections = []
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue