Esempio n. 1
0
    def test_get_roads_multiple_non_aligned_segments(self):
        """
        (0,0)--(1,0)--(5,1)--(6,2)
        Note that the last 2 segments have a 45deg angle
        """
        n1 = GraphNode(Point(0, 0))
        n2 = GraphNode(Point(1, 0))
        n3 = GraphNode(Point(5, 1))
        n4 = GraphNode(Point(6, 2))

        self._connect(n1, n2)
        self._connect(n2, n3)
        self._connect(n3, n4)

        VertexGraphToRoadsConverter(self.city, 0.25, [n1, n2, n3, n4]).run()

        intersection = RoadIntersectionNode.on(5, 1)
        expected_roads = [
            Street.from_nodes([RoadSimpleNode.on(0, 0), RoadSimpleNode.on(1, 0), intersection]),
            Street.from_nodes([RoadSimpleNode.on(6, 2), intersection])
        ]
        self.assertItemsEqual(self.city.roads, expected_roads)
Esempio n. 2
0
    def test_get_roads_L_type(self):
        """
        (0,0)--(1,0)--(6,1)
                  |---(6,6)
        Note that (6,6) is discarded since the angle is greater than 15deg
        """
        n1 = GraphNode(Point(0, 0))
        n2 = GraphNode(Point(1, 0))
        n3 = GraphNode(Point(6, 1))
        n4 = GraphNode(Point(6, 6))

        self._connect(n1, n2)
        self._connect(n2, n3)
        self._connect(n2, n4)

        VertexGraphToRoadsConverter(self.city, 0.25, [n1, n2, n3, n4]).run()
        intersection = RoadIntersectionNode.on(1, 0)
        expected_roads = [
            Street.from_nodes([RoadSimpleNode.on(0, 0), intersection, RoadSimpleNode.on(6, 1)]),
            Street.from_nodes([RoadSimpleNode.on(6, 6), intersection])
        ]
        self.assertItemsEqual(self.city.roads, expected_roads)
Esempio n. 3
0
    def test_get_roads_Y_type(self):
        """
        (0,0)--(1,0)--(6,1)
                  |---(6,-0.8)
        Note that (6,1) is discarded only because (6,-0.8) is a better
        candidate, but both are eligible
        """
        n1 = GraphNode(Point(0, 0))
        n2 = GraphNode(Point(1, 0))
        n3 = GraphNode(Point(6, 1))
        n4 = GraphNode(Point(6, -0.8))

        self._connect(n1, n2)
        self._connect(n2, n3)
        self._connect(n2, n4)

        VertexGraphToRoadsConverter(self.city, 0.25, [n1, n2, n3, n4]).run()
        intersection = RoadIntersectionNode.on(1, 0)
        expected_roads = [
            Street.from_nodes([RoadSimpleNode.on(0, 0), intersection, RoadSimpleNode.on(6, -0.8)]),
            Street.from_nodes([RoadSimpleNode.on(6, 1), intersection])
        ]
        self.assertItemsEqual(self.city.roads, expected_roads)
Esempio n. 4
0
    def test_trim_redundant_nodes_on_collinear_segments_with_intersection(
            self):
        """Two collinear segments, where the midpoint is an intersection.
        The middle point should not be removed, as that would remove the intersection"""

        city = City()
        city.add_intersection_at(Point(100, 0))
        city.add_road(
            Road.from_control_points([Point(100, 100),
                                      Point(100, 0)]))

        points = [Point(0, 0), Point(100, 0), Point(200, 0)]
        road = Road.from_control_points(points)
        city.add_road(road)

        expected_nodes = [
            RoadSimpleNode(Point(0, 0)),
            RoadIntersectionNode(Point(100, 0)),
            RoadSimpleNode(Point(200, 0)),
        ]
        self.assertEqual(road.nodes(), expected_nodes)
        road.trim_redundant_nodes()
        self.assertEqual(road.nodes(), expected_nodes)
Esempio n. 5
0
    def test_get_roads_Y_street_best_neighbour_street(self):
        """
        (0,0)--(1,0)--(6,1)(trunk)
                  |---(6,-0.8)
        Expected: main street:[(0,0),(1,0),(6,-0.8)]
                  access street:[(1,0), (6,1)]
        """
        n1 = GraphNode(Point(0, 0))
        n2 = GraphNode(Point(1, 0))
        n3 = GraphNode(Point(6, 1))
        n3.is_minor_road = False  # make trunk
        n4 = GraphNode(Point(6, -0.8))

        self._connect(n1, n2)
        self._connect(n2, n3)
        self._connect(n2, n4)

        VertexGraphToRoadsConverter(self.city, 0.25, [n1, n2, n3, n4]).run()
        intersection = RoadIntersectionNode.on(1, 0)
        expected_roads = [
            Street.from_nodes([RoadSimpleNode.on(0, 0), intersection, RoadSimpleNode.on(6, -0.8)]),
            Street.from_nodes([intersection, RoadSimpleNode.on(6, 1)])
        ]
        self.assertItemsEqual(self.city.roads, expected_roads)