Пример #1
0
 def get_vertices(self):
     cellid = int(self.cellid, base=16)
     cell = s2.S2Cell(s2.S2CellId(cellid))
     loop = s2.S2Loop(cell)
     v0 = loop.GetS2LatLngVertex(0)
     v0 = [v0.lat().degrees(), v0.lng().degrees()]
     v1 = loop.GetS2LatLngVertex(1)
     v1 = [v1.lat().degrees(), v1.lng().degrees()]
     v2 = loop.GetS2LatLngVertex(2)
     v2 = [v2.lat().degrees(), v2.lng().degrees()]
     v3 = loop.GetS2LatLngVertex(3)
     v3 = [v3.lat().degrees(), v3.lng().degrees()]
     return [v0, v1, v2, v3]
Пример #2
0
  def testS2LoopRegion(self):
    cell = s2.S2Cell(s2.S2CellId(s2.S2LatLng.FromDegrees(3.0, 4.0)).parent(8))
    loop = s2.S2Loop(cell)

    inside = s2.S2LatLng.FromDegrees(3.0, 4.0).ToPoint()
    outside = s2.S2LatLng.FromDegrees(30.0, 40.0).ToPoint()

    self.assertTrue(loop.Contains(inside))
    self.assertFalse(loop.Contains(outside))
    self.assertTrue(loop.Contains(s2.S2Cell(inside)))
    self.assertFalse(loop.Contains(s2.S2Cell(outside)))
    self.assertTrue(loop.MayIntersect(s2.S2Cell(inside)))
    self.assertFalse(loop.MayIntersect(s2.S2Cell(outside)))

    cap_bound = loop.GetCapBound()
    self.assertTrue(cap_bound.Contains(inside))
    self.assertFalse(cap_bound.Contains(outside))

    rect_bound = loop.GetRectBound()
    self.assertTrue(rect_bound.Contains(inside))
    self.assertFalse(rect_bound.Contains(outside))
Пример #3
0
 def verts2loop(vs):
     loop = s2.S2Loop()
     loop.Init([s2.S2LatLng.FromDegrees(*v).ToPoint() for v in vs])
     return loop
Пример #4
0
 def testS2PolygonInitNestedWithIncorrectTypeIsWrappedCorrectly(self):
     london = s2.S2LatLng.FromDegrees(51.5001525, -0.1262355)
     loop = s2.S2Loop(s2.S2Cell(s2.S2CellId(london)))
     polygon = s2.S2Polygon()
     with self.assertRaises(TypeError):
         polygon.InitNested([loop, s2.S2CellId()])
Пример #5
0
 def testS2PolygonInitNestedIsWrappedCorrectly(self):
     london = s2.S2LatLng.FromDegrees(51.5001525, -0.1262355)
     small_loop = s2.S2Loop(s2.S2Cell(s2.S2CellId(london)))
     big_loop = s2.S2Loop(s2.S2Cell(s2.S2CellId(london).parent(1)))
     polygon = s2.S2Polygon()
     polygon.InitNested([big_loop, small_loop])
Пример #6
0
 def testS2PolygonCopiesLoopInConstructorBecauseItTakesOwnership(self):
     london = s2.S2LatLng.FromDegrees(51.5001525, -0.1262355)
     loop = s2.S2Loop(s2.S2Cell(s2.S2CellId(london)))
     s2.S2Polygon(loop)
Пример #7
0
 def testS2LoopUsesValueEquality(self):
     self.assertEqual(s2.S2Loop(), s2.S2Loop())