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

Function cluster_objects

src/table.py:1016–1029  ·  view source on GitHub ↗
(xs, key_fn, tolerance)

Source from the content-addressed store, hash-verified

1014
1015
1016def cluster_objects(xs, key_fn, tolerance) -> list:
1017 if not callable(key_fn):
1018 key_fn = itemgetter(key_fn)
1019
1020 values = map(key_fn, xs)
1021 cluster_dict = make_cluster_dict(values, tolerance)
1022
1023 get_0, get_1 = itemgetter(0), itemgetter(1)
1024
1025 cluster_tuples = sorted(((x, cluster_dict.get(key_fn(x))) for x in xs), key=get_1)
1026
1027 grouped = itertools.groupby(cluster_tuples, key=get_1)
1028
1029 return [list(map(get_0, v)) for k, v in grouped]
1030
1031
1032def move_object(obj, axis: str, value):

Callers 7

to_textmapMethod · 0.85
iter_sort_charsMethod · 0.85
extract_textFunction · 0.85
yield_unique_charsFunction · 0.85
snap_objectsFunction · 0.85
words_to_edges_hFunction · 0.85
words_to_edges_vFunction · 0.85

Calls 2

make_cluster_dictFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…