diff --git a/src/c3nav/routing/graph.py b/src/c3nav/routing/graph.py index 8a330c3f..c399d161 100644 --- a/src/c3nav/routing/graph.py +++ b/src/c3nav/routing/graph.py @@ -11,9 +11,10 @@ from scipy.sparse.csgraph._tools import csgraph_from_dense from c3nav.mapdata.models import Elevator, Level from c3nav.mapdata.models.geometry import LevelConnector 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.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, SegmentRouteWrapper) @@ -281,6 +282,14 @@ class Graph: dest_rooms = set(point.room for point in dest_points) 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) 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} diff --git a/src/c3nav/routing/room.py b/src/c3nav/routing/room.py index 26551862..d984e2e2 100644 --- a/src/c3nav/routing/room.py +++ b/src/c3nav/routing/room.py @@ -304,5 +304,15 @@ class GraphRoom(): connections.update(area.connected_points(point, mode)) 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', )) diff --git a/src/c3nav/routing/route.py b/src/c3nav/routing/route.py index 87f1e30a..a2c0dd71 100644 --- a/src/c3nav/routing/route.py +++ b/src/c3nav/routing/route.py @@ -20,6 +20,9 @@ class Route: return ('' % ('\n '.join(repr(connection) for connection in self.connections), self.distance)) + def split(self): + return self + def create_routeparts(self): routeparts = [] connections = []