コード例 #1
0
    def test_way_relation_is_location_in_bbox(self):
        wayRelation = WayRelation(mockOSMWay_01_02_Loop)
        bbox = wayRelation.bbox

        loc_avg = np.average(bbox, axis=0)
        loc_min = np.min(bbox, axis=0)
        loc_max = np.max(bbox, axis=0)

        locations = [
            loc_avg,
            loc_min,
            loc_max,
            [loc_avg[0], loc_min[1]],
            [loc_avg[0], loc_max[1]],
            [loc_min[0], loc_avg[1]],
            [loc_max[0], loc_avg[1]],
            loc_min - 0.1,
            loc_max + 0.1,
            [loc_avg[0], loc_min[1] - 0.1],
            [loc_avg[0], loc_max[1] + 0.1],
            [loc_min[0] - 0.1, loc_avg[1]],
            [loc_max[0] + 0.1, loc_avg[1]],
        ]

        is_in = [wayRelation.is_location_in_bbox(loc) for loc in locations]

        self.assertEqual(is_in, [
            True, True, True, True, True, True, True, False, False, False,
            False, False, False
        ])
コード例 #2
0
    def test_way_relation_update_only_resets_if_no_possible_found(self):
        wayRelation = WayRelation(mockOSMWay_01_01_LongCurvy)
        location_rad = wayRelation.bbox[
            0]  # Location inside bbox but outside actual way (due to padding)

        wayRelation.update(location_rad, 0., 10.)

        self.assertTrue(wayRelation.is_location_in_bbox(location_rad))
        self.assert_wayRelation_variables_reset(wayRelation)
コード例 #3
0
    def test_way_relation_update_resets_on_update(self):
        wayRelation = WayRelation(mockOSMWay_01_01_LongCurvy)
        self.make_wayRelation_location_dirty(wayRelation)
        location_rad = np.array([0., 0.])  # Location outside bbox

        wayRelation.update(location_rad, 0., 10.)

        self.assertFalse(wayRelation.is_location_in_bbox(location_rad))
        self.assert_wayRelation_variables_reset(wayRelation)
コード例 #4
0
    def test_way_relation_updates_in_the_correct_direction_with_correct_property_values(
            self):
        wayRelation = WayRelation(mockOSMWay_01_01_LongCurvy)
        location_rad = np.radians(
            np.array([52.32855593146639, 13.445320150125069]))
        bearing_rad = 0.

        wayRelation.update(location_rad, bearing_rad, 10.)

        self.assertTrue(wayRelation.is_location_in_bbox(location_rad))
        self.assertEqual(wayRelation.direction, DIRECTION.FORWARD)
        self.assertEqual(wayRelation.ahead_idx, 17)
        self.assertEqual(wayRelation.behind_idx, 16)
        self.assertAlmostEqual(wayRelation._distance_to_way, 3.43290781621360)
        self.assertAlmostEqual(wayRelation._active_bearing_delta,
                               0.320717420388962)
        self.assertAlmostEqual(wayRelation.distance_to_node_ahead,
                               25.4998961709014)
        self.assertTrue(wayRelation.active)
        self.assertFalse(wayRelation.diverting)
        assert_array_almost_equal(wayRelation.location_rad, location_rad)
        self.assertEqual(wayRelation.bearing_rad, bearing_rad)
        self.assertIsNone(wayRelation._speed_limit)

        bearing_rad = 180.

        wayRelation.update(location_rad, bearing_rad, 10.)

        self.assertTrue(wayRelation.is_location_in_bbox(location_rad))
        self.assertEqual(wayRelation.direction, DIRECTION.BACKWARD)
        self.assertEqual(wayRelation.ahead_idx, 16)
        self.assertEqual(wayRelation.behind_idx, 17)
        self.assertAlmostEqual(wayRelation._distance_to_way, 3.43290781621360)
        self.assertAlmostEqual(wayRelation._active_bearing_delta,
                               0.9507682562504284)
        self.assertAlmostEqual(wayRelation.distance_to_node_ahead,
                               11.11623371145368)
        self.assertTrue(wayRelation.active)
        self.assertFalse(wayRelation.diverting)
        assert_array_almost_equal(wayRelation.location_rad, location_rad)
        self.assertEqual(wayRelation.bearing_rad, bearing_rad)
        self.assertIsNone(wayRelation._speed_limit)
コード例 #5
0
    def test_way_relation_updates_with_location_closest_to_way_when_multiple_possible(
            self):
        wayRelation = WayRelation(mockOSMWay_01_02_Loop)
        location_rad = np.radians(
            np.array([52.313303275461564, 13.437729236325788]))
        bearing_rad = np.radians(10.)

        wayRelation.update(location_rad, bearing_rad, 10.)

        self.assertTrue(wayRelation.is_location_in_bbox(location_rad))
        self.assertEqual(wayRelation.direction, DIRECTION.BACKWARD)
        self.assertEqual(wayRelation.ahead_idx, 26)
        self.assertEqual(wayRelation.behind_idx, 27)
        self.assertAlmostEqual(wayRelation._distance_to_way,
                               10.151775235257011)
        self.assertAlmostEqual(wayRelation._active_bearing_delta,
                               0.06371131069242782)
        self.assertAlmostEqual(wayRelation.distance_to_node_ahead,
                               10.174073707120915)
        self.assertTrue(wayRelation.active)
        self.assertFalse(wayRelation.diverting)
        assert_array_almost_equal(wayRelation.location_rad, location_rad)
        self.assertEqual(wayRelation.bearing_rad, bearing_rad)
        self.assertIsNone(wayRelation._speed_limit)