def test_size(self): # Act / Assert extent = hm.Extent(coords=(hm.Coordinate(-10, -10), hm.Coordinate(10, 10))) # Assert self.assertEqual(extent.size(), hm.Coordinate(20, 20))
def test_corners(self): # Arrange extent = hm.Extent(coords=(hm.Coordinate(-10, -10), hm.Coordinate(10, 10))) # Act / Assert self.assertEqual(extent.corners(), (hm.Coordinate(-10, -10), hm.Coordinate(10, 10)))
def test_is_inside(self): # Arrange extent = hm.Extent(coords=(hm.Coordinate(-10, -10), hm.Coordinate(10, 10))) # Act / Assert self.assertTrue(extent.is_inside(hm.Coordinate(1, 1))) self.assertFalse(extent.is_inside(hm.Coordinate(100, 100)))
def test_resize(self): # Arrange extent = hm.Extent(coords=(hm.Coordinate(-10, -10), hm.Coordinate(10, 10))) # Act extent.resize(width=10, height=20) # Assert self.assertEqual(extent.corners(), (hm.Coordinate(-5, -10), hm.Coordinate(5, 10)))
def test_grow(self): # Arrange extent = hm.Extent(coords=(hm.Coordinate(-10, -10), hm.Coordinate(10, 10))) # Act extent.grow(20) # Assert self.assertEqual(extent.corners(), (hm.Coordinate(-30, -30), hm.Coordinate(30, 30)))
def test_basic(self): '''Test Coordinate class.''' coord = hm.Coordinate(1, 2) self.assertEqual(coord.x, 1) self.assertEqual(coord.y, 2) self.assertEqual(coord.first, coord.x) self.assertEqual(coord.second, coord.y) self.assertEqual(coord, coord.copy()) self.assertEqual(str(coord), "(1, 2)") self.assertIsInstance(hash(coord), int) coord2 = hm.Coordinate(6, 12) self.assertEqual(coord2 - coord, hm.Coordinate(5, 10))
def test_from_bounding_box(self): # Arrange extent1 = hm.Extent(coords=(hm.Coordinate(-10, -10), hm.Coordinate(10, 10))) extent2 = hm.Extent(coords=(hm.Coordinate(0, 0), hm.Coordinate(40, 40))) # Act extent1.from_bounding_box(extent2) # Assert self.assertEqual(extent1.size(), hm.Coordinate(40, 40))
def test_update(self): # Arrange extent1 = hm.Extent(coords=(hm.Coordinate(-10, -10), hm.Coordinate(10, 10))) extent2 = hm.Extent(coords=(hm.Coordinate(0, 0), hm.Coordinate(40, 40))) # Act extent1.update(extent2) # Assert self.assertEqual(extent1.size(), hm.Coordinate(50, 50))
def test_init_from_coords(self): # Act extent = hm.Extent(coords=(hm.Coordinate(-10, -10), hm.Coordinate(10, 10))) # Assert self.assertIsNotNone(extent) self.assertIsInstance(extent, hm.Extent) self.assertEqual(str(extent), "-10,-10,10,10") # Assert self.assertIsNotNone(extent) self.assertIsInstance(extent, hm.Extent) self.assertEqual(str(extent), "-10,-10,10,10")
def test_basic(self): '''Test Coordinate class.''' coord = hm.Coordinate(1, 2) self.assertEqual(coord.x, 1) self.assertEqual(coord.y, 2) self.assertEqual(coord.first, coord.x) self.assertEqual(coord.second, coord.y) self.assertEqual(coord, coord.copy())
def vector3_to_latlon(self, data): pt = ((data["z"] - config["map_bounds"]["min"]["z"]) / (config["map_bounds"]["max"]["z"] - config["map_bounds"]["min"]["z"]) * self.map_size[0], (data["x"] - config["map_bounds"]["min"]["x"]) / (config["map_bounds"]["max"]["x"] - config["map_bounds"]["min"]["x"]) * self.map_size[1]) #print("point on image: " + str(pt)) latlon = self.hm_config.projection.inverse_project(hm.Coordinate(*pt)) return latlon
def _assert_mapping(self, latlon_given, xy_given, projection): latlon_given = hm.LatLon(*latlon_given) xy_given = hm.Coordinate(*xy_given) xy_actual = projection.project(latlon_given) self.assertTrue(isinstance(xy_actual, hm.Coordinate)) self.assertAlmostEqual(xy_given.x, xy_actual.x) self.assertAlmostEqual(xy_given.y, xy_actual.y) latlon_actual = projection.inverse_project(xy_given) self.assertTrue(isinstance(latlon_actual, hm.LatLon)) self.assertAlmostEqual(latlon_given.lat, latlon_actual.lat) self.assertAlmostEqual(latlon_given.lon, latlon_actual.lon)
def setup_config(self, iter): map = PIL.Image.open(config["map_img"]) self.map_size = map.size self.hm_config = hm.Configuration() self.hm_config.width = map.size[0] self.hm_config.height = map.size[1] self.hm_config.margin = 0 self.hm_config.zoom = 1 self.hm_config.projection = hm.EquirectangularProjection() self.hm_config.projection.pixels_per_degree = 1 self.hm_config.extent_out = hm.Extent( coords=[hm.Coordinate(c[0], c[1]) for c in [(0, 0), map.size]]) self.hm_config.extent_in = hm.Extent(coords=[ self.hm_config.projection.inverse_project(hm.Coordinate( c[0], c[1])) for c in [(0, 0), map.size] ]) self.hm_config.shapes = iter self.hm_config.decay = 0.5 self.hm_config.kernel = hm.LinearKernel(5) self.hm_config.background_image = map self.hm_config.fill_missing() return config