MCPcopy Index your code
hub / github.com/pymupdf/PyMuPDF / snap_objects

Function snap_objects

src/table.py:1054–1063  ·  view source on GitHub ↗
(objs, attr: str, tolerance)

Source from the content-addressed store, hash-verified

1052
1053
1054def 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
1066def snap_edges(

Callers 1

snap_edgesFunction · 0.85

Calls 2

cluster_objectsFunction · 0.85
move_objectFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…