def test_filter_nodes(self): criteriaA = nodetools.get_criteria_func([(self.complete_feature_keys, operator.lt, 0.5)], True) criteriaB = nodetools.get_criteria_func([(self.sparse_feature_keys, operator.ge, 0.3)], True) filtered_nodes = nodetools.filter_nodes_by_criteria(self.nodes, [criteriaA, criteriaB], True) # Has some nodes self.assertGreater(len(filtered_nodes), 0) # Does not have all nodes self.assertGreater(len(filtered_nodes), 0)
def refine_coastlines(seed, world): # Want to find all coastal nodes with an altitude between -0.01 and 0.01, and use # the latitude and longtiude of these points as locations to refine. This increases coastal # smoothness. Warning! Reset random.seed before both altitude generation routines, or # the extra cells we just generated will no longer be on the coast. coastal_test = nodetools.get_criteria_func([ (["terrain", "altitude"], operator.lt, 0.02), (["terrain", "altitude"], operator.gt, -0.02), ]) locations_to_refine = map(lambda n: (n.latitude, n.longitude), filter(coastal_test, world.all_boundary_nodes) ) print("Coastal locations to refine: %d" % len(locations_to_refine)) world.refine_voronoi_nodes_around_locations(locations_to_refine) random.seed(seed) weight = 1 nodetools.set_all_nodes_feature_with_funcs(nodes=world.all_boundary_nodes, feature=["terrain", "altitude"], valuators=[(nodeval.get_simplex_noise_valuator(seed), weight)], criteria_funcs=[])