예제 #1
0
 def testSpatialPredicates(self):
     # circle-circle, circle-box, box-circle
     c1 = g.SphericalCircle((0.0, 0.0), 1.0)
     self.assertTrue(c1.intersects(c1))
     self.assertTrue(c1.contains(c1))
     b1 = c1.getBoundingBox()
     self.assertTrue(b1.contains(c1))
     self.assertTrue(b1.intersects(c1))
     c2 = g.SphericalCircle((3.0, 0.0), 1.0)
     b2 = c2.getBoundingBox()
     self.assertTrue(b2.contains(c2))
     self.assertTrue(b2.intersects(c2))
     self.assertFalse(c1.contains(c2))
     self.assertFalse(c1.intersects(c2))
     c1 = g.SphericalCircle((0.0, 0.0), 5.0)
     c3 = g.SphericalCircle((180.0, 0.0), 5.0)
     b1 = c1.getBoundingBox()
     self.assertTrue(c1.contains(c2))
     self.assertFalse(c2.contains(c1))
     self.assertTrue(c1.intersects(c2))
     self.assertTrue(c2.intersects(c1))
     self.assertTrue(b2.intersects(c1))
     self.assertTrue(b2.intersects(c2))
     self.assertTrue(b1.intersects(c1))
     self.assertTrue(b1.intersects(c2))
     self.assertFalse(c3.intersects(b1))
     self.assertFalse(b1.intersects(c3))
     self.assertFalse(c3.contains(b1))
     self.assertFalse(b1.contains(c3))
     b3 = g.SphericalBox((1.0, -1.0), (359.0, 1.0))
     self.assertTrue(b3.intersects(c1))
     self.assertTrue(b3.intersects(c2))
     self.assertTrue(b3.contains(c2))
     self.assertFalse(b3.contains(c1))
     self.assertFalse(c1.contains(b3))
     self.assertFalse(c2.contains(b3))
     # circle-point
     self.assertTrue(c1.contains((1.0, 0.0, 0.0)))
     self.assertTrue(c1.intersects((0.0, 0.0)))
     self.assertFalse(c1.intersects((10.0, 0.0)))
     self.assertFalse(c1.contains((-10.0, 0.0)))
     points = _pointsOnCircle((0.0, 0.0), 4.999, 100)
     for p in points:
         self.assertTrue(c1.contains(p))
     points = _pointsOnCircle((0.0, 0.0), 5.001, 100)
     for p in points:
         self.assertFalse(c1.contains(p))
     # circle-polygon
     p1 = g.SphericalConvexPolygon(_pointsOnCircle((0.0, 0.0), 10.0, 100))
     p2 = g.SphericalConvexPolygon(_pointsOnCircle((0.0, 0.0), 3.0, 100))
     self.assertTrue(c1.contains(p2))
     self.assertTrue(c1.intersects(p2))
     self.assertFalse(c1.contains(p1))
     self.assertTrue(c1.intersects(p2))
     self.assertTrue(p1.intersects(c1))
     self.assertTrue(p2.intersects(c1))
     self.assertTrue(p1.contains(c1))
     self.assertFalse(p2.contains(c1))
예제 #2
0
 def testSpatialPredicates(self):
     # polygon-point, polygon-circle
     p = g.SphericalConvexPolygon(_pointsOnCircle((0.0, 0.0), 1.0, 8))
     self.assertTrue(p.contains(p.getBoundingCircle().getCenter()))
     self.assertTrue(p.intersects(p.getBoundingCircle().getCenter()))
     points = _pointsOnCircle((0.0, 0.0), 0.5, 50)
     for v in points:
         self.assertTrue(p.contains(v))
         self.assertTrue(p.intersects(v))
     c = g.SphericalCircle((0.0, 0.0), 0.5)
     self.assertTrue(p.contains(c))
     self.assertTrue(p.intersects(c))
     self.assertFalse(c.contains(p))
     self.assertTrue(c.intersects(p))
     points = _pointsOnCircle((0.0, 0.0), 1.001, 50)
     for v in points:
         self.assertFalse(p.contains(v))
         self.assertFalse(p.intersects(v))
     c = g.SphericalCircle((0.0, 0.0), 1.001)
     c2 = g.SphericalCircle((180.0, 0.0), 1.001)
     self.assertTrue(c.contains(p))
     self.assertTrue(c.intersects(p))
     self.assertFalse(c2.intersects(p))
     self.assertFalse(p.intersects(c2))
     self.assertFalse(c2.contains(p))
     self.assertFalse(p.contains(c2))
     self.assertFalse(p.contains(c))
     self.assertTrue(p.intersects(c))
     # polygon-box
     b = g.SphericalBox((-0.5, -0.5), (0.5, 0.5))
     self.assertTrue(b.intersects(p))
     self.assertTrue(p.intersects(b))
     self.assertTrue(p.contains(b))
     self.assertFalse(b.contains(p))
     b = g.SphericalBox((0.5, -0.5), (359.5, 0.5))
     self.assertTrue(b.intersects(p))
     self.assertTrue(p.intersects(b))
     self.assertFalse(b.contains(p))
     self.assertFalse(p.contains(b))
     # polygon-polygon
     self.assertTrue(p.intersects(p))
     p2 = g.SphericalConvexPolygon(_pointsOnCircle((0.5, 0.0), 1.0, 8))
     self.assertTrue(p.intersects(p2))
     self.assertTrue(p2.intersects(p))
     self.assertFalse(p.contains(p2))
     self.assertFalse(p2.contains(p))
     p3 = g.SphericalConvexPolygon(_pointsOnCircle((0.25, 0.0), 0.25, 8))
     self.assertTrue(p.contains(p3))
예제 #3
0
 def testIntersect(self):
     pmap = g.SphericalBoxPartitionMap(1, 1)
     b = g.SphericalBox((0.0, -90.0), (360.0, 90.0))
     for chunkId, subIter in pmap.intersect(b):
         self.assertEqual(chunkId, 0)
         for subChunkId, regions in subIter:
             self.assertEqual(subChunkId, 0)
             self.assertEqual(regions, set())
     pmap = g.SphericalBoxPartitionMap(18, 10)
     b = g.SphericalBox((0.01, 0.01), (0.99, 0.99))
     for chunkId, subIter in pmap.intersect(b):
         self.assertEqual(chunkId, 324)
         for subChunkId, regions in subIter:
             self.assertEqual(subChunkId, 0)
             self.assertEqual(len(regions), 1)
             self.assertTrue(b in regions)
     # Test with an assortment of regions
     regions = [
         g.SphericalBox((-0.01, -0.01), (11.0, 11.0)),
         g.SphericalBox((350.0, 80.0), (360.0, 90.0)),
         g.SphericalBox((350.0, -90.0), (360.0, -80.0)),
         g.SphericalBox((-5.0, 20.0), (5.0, 22.0)),
         g.SphericalBox((0.0, -25.0), (2.0, -20.0)),
         g.SphericalCircle((45.0, 45.0), 1.0),
         g.SphericalConvexPolygon((-1.0, 0.0, 0.0), (0.0, 1.0, 0.0),
                                  g.normalize((-1.0, 1.0, -1.0))),
     ]
     # compute expected results by brute force
     results = {}
     for chunkId, subIter in pmap:
         for subChunkId in subIter:
             bbox = pmap.getSubChunkBoundingBox(chunkId, subChunkId)
             for i in xrange(len(regions)):
                 if regions[i].contains(bbox):
                     results[(chunkId, subChunkId)] = set()
                     break
                 elif regions[i].intersects(bbox):
                     if (chunkId, subChunkId) not in results:
                         results[(chunkId, subChunkId)] = set()
                     results[(chunkId, subChunkId)].add(regions[i])
     # and compare them to the results of intersect()
     for chunkId, subIter in pmap.intersect(regions):
         for subChunkId, xr in subIter:
             exr = results.pop((chunkId, subChunkId), None)
             self.assertEqual(xr, exr)
     self.assertEqual(len(results), 0)
예제 #4
0
 def testArea(self):
     verts = [(1.0, 0.0, 0.0), (0.0, 1.0, 0.0),
              g.normalize((1.0, 1.0, 1.0))]
     p = g.SphericalConvexPolygon(verts)
     self.assertAlmostEqual(p.area(), math.pi / 6)