def test_projection_and_angle(self): "Test re-projecting existing point" geo1 = Coordinates(13.41, 52.525) geo2 = Coordinates(13.414, 52.525) dist = distance(geo1, geo2) angle = bearing(geo1, geo2) geo3 = extrapolate(geo1, dist, angle) self.assertAlmostEqual(geo2.lon, geo3.lon) self.assertAlmostEqual(geo2.lat, geo3.lat)
def test_bearingscore_4(self): "Test bearing difference of -90°" node1 = DummyNode(Coordinates(0.0, 0.0)) node2 = DummyNode(Coordinates(0.0, 90.0)) node3 = DummyNode(Coordinates(-1.0, 0.0)) wanted_bearing = degrees(bearing(node1.coordinates, node2.coordinates)) wanted = LocationReferencePoint(13.416, 52.525, FRC.FRC2, FOW.SINGLE_CARRIAGEWAY, wanted_bearing, None, None) line = DummyLine(1, node1, node3) score = score_bearing(wanted, PointOnLine(line, 1.0), True, self.config.bear_dist) self.assertAlmostEqual(score, 0.5)
def test_bearingscore_5(self): "Test perfect/worst possible bearing" node1 = DummyNode(Coordinates(1.0, 0.0)) node2 = DummyNode(Coordinates(0.0, 0.0)) wanted_bearing = degrees(bearing(node1.coordinates, node2.coordinates)) wanted = LocationReferencePoint(13.416, 52.525, FRC.FRC2, FOW.SINGLE_CARRIAGEWAY, wanted_bearing, None, None) line = DummyLine(1, node1, node2) score = score_bearing(wanted, PointOnLine(line, 0.0), False, self.config.bear_dist) self.assertAlmostEqual(score, 1.0) score = score_bearing(wanted, PointOnLine(line, 1.0), True, self.config.bear_dist) self.assertAlmostEqual(score, 0.0)
def test_bearing_90_2(self): "Test bearing function where it should be 90°" geo1 = Coordinates(-1.0, 0.0) geo2 = Coordinates(-2.0, 0.0) bear = bearing(geo1, geo2) self.assertEqual(bear, -pi / 2)
def test_bearing_180(self): "Test bearing function where it should be 180°" geo1 = Coordinates(0.0, -10.0) geo2 = Coordinates(0.0, -20.0) bear = bearing(geo1, geo2) self.assertEqual(bear, pi)
def test_bearing_zero(self): "Test bearing function where it should be zero" geo1 = Coordinates(0.0, 10.0) geo2 = Coordinates(0.0, 20.0) bear = bearing(geo1, geo2) self.assertEqual(bear, 0.0)