(objs, attr: str, tolerance)
| 1052 | |
| 1053 | |
| 1054 | def snap_objects(objs, attr: str, tolerance) -> list: |
| 1055 | axis = {"x0": "h", "x1": "h", "top": "v", "bottom": "v"}[attr] |
| 1056 | list_objs = list(objs) |
| 1057 | clusters = cluster_objects(list_objs, itemgetter(attr), tolerance) |
| 1058 | avgs = [sum(map(itemgetter(attr), cluster)) / len(cluster) for cluster in clusters] |
| 1059 | snapped_clusters = [ |
| 1060 | [move_object(obj, axis, avg - obj[attr]) for obj in cluster] |
| 1061 | for cluster, avg in zip(clusters, avgs) |
| 1062 | ] |
| 1063 | return list(itertools.chain(*snapped_clusters)) |
| 1064 | |
| 1065 | |
| 1066 | def snap_edges( |
no test coverage detected
searching dependent graphs…