Ejemplo n.º 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))
Ejemplo n.º 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))
Ejemplo n.º 3
0
 def testSpatialPredicates(self):
     # ellipse-point
     for cen in ((0.0, 0.0), (45.0, 45.0), (135.0, -45.0), (0.0, 90.0)):
         smaa = random.uniform(30, 20000)
         smia = random.uniform(1, smaa)
         a = random.uniform(0.0, 360.0)
         e = g.SphericalEllipse(cen, smaa, smia, a)
         self.assertTrue(e.contains(cen))
         self.assertTrue(e.contains(g.cartesianUnitVector(cen)))
         self.assertTrue(e.intersects(cen))
         self.assertTrue(e.intersects(g.cartesianUnitVector(cen)))
         points = _pointsOnCircle(
             cen,
             e.getInnerCircle().getRadius() - g.ANGLE_EPSILON, 100)
         for p in points:
             self.assertTrue(e.contains(p))
         points = _pointsOnCircle(
             cen,
             e.getBoundingCircle().getRadius() + g.ANGLE_EPSILON, 100)
         for p in points:
             self.assertFalse(e.intersects(p))
         points = _pointsOnEllipse(
             cen, smaa - g.ANGLE_EPSILON * g.ARCSEC_PER_DEG,
             smia - g.ANGLE_EPSILON * g.ARCSEC_PER_DEG, a, 100)
         for p in points:
             self.assertTrue(e.contains(p))
         points = _pointsOnEllipse(
             cen, smaa + g.ANGLE_EPSILON * g.ARCSEC_PER_DEG,
             smia + g.ANGLE_EPSILON * g.ARCSEC_PER_DEG, a, 100)
         for p in points:
             self.assertFalse(e.contains(p))
     # ellipse-circle
     cen = (0.0, 0.0)
     e = g.SphericalEllipse(cen, 7200.0, 3600.0, 90.0)
     c = g.SphericalCircle(cen,
                           e.getInnerCircle().getRadius() - g.ANGLE_EPSILON)
     self.assertTrue(e.intersects(c))
     self.assertTrue(c.intersects(e))
     self.assertTrue(e.contains(c))
     self.assertFalse(c.contains(e))
     # ellipse-box
     b = g.SphericalBox((-0.5, -0.5), (0.5, 0.5))
     self.assertTrue(e.intersects(b))
     self.assertTrue(e.contains(b))
     b = g.SphericalBox((0.5, -0.5), (359.5, 0.5))
     self.assertTrue(e.intersects(b))
     self.assertFalse(e.contains(b))
Ejemplo n.º 4
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)