def test_comparison_operators(self): self.assertEqual(Box(LonLat.fromDegrees(45, 45)), LonLat.fromDegrees(45, 45)) self.assertEqual(Box.fromDegrees(90, -45, 180, 45), Box(NormalizedAngleInterval.fromDegrees(90, 180), AngleInterval.fromDegrees(-45, 45))) self.assertNotEqual(Box(LonLat.fromDegrees(45, 45)), LonLat.fromDegrees(45, 90)) self.assertNotEqual(Box.fromDegrees(90, -45, 180, 45), Box.fromDegrees(90, -45, 180, 90))
def test_expanding_and_clipping(self): a = Box.fromDegrees(0, 0, 10, 10) b = (a.expandedTo(LonLat.fromDegrees(20, 20)).expandedTo( Box.fromDegrees(0, 0, 30, 10)).clippedTo( Box.fromDegrees(10, 10, 15, 15)).clippedTo(LonLat.fromDegrees(11, 11))) a.expandTo(LonLat.fromDegrees(20, 20)) a.expandTo(Box.fromDegrees(0, 0, 30, 10)) a.clipTo(Box.fromDegrees(10, 10, 15, 15)) a.clipTo(LonLat.fromDegrees(11, 11)) self.assertEqual(a, b) self.assertEqual(a, LonLat.fromDegrees(11, 11)) a.clipTo(LonLat.fromDegrees(0, 0)) self.assertTrue(a.isEmpty())
def testIntersecting(self): b = Box.fromDegrees(273.6, 30.7, 273.7180105379097, 30.722546655347717) c = Chunker(85, 12) self.assertEqual(c.getChunksIntersecting(b), [9630, 9631, 9797]) self.assertEqual(c.getSubChunksIntersecting(b), [(9630, [770]), (9631, [759]), (9797, [11])])
def test_center_and_dimensions(self): b = Box.fromDegrees(-90, -45, 90, 45) self.assertEqual(b.getCenter(), LonLat.fromDegrees(0, 0)) self.assertEqual(b.getWidth(), Angle.fromDegrees(180)) self.assertEqual(b.getHeight(), Angle.fromDegrees(90)) self.assertEqual(b.getLon().getA(), NormalizedAngle.fromDegrees(-90)) self.assertEqual(b.getLat().getB(), Angle.fromDegrees(45))
def test_relationships(self): b1 = Box.fromDegrees(90, 0, 180, 45) p = LonLat.fromDegrees(135, 10) self.assertTrue(p in b1) self.assertTrue(b1.contains(p)) b2 = Box.fromDegrees(135, 15, 135, 30) self.assertTrue(b1.contains(b2)) self.assertTrue(b2.isWithin(b1)) b3 = Box.fromDegrees(0, -45, 90, 0) u = UnitVector3d(1, 1, -1) self.assertTrue(b1.intersects(b3)) self.assertTrue(u in b3) self.assertTrue(b3.contains(u)) b4 = Box.fromDegrees(200, 10, 300, 20) self.assertTrue(b1.isDisjointFrom(b4)) r = b1.relate(LonLat.fromDegrees(135, 10)) self.assertEqual(r, CONTAINS) r = b4.relate(b1) self.assertEqual(r, DISJOINT)
def test_construction(self): b = Box(Box.allLongitudes(), Box.allLatitudes()) self.assertTrue(b.isFull()) b = Box.fromDegrees(-90, -45, 90, 45) self.assertEqual(b, Box(b.getLon(), b.getLat())) a = Box.fromRadians(-0.5 * math.pi, -0.25 * math.pi, 0.5 * math.pi, 0.25 * math.pi) b = Box(LonLat.fromRadians(-0.5 * math.pi, -0.25 * math.pi), LonLat.fromRadians(0.5 * math.pi, 0.25 * math.pi)) c = Box(LonLat.fromRadians(0, 0), Angle(0.5 * math.pi), Angle(0.25 * math.pi)) d = c.clone() self.assertEqual(a, b) self.assertEqual(b, c) self.assertEqual(c, d) self.assertNotEqual(id(c), id(d)) b = Box() self.assertTrue(b.isEmpty()) self.assertTrue(Box.empty().isEmpty()) self.assertTrue(Box.full().isFull())
def test_pickle(self): a = Box.fromDegrees(0, 0, 10, 10) b = pickle.loads(pickle.dumps(a, pickle.HIGHEST_PROTOCOL)) self.assertEqual(a, b)
def test_yaml(self): a = Box.fromDegrees(0, 0, 10, 10) b = yaml.safe_load(yaml.dump(a)) self.assertEqual(a, b)