def test_replace_tree(self): tree2 = FeatureTree([self.f1, self.f2, self.f3]) self.assertEqual(tree2.z((0, 0)), 1) self.assertEqual(tree2.z((0.5, 0.5)), (1 + 10) / 2) self.assertEqual(tree2.z((1.2, 1.2)), 10) self.assertEqual(tree2.z((0.78, 0.75)), 0.8 * 100 + 0.2 * ((1 + 10) / 2))
def test_addition_tree(self): tree3 = FeatureTree([self.f1, self.f2, self.f4]) self.assertEqual(tree3.z((0, 0)), 1) self.assertEqual(tree3.z((0.5, 0.5)), (1 + 10) / 2) self.assertEqual(tree3.z((1.2, 1.2)), 10) self.assertAlmostEqual(tree3.z((0.78, 0.75)), 0.8 * 1000 + ((1 + 10) / 2))
def test_tree(self): self.f1.influ = "all" self.f2.influ = "all" tree = FeatureTree([self.f1, self.f2]) self.assertEqual(tree.z((0, 0)), 1 / 2) self.assertEqual(tree.z((0.75, 0.75)), (1 + 10) / 2) self.assertEqual(tree.z((1.2, 1.2)), 10 / 2)
def __init__(self, features, x=200, y=200): self.res_x = x self.res_y = y self.tree = FeatureTree(features) self.models = self.tree.models # compute z coordinate and gather abstract models self.abstract_models = set() for model in self.models: (x, y) = model.pos z = self.tree.z(model.pos) model.pos3D = (x, y, z) self.abstract_models.add(model.model) self.heightmap_init = False
class Environment: """Environment class""" def __init__(self, features, x=200, y=200): self.res_x = x self.res_y = y self.tree = FeatureTree(features) self.models = self.tree.models # compute z coordinate and gather abstract models self.abstract_models = set() for model in self.models: (x, y) = model.pos z = self.tree.z(model.pos) model.pos3D = (x, y, z) self.abstract_models.add(model.model) self.heightmap_init = False # def translate_hm(self, coords): # return self.tree.z((coords[0] + self.res_x // 2, coords[1] + self.res_y // 2)) def init_heightmap(self, res_x, res_y): self.res_x = res_x self.res_y = res_y self.heightmap = HeightMap(res_x, res_y, self.tree.z) self.heightmap_init = True def export_heightmap(self, filename, res_x=None, res_y=None): if res_x is None: res_x = self.res_x if res_y is None: res_y = self.res_y if not self.heightmap_init: self.init_heightmap(res_x, res_y) self.heightmap.export(filename)