def find_best_match(stone, selection, bucket_size_c=10, bucket_size_s=200): min_colors = sorted(selection, key=lambda x: compare_colors(x.color, stone.color)) min_structures = sorted(selection, key=lambda x: compare_histograms(x.structure, stone.structure)) color_set = set(min_colors[:bucket_size_c]) structure_set = set(min_structures[:bucket_size_s]) intersection_list = list(color_set.intersection(structure_set)) if len(intersection_list) > 0: log.debug('Found in intersection set') return choice(intersection_list) return min_colors[0]
def find_most_distant_color(stone, selection): s = max(selection, key=lambda x: compare_colors(x.color, stone.color)) return s