def testS2PolylineRegion(self): polyline = s2.S2Polyline() polyline.InitFromS2LatLngs([ s2.S2LatLng.FromDegrees(0.0, 0.0), s2.S2LatLng.FromDegrees(1.0, 1.0) ]) # Contains(S2Point) always return false. self.assertFalse( polyline.Contains(s2.S2LatLng.FromDegrees(0.0, 0.0).ToPoint())) self.assertFalse( polyline.Contains(s2.S2Cell(s2.S2LatLng.FromDegrees(0.0, 0.0)))) self.assertTrue( polyline.MayIntersect(s2.S2Cell(s2.S2LatLng.FromDegrees(0.0, 0.0)))) self.assertFalse( polyline.MayIntersect(s2.S2Cell(s2.S2LatLng.FromDegrees(3.0, 4.0)))) cap_bound = polyline.GetCapBound() self.assertTrue( cap_bound.Contains(s2.S2LatLng.FromDegrees(0.0, 0.0).ToPoint())) self.assertFalse( cap_bound.Contains(s2.S2LatLng.FromDegrees(2.0, 2.0).ToPoint())) rect_bound = polyline.GetRectBound() self.assertTrue( rect_bound.Contains(s2.S2LatLng.FromDegrees(0.0, 0.0).ToPoint())) self.assertFalse( rect_bound.Contains(s2.S2LatLng.FromDegrees(2.0, 2.0).ToPoint()))
def testS2PointsCanBeNormalized(self): line = s2.S2Polyline() line.InitFromS2LatLngs([ s2.S2LatLng.FromDegrees(37.794484, -122.394871), s2.S2LatLng.FromDegrees(37.762699, -122.435158) ]) self.assertNotAlmostEqual(line.GetCentroid().Norm(), 1.0) self.assertAlmostEqual(line.GetCentroid().Normalize().Norm(), 1.0)
def testS2PolylineInitFromS2Points(self): e7_10deg = 0x5f5e100 list_points = [] for lat, lng in [(0, 0), (0, e7_10deg), (e7_10deg, e7_10deg)]: list_points.append(s2.S2LatLng.FromE7(lat, lng).ToPoint()) line = s2.S2Polyline() line.InitFromS2Points(list_points) self.assertAlmostEqual(20.0, line.GetLength().degrees())
def testS2PolygonIntersectsWithPolyline(self): london = s2.S2LatLng.FromDegrees(51.5001525, -0.1262355) polygon = s2.S2Polygon(s2.S2Cell(s2.S2CellId(london).parent(15))) line = s2.S2Polyline() line.InitFromS2LatLngs([s2.S2LatLng.FromDegrees(51.5, -0.128), s2.S2LatLng.FromDegrees(51.5, -0.125)]) intersections = polygon.IntersectWithPolyline(line) self.assertEqual(1, len(intersections))
def testS2PolylineUsesValueEquality(self): self.assertEqual(s2.S2Polyline(), s2.S2Polyline())